BEGIN; BEGIN EXPLAIN select nation, o_year, sum(amount) as sum_profit from ( select n_name as nation, extract(year from o_orderdate) as o_year, l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount from part, supplier, lineitem, partsupp, orders, nation where s_suppkey = l_suppkey and ps_suppkey = l_suppkey and ps_partkey = l_partkey and p_partkey = l_partkey and o_orderkey = l_orderkey and s_nationkey = n_nationkey and p_name like '%cream%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=19809409.90..23719090.44 rows=3 width=46) Group Key: nation.n_name, date_part('year'::text, (orders.o_orderdate)::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=19809409.90..23719090.34 rows=3 width=46) -> GroupAggregate (cost=19809409.90..23719090.34 rows=3 width=46) Group Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) -> Sort (cost=23719090.37..23719090.37 rows=3 width=46) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) DESC -> Hash Join (cost=19809409.90..23719090.34 rows=3 width=46) Hash Cond: (supplier.s_nationkey = nation.n_nationkey) -> Nested Loop (cost=19809408.34..23719088.72 rows=3 width=24) -> 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=19809508.14..23719168.14 rows=3 width=24) Distribute results by H: l_orderkey -> Hash Join (cost=19809408.14..23719068.05 rows=3 width=24) Hash Cond: ((partsupp.ps_suppkey = supplier.s_suppkey) AND (partsupp.ps_partkey = lineitem.l_partkey)) -> Seq Scan on partsupp (cost=0.00..2509659.32 rows=80000032 width=12) -> Hash (cost=19736229.95..19736229.95 rows=4878546 width=36) -> Hash Join (cost=712665.53..19736229.95 rows=4878546 width=36) Hash Cond: (lineitem.l_suppkey = supplier.s_suppkey) -> Hash Join (cost=668367.53..19624851.94 rows=4878546 width=28) Hash Cond: (lineitem.l_partkey = part.p_partkey) -> 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=100.00..34058755.63 rows=600037888 width=24) Distribute results by H: l_partkey -> Seq Scan on lineitem (cost=0.00..16657556.88 rows=600037888 width=24) -> Hash (cost=655241.12..655241.12 rows=1050112 width=4) -> Seq Scan on part (cost=0.00..655241.12 rows=1050112 width=4) Filter: ((p_name)::text ~~ '%cream%'::text) -> Hash (cost=31798.00..31798.00 rows=1000000 width=8) -> Seq Scan on supplier (cost=0.00..31798.00 rows=1000000 width=8) -> Index Scan using pk_orders on orders (cost=0.20..6.88 rows=1 width=8) Index Cond: (o_orderkey = lineitem.l_orderkey) -> Hash (cost=1.25..1.25 rows=25 width=30) -> Seq Scan on nation (cost=0.00..1.25 rows=25 width=30) (32 rows) COMMIT; COMMIT