EXPLAIN select 100.00 * sum(case when p_type like 'PROMO%' then l_extendedprice * (1 - l_discount) else 0 end) / sum(l_extendedprice * (1 - l_discount)) as promo_revenue from lineitem, part where l_partkey = p_partkey and l_shipdate >= date '1994-04-01' and l_shipdate < date '1994-04-01' + interval '1 month'; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=1167121.22..1167121.24 rows=1 width=29) -> Hash Join (cost=114114.36..1155535.66 rows=662032 width=29) Hash Cond: (lineitem.l_partkey = part.p_partkey) -> Bitmap Heap Scan on lineitem (cost=14816.64..1020400.70 rows=698154 width=12) Recheck Cond: ((l_shipdate >= '1994-04-01'::date) AND (l_shipdate < '1994-05-01 00:00:00'::timestamp without time zone)) -> Bitmap Index Scan on i_l_shipdate (cost=0.00..14642.11 rows=698154 width=0) Index Cond: ((l_shipdate >= '1994-04-01'::date) AND (l_shipdate < '1994-05-01 00:00:00'::timestamp without time zone)) -> Hash (cost=60626.43..60626.43 rows=1999943 width=25) -> Seq Scan on part (cost=0.00..60626.43 rows=1999943 width=25) (9 rows)