BEGIN; BEGIN EXPLAIN select o_orderpriority, count(*) as order_count from orders where o_orderdate >= date '1997-10-01' and o_orderdate < cast(date '1997-10-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=1138165.98..1138165.98 rows=1 width=16) Sort Key: orders.o_orderpriority -> HashAggregate (cost=1138165.96..1138165.97 rows=1 width=16) Group Key: orders.o_orderpriority -> Nested Loop Semi Join (cost=12130.70..1137405.73 rows=152045 width=16) -> Bitmap Heap Scan on orders (cost=12130.13..274230.23 rows=571873 width=20) Recheck Cond: ((o_orderdate >= '1997-10-01'::date) AND (o_orderdate < '1998-01-01'::date)) -> Bitmap Index Scan on orders_o_orderdate_o_orderkey_idx (cost=0.00..11987.16 rows=571873 width=0) Index Cond: ((o_orderdate >= '1997-10-01'::date) AND (o_orderdate < '1998-01-01'::date)) -> Index Scan using lineitem_l_orderkey_idx_part1 on lineitem (cost=0.56..4.56 rows=5 width=4) Index Cond: (l_orderkey = orders.o_orderkey) Planning time: 2.406 ms (12 rows) COMMIT; COMMIT