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 = 'JORDAN' and n2.n_name = 'BRAZIL') or (n1.n_name = 'BRAZIL' and n2.n_name = 'JORDAN') ) 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=1970881.04..1970888.70 rows=3064 width=64) Sort Key: n1.n_name, n2.n_name, (date_part('year'::text, (lineitem.l_shipdate)::timestamp without time zone)) -> HashAggregate (cost=1970657.66..1970703.62 rows=3064 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..1969748.44 rows=60615 width=64) Hash Cond: (lineitem.l_suppkey = supplier.s_suppkey) Join Filter: (((n1.n_name = 'JORDAN'::bpchar) AND (n2.n_name = 'BRAZIL'::bpchar)) OR ((n1.n_name = 'BRAZIL'::bpchar) AND (n2.n_name = 'JORDAN'::bpchar))) -> Nested Loop (cost=58604.97..1957915.71 rows=1457015 width=42) -> Hash Join (cost=58604.40..530594.42 rows=1201199 width=30) Hash Cond: (orders.o_custkey = customer.c_custkey) -> Seq Scan on orders (cost=0.00..403671.84 rows=15014984 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 = 'BRAZIL'::bpchar) OR (n_name = 'JORDAN'::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 = 'JORDAN'::bpchar) OR (n_name = 'BRAZIL'::bpchar)) Planning time: 11.526 ms (28 rows) COMMIT; COMMIT