BEGIN; BEGIN EXPLAIN (ANALYZE, BUFFERS) select o_orderpriority, count(*) as order_count from orders where o_orderdate >= date '1995-04-01' and o_orderdate < cast(date '1995-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=1485669.35..1485669.36 rows=1 width=16) (actual time=13040.716..13040.717 rows=5 loops=1) Sort Key: orders.o_orderpriority Sort Method: quicksort Memory: 25kB Buffers: shared hit=2638069 read=460618 -> HashAggregate (cost=1485669.33..1485669.34 rows=1 width=16) (actual time=13040.668..13040.670 rows=5 loops=1) Group Key: orders.o_orderpriority Buffers: shared hit=2638064 read=460618 -> Nested Loop Semi Join (cost=5898.53..1484907.55 rows=152357 width=16) (actual time=27.875..12752.543 rows=519963 loops=1) Buffers: shared hit=2638064 read=460618 -> Bitmap Heap Scan on orders (cost=5897.97..271030.60 rows=571509 width=20) (actual time=27.845..5217.129 rows=566937 loops=1) Recheck Cond: ((o_orderdate >= '1995-04-01'::date) AND (o_orderdate < '1995-07-01'::date)) Rows Removed by Index Recheck: 14433063 Heap Blocks: lossy=256560 Buffers: shared hit=164163 read=92408 -> Bitmap Index Scan on orders_o_orderkey_o_orderdate_brin_idx (cost=0.00..5755.09 rows=571509 width=0) (actual time=27.674..27.674 rows=2566400 loops=1) Index Cond: ((o_orderdate >= '1995-04-01'::date) AND (o_orderdate < '1995-07-01'::date)) Buffers: shared hit=3 read=8 -> Index Scan using pk_lineitem on lineitem (cost=0.56..7.16 rows=5 width=4) (actual time=0.012..0.012 rows=1 loops=566937) Index Cond: (l_orderkey = orders.o_orderkey) Filter: (l_commitdate < l_receiptdate) Rows Removed by Filter: 1 Buffers: shared hit=2473901 read=368210 Planning time: 2.308 ms Execution time: 13040.843 ms (24 rows) COMMIT; COMMIT