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 = 'RUSSIA' and n2.n_name = 'ROMANIA') or (n1.n_name = 'ROMANIA' and n2.n_name = 'RUSSIA') ) 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=23497634.98..23497642.67 rows=3074 width=64) Sort Key: n1.n_name, n2.n_name, (date_part('year'::text, (lineitem.l_shipdate)::timestamp without time zone)) -> HashAggregate (cost=23497410.80..23497456.91 rows=3074 width=64) Group Key: n1.n_name, n2.n_name, date_part('year'::text, (lineitem.l_shipdate)::timestamp without time zone) -> Remote Subquery Scan on all (datanode_1_1,datanode_2_1,datanode_3_1,datanode_4_1,datanode_5_1,datanode_6_1,datanode_7_1,datanode_8_1) (cost=9170026.01..23494771.14 rows=175977 width=64) -> HashAggregate (cost=9170026.01..23494771.14 rows=3074 width=64) Group Key: n1.n_name, n2.n_name, date_part('year'::text, (lineitem.l_shipdate)::timestamp without time zone) -> Hash Join (cost=9170026.01..23494771.14 rows=175977 width=64) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Join Filter: (((n1.n_name = 'RUSSIA'::bpchar) AND (n2.n_name = 'ROMANIA'::bpchar)) OR ((n1.n_name = 'ROMANIA'::bpchar) AND (n2.n_name = 'RUSSIA'::bpchar))) -> Hash Join (cost=3910433.79..18136263.43 rows=14603178 width=42) Hash Cond: (lineitem.l_suppkey = supplier.s_suppkey) -> Bitmap Heap Scan on lineitem (cost=3873084.39..17268358.28 rows=182539726 width=20) Recheck Cond: ((l_shipdate >= '1995-01-01'::date) AND (l_shipdate <= '1996-12-31'::date)) -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..3827449.46 rows=182539726 width=0) Index Cond: ((l_shipdate >= '1995-01-01'::date) AND (l_shipdate <= '1996-12-31'::date)) -> Hash (cost=36349.40..36349.40 rows=80000 width=30) -> Hash Join (cost=1.40..36349.40 rows=80000 width=30) Hash Cond: (supplier.s_nationkey = n1.n_nationkey) -> Seq Scan on supplier (cost=0.00..31798.00 rows=1000000 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 = 'RUSSIA'::bpchar) OR (n_name = 'ROMANIA'::bpchar)) -> Hash (cost=5216157.32..5216157.32 rows=3474792 width=30) -> Hash Join (cost=586022.40..5216157.32 rows=3474792 width=30) Hash Cond: (orders.o_custkey = customer.c_custkey) -> Seq Scan on orders (cost=0.00..4032887.00 rows=150000000 width=8) -> Hash (cost=571022.40..571022.40 rows=1200000 width=30) -> Hash Join (cost=1.40..571022.40 rows=1200000 width=30) Hash Cond: (customer.c_nationkey = n2.n_nationkey) -> Seq Scan on customer (cost=0.00..502771.00 rows=15000000 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 = 'ROMANIA'::bpchar) OR (n_name = 'RUSSIA'::bpchar)) (34 rows) COMMIT; COMMIT