with patch: QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=3500605.72..3500605.73 rows=1 width=52) (actual time=572114.740..572114.740 rows=1 loops=1) -> Sort (cost=3500605.72..3500605.73 rows=1 width=52) (actual time=572114.738..572114.738 rows=1 loops=1) Sort Key: supplier.s_name Sort Method: top-N heapsort Memory: 25kB -> Nested Loop Semi Join (cost=3025720.40..3500605.71 rows=1 width=52) (actual time=178675.638..572096.079 rows=3600 loops=1) Join Filter: (supplier.s_suppkey = lineitem.l_suppkey) Rows Removed by Join Filter: 723939540 -> Nested Loop (cost=0.42..650.46 rows=8000 width=56) (actual time=5.210..128.099 rows=8090 loops=1) -> Seq Scan on nation (cost=0.00..0.41 rows=1 width=4) (actual time=0.016..0.039 rows=1 loops=1) Filter: (n_name = 'EGYPT'::bpchar) Rows Removed by Filter: 24 -> Index Scan using idx_supplier_nation_key on supplier (cost=0.42..570.04 rows=8000 width=64) (actual time=5.189..123.582 rows=8090 loops=1) Index Cond: (s_nationkey = nation.n_nationkey) -> Materialize (cost=3025719.98..3499235.25 rows=6 width=16) (actual time=21.810..40.888 rows=89486 loops=8090) -> Merge Join (cost=3025719.98..3499235.22 rows=6 width=16) (actual time=176440.801..245903.143 rows=118124 loops=1) Merge Cond: ((lineitem.l_partkey = partsupp.ps_partkey) AND (lineitem.l_suppkey = partsupp.ps_suppkey)) Join Filter: ((partsupp.ps_availqty)::numeric > ((0.5 * sum(lineitem.l_quantity)))) Rows Removed by Join Filter: 242 -> GroupAggregate (cost=2921830.80..3248925.16 rows=9680570 width=48) (actual time=174001.209..239395.275 rows=10890067 loops=1) Group Key: lineitem.l_partkey, lineitem.l_suppkey -> Sort (cost=2921830.80..2967302.26 rows=18188581 width=21) (actual time=174001.170..191792.420 rows=18194084 loops=1) Sort Key: lineitem.l_partkey, lineitem.l_suppkey Sort Method: external merge Disk: 551928kB -> Bitmap Heap Scan on lineitem (cost=191420.72..707288.74 rows=18188581 width=21) (actual time=16502.428..142386.748 rows=18195269 loops=1) Recheck Cond: ((l_shipdate >= '1994-01-01'::date) AND (l_shipdate < '1995-01-01 00:00:00'::timestamp without time zone)) Rows Removed by Index Recheck: 64500318 Heap Blocks: exact=643068 lossy=1586943 -> Bitmap Index Scan on idx_l_shipdate (cost=0.00..186873.58 rows=18188581 width=0) (actual time=15788.414..15788.414 rows=18195269 loops=1) Index Cond: ((l_shipdate >= '1994-01-01'::date) AND (l_shipdate < '1995-01-01 00:00:00'::timestamp without time zone)) -> Sort (cost=103889.17..104293.20 rows=161611 width=24) (actual time=2438.874..2492.173 rows=173936 loops=1) Sort Key: partsupp.ps_partkey, partsupp.ps_suppkey Sort Method: quicksort Memory: 19733kB -> Nested Loop (cost=1000.43..89908.07 rows=161611 width=24) (actual time=0.492..2098.288 rows=173936 loops=1) -> Gather (cost=1000.00..25736.47 rows=40404 width=4) (actual time=0.441..43.207 rows=43484 loops=1) Workers Planned: 4 Workers Launched: 4 -> Parallel Seq Scan on part (cost=0.00..20696.07 rows=10101 width=4) (actual time=0.101..568.375 rows=8697 loops=5) Filter: ((p_name)::text ~~ 'beige%'::text) Rows Removed by Filter: 791303 -> Index Scan using idx_partsupp_partkey on partsupp (cost=0.43..1.23 rows=36 width=20) (actual time=0.040..0.044 rows=4 loops=43484) Index Cond: (ps_partkey = part.p_partkey) Planning time: 4.366 ms Execution time: 572175.608 ms (43 rows) without patch: QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=3511640.58..3511640.58 rows=1 width=52) (actual time=210752.754..210752.754 rows=1 loops=1) -> Sort (cost=3511640.58..3511640.58 rows=0 width=52) (actual time=210752.752..210752.752 rows=1 loops=1) Sort Key: supplier.s_name Sort Method: top-N heapsort Memory: 25kB -> Nested Loop (cost=3511638.11..3511640.57 rows=0 width=52) (actual time=209079.102..210746.190 rows=3600 loops=1) -> Nested Loop (cost=3511637.98..3511640.32 rows=2 width=60) (actual time=209048.920..210175.846 rows=89512 loops=1) -> HashAggregate (cost=3511637.56..3511637.62 rows=6 width=16) (actual time=209036.754..209097.302 rows=89512 loops=1) Group Key: partsupp.ps_suppkey -> Merge Join (cost=3014830.12..3511637.54 rows=2 width=16) (actual time=130994.237..208887.149 rows=118124 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Join Filter: ((partsupp.ps_availqty)::numeric > ((0.5 * sum(lineitem.l_quantity)))) Rows Removed by Join Filter: 242 -> Sort (cost=92999.32..93100.33 rows=40403 width=24) (actual time=1307.666..1368.686 rows=173936 loops=1) Sort Key: partsupp.ps_partkey, partsupp.ps_suppkey Sort Method: quicksort Memory: 19733kB -> Nested Loop (cost=1000.43..89908.07 rows=40403 width=24) (actual time=0.298..1069.290 rows=173936 loops=1) -> Gather (cost=1000.00..25736.47 rows=40404 width=4) (actual time=0.254..36.733 rows=43484 loops=1) Workers Planned: 4 Workers Launched: 4 -> Parallel Seq Scan on part (cost=0.00..20696.07 rows=10101 width=4) (actual time=0.059..738.015 rows=8697 loops=5) Filter: ((p_name)::text ~~ 'beige%'::text) Rows Removed by Filter: 791303 -> Index Scan using idx_partsupp_partkey on partsupp (cost=0.43..1.23 rows=36 width=20) (actual time=0.018..0.021 rows=4 loops=43484) Index Cond: (ps_partkey = part.p_partkey) -> Materialize (cost=2921830.80..3369932.29 rows=9680570 width=48) (actual time=129686.054..201794.618 rows=10890067 loops=1) -> GroupAggregate (cost=2921830.80..3248925.16 rows=9680570 width=48) (actual time=129686.045..195197.222 rows=10890067 loops=1) Group Key: lineitem.l_partkey, lineitem.l_suppkey -> Sort (cost=2921830.80..2967302.26 rows=18188581 width=21) (actual time=129686.013..147644.109 rows=18194084 loops=1) Sort Key: lineitem.l_partkey, lineitem.l_suppkey Sort Method: external merge Disk: 551928kB -> Bitmap Heap Scan on lineitem (cost=191420.72..707288.74 rows=18188581 width=21) (actual time=12280.877..97715.337 rows=18195269 loops=1) Recheck Cond: ((l_shipdate >= '1994-01-01'::date) AND (l_shipdate < '1995-01-01 00:00:00'::timestamp without time zone)) Rows Removed by Index Recheck: 64500318 Heap Blocks: exact=643068 lossy=1586943 -> Bitmap Index Scan on idx_l_shipdate (cost=0.00..186873.58 rows=18188581 width=0) (actual time=11605.457..11605.457 rows=18195269 loops=1) Index Cond: ((l_shipdate >= '1994-01-01'::date) AND (l_shipdate < '1995-01-01 00:00:00'::timestamp without time zone)) -> Index Scan using supplier_pkey on supplier (cost=0.42..0.44 rows=1 width=64) (actual time=0.010..0.011 rows=1 loops=89512) Index Cond: (s_suppkey = lineitem.l_suppkey) -> Index Scan using nation_pkey on nation (cost=0.14..0.16 rows=1 width=4) (actual time=0.006..0.006 rows=0 loops=89512) Index Cond: (n_nationkey = supplier.s_nationkey) Filter: (n_name = 'EGYPT'::bpchar) Rows Removed by Filter: 1 Planning time: 5.461 ms Execution time: 210810.480 ms (44 rows)