BEGIN; BEGIN EXPLAIN select supp_nation, cust_nation, l_year, sum(volume) as revenue from ( select n1.n_name as supp_nation, n2.n_name as cust_nation, extract(year from l_shipdate) as l_year, l_extendedprice * (1 - l_discount) as volume from supplier, lineitem, orders, customer, nation n1, nation n2 where s_suppkey = l_suppkey and o_orderkey = l_orderkey and c_custkey = o_custkey and s_nationkey = n1.n_nationkey and c_nationkey = n2.n_nationkey and ( (n1.n_name = 'UNITED KINGDOM' and n2.n_name = 'KENYA') or (n1.n_name = 'KENYA' and n2.n_name = 'UNITED KINGDOM') ) and l_shipdate between date '1995-01-01' and date '1996-12-31' ) as shipping group by supp_nation, cust_nation, l_year order by supp_nation, cust_nation, l_year; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sort (cost=1968906.69..1968914.33 rows=3059 width=64) Sort Key: n1.n_name, n2.n_name, (date_part('year'::text, (lineitem.l_shipdate)::timestamp without time zone)) -> HashAggregate (cost=1968683.70..1968729.59 rows=3059 width=64) Group Key: n1.n_name, n2.n_name, date_part('year'::text, (lineitem.l_shipdate)::timestamp without time zone) -> Hash Join (cost=62340.37..1967777.09 rows=60441 width=64) Hash Cond: (lineitem.l_suppkey = supplier.s_suppkey) Join Filter: (((n1.n_name = 'UNITED KINGDOM'::bpchar) AND (n2.n_name = 'KENYA'::bpchar)) OR ((n1.n_name = 'KENYA'::bpchar) AND (n2.n_name = 'UNITED KINGDOM'::bpchar))) -> Nested Loop (cost=58604.97..1955968.20 rows=1452673 width=42) -> Hash Join (cost=58604.40..530123.40 rows=1200000 width=30) Hash Cond: (orders.o_custkey = customer.c_custkey) -> Seq Scan on orders (cost=0.00..403269.00 rows=15000000 width=8) -> Hash (cost=57104.40..57104.40 rows=120000 width=30) -> Hash Join (cost=1.40..57104.40 rows=120000 width=30) Hash Cond: (customer.c_nationkey = n2.n_nationkey) -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=8) -> Hash (cost=1.38..1.38 rows=2 width=30) -> Seq Scan on nation n2 (cost=0.00..1.38 rows=2 width=30) Filter: ((n_name = 'KENYA'::bpchar) OR (n_name = 'UNITED KINGDOM'::bpchar)) -> Index Scan using lineitem_l_orderkey_l_linenumber_l_shipdate_idx on lineitem (cost=0.56..1.15 rows=4 width=20) Index Cond: ((l_orderkey = orders.o_orderkey) AND (l_shipdate >= '1995-01-01'::date) AND (l_shipdate <= '1996-12-31'::date)) -> Hash (cost=3635.40..3635.40 rows=8000 width=30) -> Hash Join (cost=1.40..3635.40 rows=8000 width=30) Hash Cond: (supplier.s_nationkey = n1.n_nationkey) -> Seq Scan on supplier (cost=0.00..3179.00 rows=100000 width=8) -> Hash (cost=1.38..1.38 rows=2 width=30) -> Seq Scan on nation n1 (cost=0.00..1.38 rows=2 width=30) Filter: ((n_name = 'UNITED KINGDOM'::bpchar) OR (n_name = 'KENYA'::bpchar)) Planning time: 4.316 ms (28 rows) COMMIT; COMMIT