BEGIN; BEGIN EXPLAIN (ANALYZE, BUFFERS) select o_orderpriority, count(*) as order_count from orders where o_orderdate >= date '1995-03-01' and o_orderdate < cast(date '1995-03-01' + interval '3 month' as date) and exists ( select * from lineitem where l_orderkey = o_orderkey and l_commitdate < l_receiptdate ) group by o_orderpriority order by o_orderpriority; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sort (cost=1302120.56..1302120.57 rows=1 width=16) (actual time=90316.604..90316.605 rows=5 loops=1) Sort Key: orders.o_orderpriority Sort Method: quicksort Memory: 25kB Buffers: shared hit=969470 read=552884 written=10535 -> HashAggregate (cost=1302120.54..1302120.55 rows=1 width=16) (actual time=90316.462..90316.465 rows=5 loops=1) Buffers: shared hit=969465 read=552884 written=10535 -> Hash Join (cost=1030262.25..1301337.46 rows=156616 width=16) (actual time=76032.939..89912.805 rows=525870 loops=1) Hash Cond: (orders.o_orderkey = lineitem.l_orderkey) Buffers: shared hit=969465 read=552884 written=10535 -> Bitmap Heap Scan on orders (cost=12797.15..278194.94 rows=589186 width=20) (actual time=297.202..4226.192 rows=573749 loops=1) Recheck Cond: ((o_orderdate >= '1995-03-01'::date) AND (o_orderdate < '1995-06-01'::date)) Buffers: shared hit=91294 read=141637 written=76 -> Bitmap Index Scan on orders_o_orderdate_o_orderkey_idx (cost=0.00..12649.85 rows=589186 width=0) (actual time=221.941..221.941 rows=581258 loops=1) Index Cond: ((o_orderdate >= '1995-03-01'::date) AND (o_orderdate < '1995-06-01'::date)) Buffers: shared hit=2 read=1662 -> Hash (cost=1000635.57..1000635.57 rows=1346362 width=4) (actual time=75734.061..75734.061 rows=13753463 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 483521kB Buffers: shared hit=878171 read=411247 written=10459 -> HashAggregate (cost=987171.95..1000635.57 rows=1346362 width=4) (actual time=63135.989..72613.370 rows=13753463 loops=1) Buffers: shared hit=878171 read=411247 written=10459 -> Index Scan using lineitem_l_orderkey_idx_part1 on lineitem (cost=0.00..936533.65 rows=20255322 width=4) (actual time=0.136..30449.731 rows=37928434 loops=1) Buffers: shared hit=878171 read=411247 written=10459 Total runtime: 90518.680 ms (23 rows) COMMIT; COMMIT