BEGIN; BEGIN EXPLAIN (ANALYZE, BUFFERS) select o_orderpriority, count(*) as order_count from orders where o_orderdate >= date '1997-09-01' and o_orderdate < cast(date '1997-09-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=1294694.02..1294694.03 rows=1 width=16) (actual time=83809.118..83809.119 rows=5 loops=1) Sort Key: orders.o_orderpriority Sort Method: quicksort Memory: 25kB Buffers: shared hit=577658 read=935893 written=16464 -> HashAggregate (cost=1294694.00..1294694.01 rows=1 width=16) (actual time=83808.964..83808.965 rows=5 loops=1) Buffers: shared hit=577653 read=935893 written=16464 -> Hash Join (cost=1024660.83..1293928.40 rows=153121 width=16) (actual time=73543.443..83561.230 rows=519671 loops=1) Hash Cond: (orders.o_orderkey = lineitem.l_orderkey) Buffers: shared hit=577653 read=935893 written=16464 -> Bitmap Heap Scan on orders (cost=12283.96..276081.38 rows=566828 width=20) (actual time=500.821..2102.053 rows=567035 loops=1) Recheck Cond: ((o_orderdate >= '1997-09-01'::date) AND (o_orderdate < '1997-12-01'::date)) Buffers: shared hit=229066 read=1644 -> Bitmap Index Scan on orders_o_orderdate_o_orderkey_idx (cost=0.00..12142.26 rows=566828 width=0) (actual time=399.238..399.238 rows=570857 loops=1) Index Cond: ((o_orderdate >= '1997-09-01'::date) AND (o_orderdate < '1997-12-01'::date)) Buffers: shared read=1629 -> Hash (cost=995358.29..995358.29 rows=1361486 width=4) (actual time=73040.700..73040.700 rows=13767175 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 484003kB Buffers: shared hit=348587 read=934249 written=16464 -> HashAggregate (cost=981743.43..995358.29 rows=1361486 width=4) (actual time=58180.408..68209.783 rows=13767175 loops=1) Buffers: shared hit=348587 read=934249 written=16464 -> Index Scan using lineitem_l_orderkey_idx_part1 on lineitem (cost=0.00..931356.56 rows=20154748 width=4) (actual time=0.180..25507.352 rows=37965693 loops=1) Buffers: shared hit=348587 read=934249 written=16464 Total runtime: 84122.045 ms (23 rows) COMMIT; COMMIT