EXPLAIN select o_orderpriority, count(*) as order_count from orders where o_orderdate >= date '1997-02-01' and o_orderdate < date '1997-02-01' + interval '3 months' 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=760565.93..760565.94 rows=1 width=16) Sort Key: orders.o_orderpriority -> HashAggregate (cost=760565.91..760565.92 rows=1 width=16) Group Key: orders.o_orderpriority -> Nested Loop Semi Join (cost=11666.23..760483.76 rows=16430 width=16) -> Bitmap Heap Scan on orders (cost=11665.66..273187.41 rows=549583 width=20) Recheck Cond: ((o_orderdate >= '1997-02-01'::date) AND (o_orderdate < '1997-05-01 00:00:00'::timestamp without time zone)) -> Bitmap Index Scan on i_o_orderdate (cost=0.00..11528.26 rows=549583 width=0) Index Cond: ((o_orderdate >= '1997-02-01'::date) AND (o_orderdate < '1997-05-01 00:00:00'::timestamp without time zone)) -> Index Scan using i_l_orderkey on lineitem (cost=0.56..14.60 rows=45 width=4) Index Cond: (l_orderkey = orders.o_orderkey) Filter: (l_commitdate < l_receiptdate) (12 rows)