BEGIN; BEGIN EXPLAIN (ANALYZE, BUFFERS) select o_orderpriority, count(*) as order_count from orders where o_orderdate >= date '1997-04-01' and o_orderdate < cast(date '1997-04-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=1287878.23..1287878.23 rows=1 width=16) (actual time=118904.017..118904.018 rows=5 loops=1) Sort Key: orders.o_orderpriority Sort Method: quicksort Memory: 25kB Buffers: shared hit=743658 read=757712 dirtied=584 written=4515 -> HashAggregate (cost=1287878.21..1287878.22 rows=1 width=16) (actual time=118903.860..118903.862 rows=5 loops=1) Buffers: shared hit=743653 read=757712 dirtied=584 written=4515 -> Hash Join (cost=1019176.63..1287120.46 rows=151551 width=16) (actual time=101765.701..118474.208 rows=520909 loops=1) Hash Cond: (orders.o_orderkey = lineitem.l_orderkey) Buffers: shared hit=743653 read=757712 dirtied=584 written=4515 -> Bitmap Heap Scan on orders (cost=11965.65..274463.53 rows=564659 width=20) (actual time=565.072..5434.093 rows=568328 loops=1) Recheck Cond: ((o_orderdate >= '1997-04-01'::date) AND (o_orderdate < '1997-07-01'::date)) Buffers: shared hit=225427 read=4148 written=874 -> Bitmap Index Scan on orders_o_orderdate_o_orderkey_idx (cost=0.00..11824.49 rows=564659 width=0) (actual time=460.925..460.925 rows=569468 loops=1) Index Cond: ((o_orderdate >= '1997-04-01'::date) AND (o_orderdate < '1997-07-01'::date)) Buffers: shared hit=94 read=1461 written=633 -> Hash (cost=990386.13..990386.13 rows=1345988 width=4) (actual time=101198.980..101198.980 rows=13767168 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 484002kB Buffers: shared hit=518226 read=753564 dirtied=584 written=3641 -> HashAggregate (cost=976926.25..990386.13 rows=1345988 width=4) (actual time=83612.336..94375.073 rows=13767168 loops=1) Buffers: shared hit=518226 read=753564 dirtied=584 written=3641 -> Index Scan using lineitem_l_orderkey_idx_part1 on lineitem (cost=0.00..926788.28 rows=20055191 width=4) (actual time=0.210..40230.173 rows=37966418 loops=1) Buffers: shared hit=518226 read=753564 dirtied=584 written=3641 Total runtime: 119371.263 ms (23 rows) COMMIT; COMMIT