BEGIN; BEGIN EXPLAIN (ANALYZE, BUFFERS) select o_orderpriority, count(*) as order_count from orders where o_orderdate >= date '1997-07-01' and o_orderdate < cast(date '1997-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=1485059.38..1485059.39 rows=1 width=16) (actual time=14185.656..14185.656 rows=5 loops=1) Sort Key: orders.o_orderpriority Sort Method: quicksort Memory: 25kB Buffers: shared hit=2522256 read=611372 -> HashAggregate (cost=1485059.36..1485059.37 rows=1 width=16) (actual time=14185.608..14185.608 rows=5 loops=1) Group Key: orders.o_orderpriority Buffers: shared hit=2522251 read=611372 -> Nested Loop Semi Join (cost=5966.81..1484279.46 rows=155980 width=16) (actual time=27.966..13874.827 rows=526449 loops=1) Buffers: shared hit=2522251 read=611372 -> Bitmap Heap Scan on orders (cost=5966.24..268160.79 rows=578170 width=20) (actual time=27.926..4273.666 rows=574557 loops=1) Recheck Cond: ((o_orderdate >= '1997-07-01'::date) AND (o_orderdate < '1997-10-01'::date)) Rows Removed by Index Recheck: 14440443 Heap Blocks: lossy=253522 Buffers: shared hit=252591 read=942 -> Bitmap Index Scan on orders_o_orderkey_o_orderdate_brin_idx (cost=0.00..5821.70 rows=578170 width=0) (actual time=27.759..27.759 rows=2535680 loops=1) Index Cond: ((o_orderdate >= '1997-07-01'::date) AND (o_orderdate < '1997-10-01'::date)) Buffers: shared hit=3 read=8 -> Index Scan using pk_lineitem on lineitem (cost=0.56..7.04 rows=5 width=4) (actual time=0.016..0.016 rows=1 loops=574557) Index Cond: (l_orderkey = orders.o_orderkey) Filter: (l_commitdate < l_receiptdate) Rows Removed by Filter: 1 Buffers: shared hit=2269660 read=610430 Planning time: 2.075 ms Execution time: 14185.777 ms (24 rows) COMMIT; COMMIT