BEGIN; BEGIN EXPLAIN select cntrycode, count(*) as numcust, sum(c_acctbal) as totacctbal from ( select substr(c_phone, 1, 2) as cntrycode, c_acctbal from customer where substr(c_phone, 1, 2) in ('12', '17', '21', '20', '15', '26', '10') and c_acctbal > ( select avg(c_acctbal) from customer where c_acctbal > 0.00 and substr(c_phone, 1, 2) in ('12', '17', '21', '20', '15', '26', '10') ) and not exists ( select * from orders where o_custkey = c_custkey ) ) as vip group by cntrycode order by cntrycode; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=6882905.85..7810973.37 rows=1 width=20) Group Key: substr((customer.c_phone)::text, 1, 2) InitPlan 1 (returns $0) -> Remote Subquery Scan on all (datanode_8_1) (cost=385361.80..385361.81 rows=1 width=4) -> Aggregate (cost=385361.80..385361.81 rows=1 width=4) -> Bitmap Heap Scan on customer customer_1 (cost=124.23..384168.73 rows=477227 width=4) Recheck Cond: ((substr((c_phone)::text, 1, 2) = ANY ('{12,17,21,20,15,26,10}'::text[])) AND (c_acctbal > '0'::double precision)) -> Bitmap Index Scan on customer_c_phone_idx_c_acctbal (cost=0.00..4.93 rows=477227 width=0) Index Cond: (substr((c_phone)::text, 1, 2) = ANY ('{12,17,21,20,15,26,10}'::text[])) -> 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=6497544.04..7425611.55 rows=1 width=20) -> GroupAggregate (cost=6497544.04..7425611.55 rows=1 width=20) Group Key: (substr((customer.c_phone)::text, 1, 2)) -> Sort (cost=7425611.56..7425611.56 rows=1 width=20) Sort Key: (substr((customer.c_phone)::text, 1, 2)) -> Hash Anti Join (cost=6497544.04..7425611.55 rows=1 width=20) Hash Cond: (customer.c_custkey = orders.o_custkey) -> Remote Subquery Scan on all (datanode_5_1) (cost=3819.05..309159.04 rows=175000 width=24) Distribute results by H: c_custkey -> Bitmap Heap Scan on customer (cost=3719.05..303984.04 rows=175000 width=24) Recheck Cond: ((substr((c_phone)::text, 1, 2) = ANY ('{12,17,21,20,15,26,10}'::text[])) AND (c_acctbal > $0)) -> Bitmap Index Scan on customer_c_phone_idx (cost=0.00..3675.30 rows=175000 width=0) Index Cond: ((substr((c_phone)::text, 1, 2) = ANY ('{12,17,21,20,15,26,10}'::text[])) AND (c_acctbal > $0)) -> Hash (cost=5382987.00..5382987.00 rows=150000000 width=4) -> 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..5382987.00 rows=150000000 width=4) Distribute results by H: o_custkey -> Seq Scan on orders (cost=0.00..4032887.00 rows=150000000 width=4) (26 rows) COMMIT; COMMIT