BEGIN; BEGIN EXPLAIN (ANALYZE, BUFFERS) select o_orderpriority, count(*) as order_count from orders where o_orderdate >= date '1997-08-01' and o_orderdate < cast(date '1997-08-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=1288900.13..1288900.13 rows=1 width=16) (actual time=112356.495..112356.496 rows=5 loops=1) Sort Key: orders.o_orderpriority Sort Method: quicksort Memory: 25kB Buffers: shared hit=1218515 read=283641 dirtied=1062 written=7567 -> HashAggregate (cost=1288900.11..1288900.12 rows=1 width=16) (actual time=112356.323..112356.325 rows=5 loops=1) Buffers: shared hit=1218510 read=283641 dirtied=1062 written=7567 -> Hash Join (cost=1019634.94..1288113.25 rows=157372 width=16) (actual time=98459.974..111975.628 rows=525898 loops=1) Hash Cond: (orders.o_orderkey = lineitem.l_orderkey) Buffers: shared hit=1218510 read=283641 dirtied=1062 written=7567 -> Bitmap Heap Scan on orders (cost=12423.95..275247.16 rows=586347 width=20) (actual time=612.388..3318.320 rows=573747 loops=1) Recheck Cond: ((o_orderdate >= '1997-08-01'::date) AND (o_orderdate < '1997-11-01'::date)) Buffers: shared hit=225341 read=5020 -> Bitmap Index Scan on orders_o_orderdate_o_orderkey_idx (cost=0.00..12277.37 rows=586347 width=0) (actual time=503.477..503.477 rows=575418 loops=1) Index Cond: ((o_orderdate >= '1997-08-01'::date) AND (o_orderdate < '1997-11-01'::date)) Buffers: shared hit=2 read=1570 -> Hash (cost=990386.13..990386.13 rows=1345988 width=4) (actual time=97845.403..97845.403 rows=13753462 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 483521kB Buffers: shared hit=993169 read=278621 dirtied=1062 written=7567 -> HashAggregate (cost=976926.25..990386.13 rows=1345988 width=4) (actual time=83345.107..94050.771 rows=13753462 loops=1) Buffers: shared hit=993169 read=278621 dirtied=1062 written=7567 -> Index Scan using lineitem_l_orderkey_idx_part1 on lineitem (cost=0.00..926788.28 rows=20055191 width=4) (actual time=0.481..40690.938 rows=37928885 loops=1) Buffers: shared hit=993169 read=278621 dirtied=1062 written=7567 Total runtime: 112705.723 ms (23 rows) COMMIT; COMMIT