BEGIN; BEGIN EXPLAIN (ANALYZE, BUFFERS) select o_orderpriority, count(*) as order_count from orders where o_orderdate >= date '1993-07-01' and o_orderdate < cast(date '1993-07-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=1301602.13..1301602.14 rows=1 width=16) (actual time=74871.733..74871.735 rows=5 loops=1) Sort Key: orders.o_orderpriority Sort Method: quicksort Memory: 25kB Buffers: shared hit=631695 read=890364 dirtied=301 written=113 -> HashAggregate (cost=1301602.11..1301602.12 rows=1 width=16) (actual time=74871.579..74871.580 rows=5 loops=1) Buffers: shared hit=631690 read=890364 dirtied=301 written=113 -> Hash Join (cost=1029909.71..1300819.57 rows=156508 width=16) (actual time=62425.659..74601.797 rows=526210 loops=1) Hash Cond: (orders.o_orderkey = lineitem.l_orderkey) Buffers: shared hit=631690 read=890364 dirtied=301 written=113 -> Bitmap Heap Scan on orders (cost=12645.94..277939.53 rows=582239 width=20) (actual time=520.533..2848.514 rows=573846 loops=1) Recheck Cond: ((o_orderdate >= '1993-07-01'::date) AND (o_orderdate < '1993-10-01'::date)) Buffers: shared hit=119277 read=113359 written=28 -> Bitmap Index Scan on orders_o_orderdate_o_orderkey_idx (cost=0.00..12500.38 rows=582239 width=0) (actual time=389.862..389.862 rows=581038 loops=1) Index Cond: ((o_orderdate >= '1993-07-01'::date) AND (o_orderdate < '1993-10-01'::date)) Buffers: shared hit=2 read=1660 written=4 -> Hash (cost=1000245.19..1000245.19 rows=1361486 width=4) (actual time=61903.224..61903.224 rows=13753463 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 483521kB Buffers: shared hit=512413 read=777005 dirtied=301 written=85 -> HashAggregate (cost=986630.33..1000245.19 rows=1361486 width=4) (actual time=49069.777..58306.703 rows=13753463 loops=1) Buffers: shared hit=512413 read=777005 dirtied=301 written=85 -> Index Scan using lineitem_l_orderkey_idx_part1 on lineitem (cost=0.00..935992.73 rows=20255041 width=4) (actual time=0.182..21429.726 rows=37928434 loops=1) Buffers: shared hit=512413 read=777005 dirtied=301 written=85 Total runtime: 75122.678 ms (23 rows) COMMIT; COMMIT