EXPLAIN select s_name, s_address from supplier, nation where s_suppkey in ( select distinct (ps_suppkey) from partsupp, part where ps_partkey=p_partkey and p_name like 'red%' and ps_availqty > ( select 0.5 * sum(l_quantity) from lineitem where l_partkey = ps_partkey and l_suppkey = ps_suppkey and l_shipdate >= '1994-01-01' and l_shipdate < date '1994-01-01' + interval '1 year' ) ) and s_nationkey = n_nationkey and n_name = 'CANADA' order by s_name; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------ Sort (cost=98489.53..98489.56 rows=11 width=51) Sort Key: supplier.s_name -> Hash Join (cost=96669.08..98489.34 rows=11 width=51) Hash Cond: (supplier.s_nationkey = nation.n_nationkey) -> Nested Loop (cost=96667.75..98486.91 rows=267 width=55) -> HashAggregate (cost=96667.46..96670.13 rows=267 width=4) Group Key: partsupp.ps_suppkey -> Nested Loop (cost=0.43..96666.79 rows=267 width=4) -> Seq Scan on part (cost=0.00..65626.29 rows=200 width=4) Filter: ((p_name)::text ~~ 'red%'::text) -> Index Scan using i_ps_partkey on partsupp (cost=0.43..155.14 rows=6 width=8) Index Cond: (ps_partkey = part.p_partkey) Filter: ((ps_availqty)::double precision > (SubPlan 1)) SubPlan 1 -> Aggregate (cost=8.59..8.60 rows=1 width=4) -> Index Scan using i_l_suppkey_partkey on lineitem (cost=0.56..8.59 rows=1 width=4) Index Cond: ((l_partkey = partsupp.ps_partkey) AND (l_suppkey = partsupp.ps_suppkey)) Filter: ((l_shipdate >= '1994-01-01'::date) AND (l_shipdate < '1995-01-01 00:00:00'::timestamp without time zone)) -> Index Scan using supplier_pkey on supplier (cost=0.29..6.78 rows=1 width=59) Index Cond: (s_suppkey = partsupp.ps_suppkey) -> Hash (cost=1.31..1.31 rows=1 width=4) -> Seq Scan on nation (cost=0.00..1.31 rows=1 width=4) Filter: (n_name = 'CANADA'::bpchar) (23 rows)