EXPLAIN select l_orderkey, sum(l_extendedprice * (1 - l_discount)) as revenue, o_orderdate, o_shippriority from customer, orders, lineitem where c_mktsegment = 'HOUSEHOLD' and c_custkey = o_custkey and l_orderkey = o_orderkey and o_orderdate < date '1995-03-26' and l_shipdate > date '1995-03-26' group by l_orderkey, o_orderdate, o_shippriority order by revenue desc, o_orderdate LIMIT 10; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------- Limit (cost=3575362.31..3575362.34 rows=10 width=20) -> Sort (cost=3575362.31..3583114.43 rows=3100846 width=20) Sort Key: (sum((lineitem.l_extendedprice * (1::double precision - lineitem.l_discount)))), orders.o_orderdate -> GroupAggregate (cost=3423080.88..3508354.15 rows=3100846 width=20) Group Key: lineitem.l_orderkey, orders.o_orderdate, orders.o_shippriority -> Sort (cost=3423080.88..3430833.00 rows=3100846 width=20) Sort Key: lineitem.l_orderkey, orders.o_orderdate, orders.o_shippriority -> Hash Join (cost=675987.95..2961554.09 rows=3100846 width=20) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) -> Seq Scan on lineitem (cost=0.00..1815233.20 rows=31979328 width=12) Filter: (l_shipdate > '1995-03-26'::date) -> Hash (cost=650705.36..650705.36 rows=1454447 width=12) -> Hash Join (cost=58935.25..650705.36 rows=1454447 width=12) Hash Cond: (orders.o_custkey = customer.c_custkey) -> Seq Scan on orders (cost=0.00..440776.19 rows=7306338 width=16) Filter: (o_orderdate < '1995-03-26'::date) -> Hash (cost=54035.46..54035.46 rows=298623 width=4) -> Seq Scan on customer (cost=0.00..54035.46 rows=298623 width=4) Filter: (c_mktsegment = 'HOUSEHOLD'::bpchar) (19 rows)