BEGIN; BEGIN 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 'cornflower%' and ps_availqty > ( select 0.5 * sum(l_quantity) from lineitem where l_partkey = ps_partkey and l_suppkey = ps_suppkey and l_shipdate >= '1995-01-01' and l_shipdate < cast(date '1995-01-01' + interval '1 year' as date) ) ) and s_nationkey = n_nationkey and n_name = 'BRAZIL' order by s_name; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Sort (cost=12740183.38..12740186.31 rows=1174 width=51) Sort Key: supplier.s_name -> Nested Loop (cost=12735713.87..12740123.52 rows=1174 width=51) Join Filter: (supplier.s_nationkey = nation.n_nationkey) -> Seq Scan on nation (cost=0.00..1.31 rows=1 width=4) Filter: (n_name = 'BRAZIL'::bpchar) -> Hash Semi Join (cost=12735713.87..12739755.20 rows=29361 width=55) Hash Cond: (supplier.s_suppkey = partsupp.ps_suppkey) -> Seq Scan on supplier (cost=0.00..3179.00 rows=100000 width=59) -> Hash (cost=12735346.86..12735346.86 rows=29361 width=4) -> HashAggregate (cost=12734759.64..12735053.25 rows=29361 width=4) -> Nested Loop (cost=0.00..12734686.23 rows=29361 width=4) -> Seq Scan on part (cost=0.00..65522.00 rows=22021 width=4) Filter: ((p_name)::text ~~ 'cornflower%'::text) -> Index Scan using pk_partsupp on partsupp (cost=0.00..575.31 rows=1 width=8) Index Cond: (ps_partkey = part.p_partkey) Filter: ((ps_availqty)::double precision > (SubPlan 1)) SubPlan 1 -> Aggregate (cost=140.92..140.94 rows=1 width=4) -> Index Scan using lineitem_l_partkey_l_quantity_l_shipmode_idx on lineitem (cost=0.00..140.92 rows=1 width=4) Index Cond: (l_partkey = partsupp.ps_partkey) Filter: ((l_shipdate >= '1995-01-01'::date) AND (l_shipdate < '1996-01-01'::date) AND (l_suppkey = partsupp.ps_suppkey)) (22 rows) COMMIT; COMMIT