/*---------------------------------------------------------------------------------------
*
* Test node group AGG
*
* Portions Copyright (c) 2016, Huawei
*
*
* IDENTIFICATION
* src/test/regress/sql/nodegroup_basic_test.sql
*---------------------------------------------------------------------------------------
*/
create schema nodegroup_agg_test;
set current_schema = nodegroup_agg_test;
set enable_nodegroup_explain=on;
ERROR: unrecognized configuration parameter "enable_nodegroup_explain"
set expected_computing_nodegroup='group1';
create node group ngroup1234 with (datanode1,datanode2,datanode3,datanode4);
create node group ngroup123456 with (datanode1,datanode2,datanode3,datanode4,datanode5,datanode6);
create node group ngroup5678 with (datanode5,datanode6,datanode7,datanode8);
create table t1ng1(c1 int, c2 int, c3 int, c4 int) distribute by hash(c1);
create table t1ng1234(c1 int, c2 int, c3 int, c4 int) distribute by hash(c1) to group ngroup1234;
insert into t1ng1 select v, v*2, v*3, v*4 from generate_series(1,30) as v;
-- populate base data
insert into t1ng1234 select * from t1ng1;
-- double size 3 times
insert into t1ng1234 select * from t1ng1234;
insert into t1ng1234 select * from t1ng1234;
insert into t1ng1234 select * from t1ng1234;
/* start test cases */
-- group by dist key, it can do locally, so no ReDis step to do
explain (costs off) select avg(c3), c1 from t1ng1234 group by 2;
QUERY PLAN
-------------------------------------------------------------------
Data Node Scan
Node/s: (ngroup1234) datanode1, datanode2, datanode3, datanode4
(2 rows)
select avg(c3), c1 from t1ng1234 group by 2 order by 2;
avg | c1
---------------------+----
3.0000000000000000 | 1
6.0000000000000000 | 2
9.0000000000000000 | 3
12.0000000000000000 | 4
15.0000000000000000 | 5
18.0000000000000000 | 6
21.0000000000000000 | 7
24.0000000000000000 | 8
27.0000000000000000 | 9
30.0000000000000000 | 10
33.0000000000000000 | 11
36.0000000000000000 | 12
39.0000000000000000 | 13
42.0000000000000000 | 14
45.0000000000000000 | 15
48.0000000000000000 | 16
51.0000000000000000 | 17
54.0000000000000000 | 18
57.0000000000000000 | 19
60.0000000000000000 | 20
63.0000000000000000 | 21
66.0000000000000000 | 22
69.0000000000000000 | 23
72.0000000000000000 | 24
75.0000000000000000 | 25
78.0000000000000000 | 26
81.0000000000000000 | 27
84.0000000000000000 | 28
87.0000000000000000 | 29
90.0000000000000000 | 30
(30 rows)
-- group by none dist key, it can not do locally, so add ReDis step on default_computing nodegroup to do aggregation to do
explain (costs off) select avg(c3), c2 from t1ng1234 group by 2;
QUERY PLAN
---------------------------------------------------------------------------------
Streaming (type: GATHER)
Node/s: All datanodes
-> HashAggregate
Group By Key: c2
-> Streaming(type: REDISTRIBUTE ng: ngroup1234->group1)
Spawn on: (ngroup1234) datanode1, datanode2, datanode3, datanode4
-> Seq Scan on t1ng1234
(7 rows)
select avg(c3), c2 from t1ng1234 group by 2 order by 2;
avg | c2
---------------------+----
3.0000000000000000 | 2
6.0000000000000000 | 4
9.0000000000000000 | 6
12.0000000000000000 | 8
15.0000000000000000 | 10
18.0000000000000000 | 12
21.0000000000000000 | 14
24.0000000000000000 | 16
27.0000000000000000 | 18
30.0000000000000000 | 20
33.0000000000000000 | 22
36.0000000000000000 | 24
39.0000000000000000 | 26
42.0000000000000000 | 28
45.0000000000000000 | 30
48.0000000000000000 | 32
51.0000000000000000 | 34
54.0000000000000000 | 36
57.0000000000000000 | 38
60.0000000000000000 | 40
63.0000000000000000 | 42
66.0000000000000000 | 44
69.0000000000000000 | 46
72.0000000000000000 | 48
75.0000000000000000 | 50
78.0000000000000000 | 52
81.0000000000000000 | 54
84.0000000000000000 | 56
87.0000000000000000 | 58
90.0000000000000000 | 60
(30 rows)
-- same with above but change default computing nodegroup to ngroup123456
set expected_computing_nodegroup='ngroup123456';
explain (costs off) select avg(c3), c2 from t1ng1234 group by 2;
QUERY PLAN
---------------------------------------------------------------------------------------
Streaming (type: GATHER)
Node/s: (GenGroup) datanode1, datanode2, datanode3, datanode4, datanode5, datanode6
-> HashAggregate
Group By Key: c2
-> Streaming(type: REDISTRIBUTE ng: ngroup1234->ngroup123456)
Spawn on: (ngroup1234) datanode1, datanode2, datanode3, datanode4
-> Seq Scan on t1ng1234
(7 rows)
select avg(c3), c2 from t1ng1234 group by 2 order by 2;
avg | c2
---------------------+----
3.0000000000000000 | 2
6.0000000000000000 | 4
9.0000000000000000 | 6
12.0000000000000000 | 8
15.0000000000000000 | 10
18.0000000000000000 | 12
21.0000000000000000 | 14
24.0000000000000000 | 16
27.0000000000000000 | 18
30.0000000000000000 | 20
33.0000000000000000 | 22
36.0000000000000000 | 24
39.0000000000000000 | 26
42.0000000000000000 | 28
45.0000000000000000 | 30
48.0000000000000000 | 32
51.0000000000000000 | 34
54.0000000000000000 | 36
57.0000000000000000 | 38
60.0000000000000000 | 40
63.0000000000000000 | 42
66.0000000000000000 | 44
69.0000000000000000 | 46
72.0000000000000000 | 48
75.0000000000000000 | 50
78.0000000000000000 | 52
81.0000000000000000 | 54
84.0000000000000000 | 56
87.0000000000000000 | 58
90.0000000000000000 | 60
(30 rows)
-- same with above but change default computing nodegroup to ngoup5678
set expected_computing_nodegroup='ngroup5678';
explain (costs off) select avg(c3), c2 from t1ng1234 group by 2;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------
Streaming (type: GATHER)
Node/s: (GenGroup) datanode5, datanode6, datanode7, datanode8, datanode1, datanode2, datanode3, datanode4
-> HashAggregate
Group By Key: c2
-> Streaming(type: REDISTRIBUTE ng: ngroup1234->ngroup5678)
Spawn on: (ngroup1234) datanode1, datanode2, datanode3, datanode4
-> Seq Scan on t1ng1234
(7 rows)
select avg(c3), c2 from t1ng1234 group by 2 order by 2;
avg | c2
---------------------+----
3.0000000000000000 | 2
6.0000000000000000 | 4
9.0000000000000000 | 6
12.0000000000000000 | 8
15.0000000000000000 | 10
18.0000000000000000 | 12
21.0000000000000000 | 14
24.0000000000000000 | 16
27.0000000000000000 | 18
30.0000000000000000 | 20
33.0000000000000000 | 22
36.0000000000000000 | 24
39.0000000000000000 | 26
42.0000000000000000 | 28
45.0000000000000000 | 30
48.0000000000000000 | 32
51.0000000000000000 | 34
54.0000000000000000 | 36
57.0000000000000000 | 38
60.0000000000000000 | 40
63.0000000000000000 | 42
66.0000000000000000 | 44
69.0000000000000000 | 46
72.0000000000000000 | 48
75.0000000000000000 | 50
78.0000000000000000 | 52
81.0000000000000000 | 54
84.0000000000000000 | 56
87.0000000000000000 | 58
90.0000000000000000 | 60
(30 rows)
-- test join with agg
-- join in ngroup1
set expected_computing_nodegroup = 'group1';
explain (costs off) select avg(t1.c2), avg(t2.c2), t2.c2 from t1ng1 as t1 join t1ng1234 as t2 on t1.c1 = t2.c1 group by 3;
QUERY PLAN
------------------------------------------------------------------------------------
Streaming (type: GATHER)
Node/s: All datanodes
-> HashAggregate
Group By Key: t2.c2
-> Streaming(type: REDISTRIBUTE ng: ngroup1234->group1)
Spawn on: (ngroup1234) datanode1, datanode2, datanode3, datanode4
-> Hash Join
Hash Cond: (t2.c1 = t1.c1)
-> Seq Scan on t1ng1234 t2
-> Hash
-> Streaming(type: REDISTRIBUTE ng: group1->ngroup1234)
Spawn on: All datanodes
-> Seq Scan on t1ng1 t1
(13 rows)
select avg(t1.c2), avg(t2.c2), t2.c2 from t1ng1 as t1 join t1ng1234 as t2 on t1.c1 = t2.c1 group by 3 order by 1,2;
avg | avg | c2
---------------------+---------------------+----
2.0000000000000000 | 2.0000000000000000 | 2
4.0000000000000000 | 4.0000000000000000 | 4
6.0000000000000000 | 6.0000000000000000 | 6
8.0000000000000000 | 8.0000000000000000 | 8
10.0000000000000000 | 10.0000000000000000 | 10
12.0000000000000000 | 12.0000000000000000 | 12
14.0000000000000000 | 14.0000000000000000 | 14
16.0000000000000000 | 16.0000000000000000 | 16
18.0000000000000000 | 18.0000000000000000 | 18
20.0000000000000000 | 20.0000000000000000 | 20
22.0000000000000000 | 22.0000000000000000 | 22
24.0000000000000000 | 24.0000000000000000 | 24
26.0000000000000000 | 26.0000000000000000 | 26
28.0000000000000000 | 28.0000000000000000 | 28
30.0000000000000000 | 30.0000000000000000 | 30
32.0000000000000000 | 32.0000000000000000 | 32
34.0000000000000000 | 34.0000000000000000 | 34
36.0000000000000000 | 36.0000000000000000 | 36
38.0000000000000000 | 38.0000000000000000 | 38
40.0000000000000000 | 40.0000000000000000 | 40
42.0000000000000000 | 42.0000000000000000 | 42
44.0000000000000000 | 44.0000000000000000 | 44
46.0000000000000000 | 46.0000000000000000 | 46
48.0000000000000000 | 48.0000000000000000 | 48
50.0000000000000000 | 50.0000000000000000 | 50
52.0000000000000000 | 52.0000000000000000 | 52
54.0000000000000000 | 54.0000000000000000 | 54
56.0000000000000000 | 56.0000000000000000 | 56
58.0000000000000000 | 58.0000000000000000 | 58
60.0000000000000000 | 60.0000000000000000 | 60
(30 rows)
explain (costs off) select avg(t1.c2), avg(t2.c2), t2.c2 from t1ng1 as t1 left join t1ng1234 as t2 on t1.c1 = t2.c1 group by 3;
QUERY PLAN
------------------------------------------------------------------------------------
Streaming (type: GATHER)
Node/s: All datanodes
-> HashAggregate
Group By Key: t2.c2
-> Streaming(type: REDISTRIBUTE ng: ngroup1234->group1)
Spawn on: (ngroup1234) datanode1, datanode2, datanode3, datanode4
-> Hash Right Join
Hash Cond: (t2.c1 = t1.c1)
-> Seq Scan on t1ng1234 t2
-> Hash
-> Streaming(type: REDISTRIBUTE ng: group1->ngroup1234)
Spawn on: All datanodes
-> Seq Scan on t1ng1 t1
(13 rows)
select avg(t1.c2), avg(t2.c2), t2.c2 from t1ng1 as t1 left join t1ng1234 as t2 on t1.c1 = t2.c1 group by 3 order by 1,2;
avg | avg | c2
---------------------+---------------------+----
2.0000000000000000 | 2.0000000000000000 | 2
4.0000000000000000 | 4.0000000000000000 | 4
6.0000000000000000 | 6.0000000000000000 | 6
8.0000000000000000 | 8.0000000000000000 | 8
10.0000000000000000 | 10.0000000000000000 | 10
12.0000000000000000 | 12.0000000000000000 | 12
14.0000000000000000 | 14.0000000000000000 | 14
16.0000000000000000 | 16.0000000000000000 | 16
18.0000000000000000 | 18.0000000000000000 | 18
20.0000000000000000 | 20.0000000000000000 | 20
22.0000000000000000 | 22.0000000000000000 | 22
24.0000000000000000 | 24.0000000000000000 | 24
26.0000000000000000 | 26.0000000000000000 | 26
28.0000000000000000 | 28.0000000000000000 | 28
30.0000000000000000 | 30.0000000000000000 | 30
32.0000000000000000 | 32.0000000000000000 | 32
34.0000000000000000 | 34.0000000000000000 | 34
36.0000000000000000 | 36.0000000000000000 | 36
38.0000000000000000 | 38.0000000000000000 | 38
40.0000000000000000 | 40.0000000000000000 | 40
42.0000000000000000 | 42.0000000000000000 | 42
44.0000000000000000 | 44.0000000000000000 | 44
46.0000000000000000 | 46.0000000000000000 | 46
48.0000000000000000 | 48.0000000000000000 | 48
50.0000000000000000 | 50.0000000000000000 | 50
52.0000000000000000 | 52.0000000000000000 | 52
54.0000000000000000 | 54.0000000000000000 | 54
56.0000000000000000 | 56.0000000000000000 | 56
58.0000000000000000 | 58.0000000000000000 | 58
60.0000000000000000 | 60.0000000000000000 | 60
(30 rows)
explain (costs off) select avg(t1.c2), avg(t2.c2), t2.c2 from t1ng1 as t1 right join t1ng1234 as t2 on t1.c1 = t2.c1 group by 3;
QUERY PLAN
------------------------------------------------------------------------------------
Streaming (type: GATHER)
Node/s: All datanodes
-> HashAggregate
Group By Key: t2.c2
-> Streaming(type: REDISTRIBUTE ng: ngroup1234->group1)
Spawn on: (ngroup1234) datanode1, datanode2, datanode3, datanode4
-> Hash Left Join
Hash Cond: (t2.c1 = t1.c1)
-> Seq Scan on t1ng1234 t2
-> Hash
-> Streaming(type: REDISTRIBUTE ng: group1->ngroup1234)
Spawn on: All datanodes
-> Seq Scan on t1ng1 t1
(13 rows)
select avg(t1.c2), avg(t2.c2), t2.c2 from t1ng1 as t1 right join t1ng1234 as t2 on t1.c1 = t2.c1 group by 3 order by 1,2;
avg | avg | c2
---------------------+---------------------+----
2.0000000000000000 | 2.0000000000000000 | 2
4.0000000000000000 | 4.0000000000000000 | 4
6.0000000000000000 | 6.0000000000000000 | 6
8.0000000000000000 | 8.0000000000000000 | 8
10.0000000000000000 | 10.0000000000000000 | 10
12.0000000000000000 | 12.0000000000000000 | 12
14.0000000000000000 | 14.0000000000000000 | 14
16.0000000000000000 | 16.0000000000000000 | 16
18.0000000000000000 | 18.0000000000000000 | 18
20.0000000000000000 | 20.0000000000000000 | 20
22.0000000000000000 | 22.0000000000000000 | 22
24.0000000000000000 | 24.0000000000000000 | 24
26.0000000000000000 | 26.0000000000000000 | 26
28.0000000000000000 | 28.0000000000000000 | 28
30.0000000000000000 | 30.0000000000000000 | 30
32.0000000000000000 | 32.0000000000000000 | 32
34.0000000000000000 | 34.0000000000000000 | 34
36.0000000000000000 | 36.0000000000000000 | 36
38.0000000000000000 | 38.0000000000000000 | 38
40.0000000000000000 | 40.0000000000000000 | 40
42.0000000000000000 | 42.0000000000000000 | 42
44.0000000000000000 | 44.0000000000000000 | 44
46.0000000000000000 | 46.0000000000000000 | 46
48.0000000000000000 | 48.0000000000000000 | 48
50.0000000000000000 | 50.0000000000000000 | 50
52.0000000000000000 | 52.0000000000000000 | 52
54.0000000000000000 | 54.0000000000000000 | 54
56.0000000000000000 | 56.0000000000000000 | 56
58.0000000000000000 | 58.0000000000000000 | 58
60.0000000000000000 | 60.0000000000000000 | 60
(30 rows)
-- join in t1ng1234's local nodegroup
set expected_computing_nodegroup = 'ngroup1234';
explain (costs off) select avg(t1.c2), avg(t2.c2), t2.c2 from t1ng1 as t1 join t1ng1234 as t2 on t1.c1 = t2.c1 group by 3;
QUERY PLAN
------------------------------------------------------------------------------------
Streaming (type: GATHER)
Node/s: All datanodes
-> HashAggregate
Group By Key: t2.c2
-> Streaming(type: REDISTRIBUTE)
Spawn on: (ngroup1234) datanode1, datanode2, datanode3, datanode4
-> Hash Join
Hash Cond: (t2.c1 = t1.c1)
-> Seq Scan on t1ng1234 t2
-> Hash
-> Streaming(type: REDISTRIBUTE ng: group1->ngroup1234)
Spawn on: All datanodes
-> Seq Scan on t1ng1 t1
(13 rows)
select avg(t1.c2), avg(t2.c2), t2.c2 from t1ng1 as t1 join t1ng1234 as t2 on t1.c1 = t2.c1 group by 3 order by 1,2;
avg | avg | c2
---------------------+---------------------+----
2.0000000000000000 | 2.0000000000000000 | 2
4.0000000000000000 | 4.0000000000000000 | 4
6.0000000000000000 | 6.0000000000000000 | 6
8.0000000000000000 | 8.0000000000000000 | 8
10.0000000000000000 | 10.0000000000000000 | 10
12.0000000000000000 | 12.0000000000000000 | 12
14.0000000000000000 | 14.0000000000000000 | 14
16.0000000000000000 | 16.0000000000000000 | 16
18.0000000000000000 | 18.0000000000000000 | 18
20.0000000000000000 | 20.0000000000000000 | 20
22.0000000000000000 | 22.0000000000000000 | 22
24.0000000000000000 | 24.0000000000000000 | 24
26.0000000000000000 | 26.0000000000000000 | 26
28.0000000000000000 | 28.0000000000000000 | 28
30.0000000000000000 | 30.0000000000000000 | 30
32.0000000000000000 | 32.0000000000000000 | 32
34.0000000000000000 | 34.0000000000000000 | 34
36.0000000000000000 | 36.0000000000000000 | 36
38.0000000000000000 | 38.0000000000000000 | 38
40.0000000000000000 | 40.0000000000000000 | 40
42.0000000000000000 | 42.0000000000000000 | 42
44.0000000000000000 | 44.0000000000000000 | 44
46.0000000000000000 | 46.0000000000000000 | 46
48.0000000000000000 | 48.0000000000000000 | 48
50.0000000000000000 | 50.0000000000000000 | 50
52.0000000000000000 | 52.0000000000000000 | 52
54.0000000000000000 | 54.0000000000000000 | 54
56.0000000000000000 | 56.0000000000000000 | 56
58.0000000000000000 | 58.0000000000000000 | 58
60.0000000000000000 | 60.0000000000000000 | 60
(30 rows)
explain (costs off) select avg(t1.c2), avg(t2.c2), t2.c2 from t1ng1 as t1 left join t1ng1234 as t2 on t1.c1 = t2.c1 group by 3;
QUERY PLAN
------------------------------------------------------------------------------------
Streaming (type: GATHER)
Node/s: All datanodes
-> HashAggregate
Group By Key: t2.c2
-> Streaming(type: REDISTRIBUTE)
Spawn on: (ngroup1234) datanode1, datanode2, datanode3, datanode4
-> Hash Right Join
Hash Cond: (t2.c1 = t1.c1)
-> Seq Scan on t1ng1234 t2
-> Hash
-> Streaming(type: REDISTRIBUTE ng: group1->ngroup1234)
Spawn on: All datanodes
-> Seq Scan on t1ng1 t1
(13 rows)
select avg(t1.c2), avg(t2.c2), t2.c2 from t1ng1 as t1 left join t1ng1234 as t2 on t1.c1 = t2.c1 group by 3 order by 1,2;
avg | avg | c2
---------------------+---------------------+----
2.0000000000000000 | 2.0000000000000000 | 2
4.0000000000000000 | 4.0000000000000000 | 4
6.0000000000000000 | 6.0000000000000000 | 6
8.0000000000000000 | 8.0000000000000000 | 8
10.0000000000000000 | 10.0000000000000000 | 10
12.0000000000000000 | 12.0000000000000000 | 12
14.0000000000000000 | 14.0000000000000000 | 14
16.0000000000000000 | 16.0000000000000000 | 16
18.0000000000000000 | 18.0000000000000000 | 18
20.0000000000000000 | 20.0000000000000000 | 20
22.0000000000000000 | 22.0000000000000000 | 22
24.0000000000000000 | 24.0000000000000000 | 24
26.0000000000000000 | 26.0000000000000000 | 26
28.0000000000000000 | 28.0000000000000000 | 28
30.0000000000000000 | 30.0000000000000000 | 30
32.0000000000000000 | 32.0000000000000000 | 32
34.0000000000000000 | 34.0000000000000000 | 34
36.0000000000000000 | 36.0000000000000000 | 36
38.0000000000000000 | 38.0000000000000000 | 38
40.0000000000000000 | 40.0000000000000000 | 40
42.0000000000000000 | 42.0000000000000000 | 42
44.0000000000000000 | 44.0000000000000000 | 44
46.0000000000000000 | 46.0000000000000000 | 46
48.0000000000000000 | 48.0000000000000000 | 48
50.0000000000000000 | 50.0000000000000000 | 50
52.0000000000000000 | 52.0000000000000000 | 52
54.0000000000000000 | 54.0000000000000000 | 54
56.0000000000000000 | 56.0000000000000000 | 56
58.0000000000000000 | 58.0000000000000000 | 58
60.0000000000000000 | 60.0000000000000000 | 60
(30 rows)
explain (costs off) select avg(t1.c2), avg(t2.c2), t2.c2 from t1ng1 as t1 right join t1ng1234 as t2 on t1.c1 = t2.c1 group by 3;
QUERY PLAN
------------------------------------------------------------------------------------
Streaming (type: GATHER)
Node/s: All datanodes
-> HashAggregate
Group By Key: t2.c2
-> Streaming(type: REDISTRIBUTE)
Spawn on: (ngroup1234) datanode1, datanode2, datanode3, datanode4
-> Hash Left Join
Hash Cond: (t2.c1 = t1.c1)
-> Seq Scan on t1ng1234 t2
-> Hash
-> Streaming(type: REDISTRIBUTE ng: group1->ngroup1234)
Spawn on: All datanodes
-> Seq Scan on t1ng1 t1
(13 rows)
select avg(t1.c2), avg(t2.c2), t2.c2 from t1ng1 as t1 right join t1ng1234 as t2 on t1.c1 = t2.c1 group by 3 order by 1,2;
avg | avg | c2
---------------------+---------------------+----
2.0000000000000000 | 2.0000000000000000 | 2
4.0000000000000000 | 4.0000000000000000 | 4
6.0000000000000000 | 6.0000000000000000 | 6
8.0000000000000000 | 8.0000000000000000 | 8
10.0000000000000000 | 10.0000000000000000 | 10
12.0000000000000000 | 12.0000000000000000 | 12
14.0000000000000000 | 14.0000000000000000 | 14
16.0000000000000000 | 16.0000000000000000 | 16
18.0000000000000000 | 18.0000000000000000 | 18
20.0000000000000000 | 20.0000000000000000 | 20
22.0000000000000000 | 22.0000000000000000 | 22
24.0000000000000000 | 24.0000000000000000 | 24
26.0000000000000000 | 26.0000000000000000 | 26
28.0000000000000000 | 28.0000000000000000 | 28
30.0000000000000000 | 30.0000000000000000 | 30
32.0000000000000000 | 32.0000000000000000 | 32
34.0000000000000000 | 34.0000000000000000 | 34
36.0000000000000000 | 36.0000000000000000 | 36
38.0000000000000000 | 38.0000000000000000 | 38
40.0000000000000000 | 40.0000000000000000 | 40
42.0000000000000000 | 42.0000000000000000 | 42
44.0000000000000000 | 44.0000000000000000 | 44
46.0000000000000000 | 46.0000000000000000 | 46
48.0000000000000000 | 48.0000000000000000 | 48
50.0000000000000000 | 50.0000000000000000 | 50
52.0000000000000000 | 52.0000000000000000 | 52
54.0000000000000000 | 54.0000000000000000 | 54
56.0000000000000000 | 56.0000000000000000 | 56
58.0000000000000000 | 58.0000000000000000 | 58
60.0000000000000000 | 60.0000000000000000 | 60
(30 rows)
-- join in ngroup123456
set expected_computing_nodegroup = 'ngroup123456';
explain (costs off) select avg(t1.c2), avg(t2.c2), t2.c2 from t1ng1 as t1 join t1ng1234 as t2 on t1.c1 = t2.c1 group by 3;
QUERY PLAN
------------------------------------------------------------------------------------
Streaming (type: GATHER)
Node/s: All datanodes
-> HashAggregate
Group By Key: t2.c2
-> Streaming(type: REDISTRIBUTE ng: ngroup1234->ngroup123456)
Spawn on: (ngroup1234) datanode1, datanode2, datanode3, datanode4
-> Hash Join
Hash Cond: (t2.c1 = t1.c1)
-> Seq Scan on t1ng1234 t2
-> Hash
-> Streaming(type: REDISTRIBUTE ng: group1->ngroup1234)
Spawn on: All datanodes
-> Seq Scan on t1ng1 t1
(13 rows)
select avg(t1.c2), avg(t2.c2), t2.c2 from t1ng1 as t1 join t1ng1234 as t2 on t1.c1 = t2.c1 group by 3 order by 1,2;
avg | avg | c2
---------------------+---------------------+----
2.0000000000000000 | 2.0000000000000000 | 2
4.0000000000000000 | 4.0000000000000000 | 4
6.0000000000000000 | 6.0000000000000000 | 6
8.0000000000000000 | 8.0000000000000000 | 8
10.0000000000000000 | 10.0000000000000000 | 10
12.0000000000000000 | 12.0000000000000000 | 12
14.0000000000000000 | 14.0000000000000000 | 14
16.0000000000000000 | 16.0000000000000000 | 16
18.0000000000000000 | 18.0000000000000000 | 18
20.0000000000000000 | 20.0000000000000000 | 20
22.0000000000000000 | 22.0000000000000000 | 22
24.0000000000000000 | 24.0000000000000000 | 24
26.0000000000000000 | 26.0000000000000000 | 26
28.0000000000000000 | 28.0000000000000000 | 28
30.0000000000000000 | 30.0000000000000000 | 30
32.0000000000000000 | 32.0000000000000000 | 32
34.0000000000000000 | 34.0000000000000000 | 34
36.0000000000000000 | 36.0000000000000000 | 36
38.0000000000000000 | 38.0000000000000000 | 38
40.0000000000000000 | 40.0000000000000000 | 40
42.0000000000000000 | 42.0000000000000000 | 42
44.0000000000000000 | 44.0000000000000000 | 44
46.0000000000000000 | 46.0000000000000000 | 46
48.0000000000000000 | 48.0000000000000000 | 48
50.0000000000000000 | 50.0000000000000000 | 50
52.0000000000000000 | 52.0000000000000000 | 52
54.0000000000000000 | 54.0000000000000000 | 54
56.0000000000000000 | 56.0000000000000000 | 56
58.0000000000000000 | 58.0000000000000000 | 58
60.0000000000000000 | 60.0000000000000000 | 60
(30 rows)
explain (costs off) select avg(t1.c2), avg(t2.c2), t2.c2 from t1ng1 as t1 left join t1ng1234 as t2 on t1.c1 = t2.c1 group by 3;
QUERY PLAN
------------------------------------------------------------------------------------
Streaming (type: GATHER)
Node/s: All datanodes
-> HashAggregate
Group By Key: t2.c2
-> Streaming(type: REDISTRIBUTE ng: ngroup1234->ngroup123456)
Spawn on: (ngroup1234) datanode1, datanode2, datanode3, datanode4
-> Hash Right Join
Hash Cond: (t2.c1 = t1.c1)
-> Seq Scan on t1ng1234 t2
-> Hash
-> Streaming(type: REDISTRIBUTE ng: group1->ngroup1234)
Spawn on: All datanodes
-> Seq Scan on t1ng1 t1
(13 rows)
select avg(t1.c2), avg(t2.c2), t2.c2 from t1ng1 as t1 left join t1ng1234 as t2 on t1.c1 = t2.c1 group by 3 order by 1,2;
avg | avg | c2
---------------------+---------------------+----
2.0000000000000000 | 2.0000000000000000 | 2
4.0000000000000000 | 4.0000000000000000 | 4
6.0000000000000000 | 6.0000000000000000 | 6
8.0000000000000000 | 8.0000000000000000 | 8
10.0000000000000000 | 10.0000000000000000 | 10
12.0000000000000000 | 12.0000000000000000 | 12
14.0000000000000000 | 14.0000000000000000 | 14
16.0000000000000000 | 16.0000000000000000 | 16
18.0000000000000000 | 18.0000000000000000 | 18
20.0000000000000000 | 20.0000000000000000 | 20
22.0000000000000000 | 22.0000000000000000 | 22
24.0000000000000000 | 24.0000000000000000 | 24
26.0000000000000000 | 26.0000000000000000 | 26
28.0000000000000000 | 28.0000000000000000 | 28
30.0000000000000000 | 30.0000000000000000 | 30
32.0000000000000000 | 32.0000000000000000 | 32
34.0000000000000000 | 34.0000000000000000 | 34
36.0000000000000000 | 36.0000000000000000 | 36
38.0000000000000000 | 38.0000000000000000 | 38
40.0000000000000000 | 40.0000000000000000 | 40
42.0000000000000000 | 42.0000000000000000 | 42
44.0000000000000000 | 44.0000000000000000 | 44
46.0000000000000000 | 46.0000000000000000 | 46
48.0000000000000000 | 48.0000000000000000 | 48
50.0000000000000000 | 50.0000000000000000 | 50
52.0000000000000000 | 52.0000000000000000 | 52
54.0000000000000000 | 54.0000000000000000 | 54
56.0000000000000000 | 56.0000000000000000 | 56
58.0000000000000000 | 58.0000000000000000 | 58
60.0000000000000000 | 60.0000000000000000 | 60
(30 rows)
explain (costs off) select avg(t1.c2), avg(t2.c2), t2.c2 from t1ng1 as t1 right join t1ng1234 as t2 on t1.c1 = t2.c1 group by 3;
QUERY PLAN
------------------------------------------------------------------------------------
Streaming (type: GATHER)
Node/s: All datanodes
-> HashAggregate
Group By Key: t2.c2
-> Streaming(type: REDISTRIBUTE ng: ngroup1234->ngroup123456)
Spawn on: (ngroup1234) datanode1, datanode2, datanode3, datanode4
-> Hash Left Join
Hash Cond: (t2.c1 = t1.c1)
-> Seq Scan on t1ng1234 t2
-> Hash
-> Streaming(type: REDISTRIBUTE ng: group1->ngroup1234)
Spawn on: All datanodes
-> Seq Scan on t1ng1 t1
(13 rows)
select avg(t1.c2), avg(t2.c2), t2.c2 from t1ng1 as t1 right join t1ng1234 as t2 on t1.c1 = t2.c1 group by 3 order by 1,2;
avg | avg | c2
---------------------+---------------------+----
2.0000000000000000 | 2.0000000000000000 | 2
4.0000000000000000 | 4.0000000000000000 | 4
6.0000000000000000 | 6.0000000000000000 | 6
8.0000000000000000 | 8.0000000000000000 | 8
10.0000000000000000 | 10.0000000000000000 | 10
12.0000000000000000 | 12.0000000000000000 | 12
14.0000000000000000 | 14.0000000000000000 | 14
16.0000000000000000 | 16.0000000000000000 | 16
18.0000000000000000 | 18.0000000000000000 | 18
20.0000000000000000 | 20.0000000000000000 | 20
22.0000000000000000 | 22.0000000000000000 | 22
24.0000000000000000 | 24.0000000000000000 | 24
26.0000000000000000 | 26.0000000000000000 | 26
28.0000000000000000 | 28.0000000000000000 | 28
30.0000000000000000 | 30.0000000000000000 | 30
32.0000000000000000 | 32.0000000000000000 | 32
34.0000000000000000 | 34.0000000000000000 | 34
36.0000000000000000 | 36.0000000000000000 | 36
38.0000000000000000 | 38.0000000000000000 | 38
40.0000000000000000 | 40.0000000000000000 | 40
42.0000000000000000 | 42.0000000000000000 | 42
44.0000000000000000 | 44.0000000000000000 | 44
46.0000000000000000 | 46.0000000000000000 | 46
48.0000000000000000 | 48.0000000000000000 | 48
50.0000000000000000 | 50.0000000000000000 | 50
52.0000000000000000 | 52.0000000000000000 | 52
54.0000000000000000 | 54.0000000000000000 | 54
56.0000000000000000 | 56.0000000000000000 | 56
58.0000000000000000 | 58.0000000000000000 | 58
60.0000000000000000 | 60.0000000000000000 | 60
(30 rows)
-- join in ngroup5678
set expected_computing_nodegroup = 'ngroup5678';
explain (costs off) select avg(t1.c2), avg(t2.c2), t2.c2 from t1ng1 as t1 join t1ng1234 as t2 on t1.c1 = t2.c1 group by 3;
QUERY PLAN
------------------------------------------------------------------------------------
Streaming (type: GATHER)
Node/s: All datanodes
-> HashAggregate
Group By Key: t2.c2
-> Streaming(type: REDISTRIBUTE ng: ngroup1234->ngroup5678)
Spawn on: (ngroup1234) datanode1, datanode2, datanode3, datanode4
-> Hash Join
Hash Cond: (t2.c1 = t1.c1)
-> Seq Scan on t1ng1234 t2
-> Hash
-> Streaming(type: REDISTRIBUTE ng: group1->ngroup1234)
Spawn on: All datanodes
-> Seq Scan on t1ng1 t1
(13 rows)
select avg(t1.c2), avg(t2.c2), t2.c2 from t1ng1 as t1 join t1ng1234 as t2 on t1.c1 = t2.c1 group by 3 order by 1,2;
avg | avg | c2
---------------------+---------------------+----
2.0000000000000000 | 2.0000000000000000 | 2
4.0000000000000000 | 4.0000000000000000 | 4
6.0000000000000000 | 6.0000000000000000 | 6
8.0000000000000000 | 8.0000000000000000 | 8
10.0000000000000000 | 10.0000000000000000 | 10
12.0000000000000000 | 12.0000000000000000 | 12
14.0000000000000000 | 14.0000000000000000 | 14
16.0000000000000000 | 16.0000000000000000 | 16
18.0000000000000000 | 18.0000000000000000 | 18
20.0000000000000000 | 20.0000000000000000 | 20
22.0000000000000000 | 22.0000000000000000 | 22
24.0000000000000000 | 24.0000000000000000 | 24
26.0000000000000000 | 26.0000000000000000 | 26
28.0000000000000000 | 28.0000000000000000 | 28
30.0000000000000000 | 30.0000000000000000 | 30
32.0000000000000000 | 32.0000000000000000 | 32
34.0000000000000000 | 34.0000000000000000 | 34
36.0000000000000000 | 36.0000000000000000 | 36
38.0000000000000000 | 38.0000000000000000 | 38
40.0000000000000000 | 40.0000000000000000 | 40
42.0000000000000000 | 42.0000000000000000 | 42
44.0000000000000000 | 44.0000000000000000 | 44
46.0000000000000000 | 46.0000000000000000 | 46
48.0000000000000000 | 48.0000000000000000 | 48
50.0000000000000000 | 50.0000000000000000 | 50
52.0000000000000000 | 52.0000000000000000 | 52
54.0000000000000000 | 54.0000000000000000 | 54
56.0000000000000000 | 56.0000000000000000 | 56
58.0000000000000000 | 58.0000000000000000 | 58
60.0000000000000000 | 60.0000000000000000 | 60
(30 rows)
explain (costs off) select avg(t1.c2), avg(t2.c2), t2.c2 from t1ng1 as t1 left join t1ng1234 as t2 on t1.c1 = t2.c1 group by 3;
QUERY PLAN
------------------------------------------------------------------------------------
Streaming (type: GATHER)
Node/s: All datanodes
-> HashAggregate
Group By Key: t2.c2
-> Streaming(type: REDISTRIBUTE ng: ngroup1234->ngroup5678)
Spawn on: (ngroup1234) datanode1, datanode2, datanode3, datanode4
-> Hash Right Join
Hash Cond: (t2.c1 = t1.c1)
-> Seq Scan on t1ng1234 t2
-> Hash
-> Streaming(type: REDISTRIBUTE ng: group1->ngroup1234)
Spawn on: All datanodes
-> Seq Scan on t1ng1 t1
(13 rows)
select avg(t1.c2), avg(t2.c2), t2.c2 from t1ng1 as t1 left join t1ng1234 as t2 on t1.c1 = t2.c1 group by 3 order by 1,2;
avg | avg | c2
---------------------+---------------------+----
2.0000000000000000 | 2.0000000000000000 | 2
4.0000000000000000 | 4.0000000000000000 | 4
6.0000000000000000 | 6.0000000000000000 | 6
8.0000000000000000 | 8.0000000000000000 | 8
10.0000000000000000 | 10.0000000000000000 | 10
12.0000000000000000 | 12.0000000000000000 | 12
14.0000000000000000 | 14.0000000000000000 | 14
16.0000000000000000 | 16.0000000000000000 | 16
18.0000000000000000 | 18.0000000000000000 | 18
20.0000000000000000 | 20.0000000000000000 | 20
22.0000000000000000 | 22.0000000000000000 | 22
24.0000000000000000 | 24.0000000000000000 | 24
26.0000000000000000 | 26.0000000000000000 | 26
28.0000000000000000 | 28.0000000000000000 | 28
30.0000000000000000 | 30.0000000000000000 | 30
32.0000000000000000 | 32.0000000000000000 | 32
34.0000000000000000 | 34.0000000000000000 | 34
36.0000000000000000 | 36.0000000000000000 | 36
38.0000000000000000 | 38.0000000000000000 | 38
40.0000000000000000 | 40.0000000000000000 | 40
42.0000000000000000 | 42.0000000000000000 | 42
44.0000000000000000 | 44.0000000000000000 | 44
46.0000000000000000 | 46.0000000000000000 | 46
48.0000000000000000 | 48.0000000000000000 | 48
50.0000000000000000 | 50.0000000000000000 | 50
52.0000000000000000 | 52.0000000000000000 | 52
54.0000000000000000 | 54.0000000000000000 | 54
56.0000000000000000 | 56.0000000000000000 | 56
58.0000000000000000 | 58.0000000000000000 | 58
60.0000000000000000 | 60.0000000000000000 | 60
(30 rows)
explain (costs off) select avg(t1.c2), avg(t2.c2), t2.c2 from t1ng1 as t1 right join t1ng1234 as t2 on t1.c1 = t2.c1 group by 3;
QUERY PLAN
------------------------------------------------------------------------------------
Streaming (type: GATHER)
Node/s: All datanodes
-> HashAggregate
Group By Key: t2.c2
-> Streaming(type: REDISTRIBUTE ng: ngroup1234->ngroup5678)
Spawn on: (ngroup1234) datanode1, datanode2, datanode3, datanode4
-> Hash Left Join
Hash Cond: (t2.c1 = t1.c1)
-> Seq Scan on t1ng1234 t2
-> Hash
-> Streaming(type: REDISTRIBUTE ng: group1->ngroup1234)
Spawn on: All datanodes
-> Seq Scan on t1ng1 t1
(13 rows)
select avg(t1.c2), avg(t2.c2), t2.c2 from t1ng1 as t1 right join t1ng1234 as t2 on t1.c1 = t2.c1 group by 3 order by 1,2;
avg | avg | c2
---------------------+---------------------+----
2.0000000000000000 | 2.0000000000000000 | 2
4.0000000000000000 | 4.0000000000000000 | 4
6.0000000000000000 | 6.0000000000000000 | 6
8.0000000000000000 | 8.0000000000000000 | 8
10.0000000000000000 | 10.0000000000000000 | 10
12.0000000000000000 | 12.0000000000000000 | 12
14.0000000000000000 | 14.0000000000000000 | 14
16.0000000000000000 | 16.0000000000000000 | 16
18.0000000000000000 | 18.0000000000000000 | 18
20.0000000000000000 | 20.0000000000000000 | 20
22.0000000000000000 | 22.0000000000000000 | 22
24.0000000000000000 | 24.0000000000000000 | 24
26.0000000000000000 | 26.0000000000000000 | 26
28.0000000000000000 | 28.0000000000000000 | 28
30.0000000000000000 | 30.0000000000000000 | 30
32.0000000000000000 | 32.0000000000000000 | 32
34.0000000000000000 | 34.0000000000000000 | 34
36.0000000000000000 | 36.0000000000000000 | 36
38.0000000000000000 | 38.0000000000000000 | 38
40.0000000000000000 | 40.0000000000000000 | 40
42.0000000000000000 | 42.0000000000000000 | 42
44.0000000000000000 | 44.0000000000000000 | 44
46.0000000000000000 | 46.0000000000000000 | 46
48.0000000000000000 | 48.0000000000000000 | 48
50.0000000000000000 | 50.0000000000000000 | 50
52.0000000000000000 | 52.0000000000000000 | 52
54.0000000000000000 | 54.0000000000000000 | 54
56.0000000000000000 | 56.0000000000000000 | 56
58.0000000000000000 | 58.0000000000000000 | 58
60.0000000000000000 | 60.0000000000000000 | 60
(30 rows)
drop table t1ng1;
drop table t1ng1234;
reset expected_computing_nodegroup;
drop node group ngroup1234;
drop node group ngroup123456;
drop node group ngroup5678;
/* Verify AGG on desired nodegroup */
create node group ng1 with(datanode2, datanode3);
create node group ng2 with(datanode1, datanode4);
create node group ng3 with(datanode1, datanode2, datanode3, datanode4, datanode5, datanode6, datanode7, datanode8);
create table t1ng1(c1 int, c2 int, c3 int, c4 int, c5 int) distribute by hash(c1) to group ng1;
insert into t1ng1 select v,v%5,v%10,v%20,v%25 from generate_series(1,500) as v;
select count(*) from t1ng1;
count
-------
500
(1 row)
set expected_computing_nodegroup = 'group1';
-- processing on group1 but t1ng1 is distributed on ng1, so redistribute any way
explain (costs off) select sum(c1), avg(c1), count(c1), c2,c3 from t1ng1 group by 4,5 order by 1,2,3;
QUERY PLAN
-----------------------------------------------------------------
Streaming (type: GATHER)
Merge Sort Key: (sum(c1)), (avg(c1)), (count(c1))
Node/s: All datanodes
-> Sort
Sort Key: (sum(c1)), (avg(c1)), (count(c1))
-> HashAggregate
Group By Key: c2, c3
-> Streaming(type: REDISTRIBUTE ng: ng1->group1)
Spawn on: (ng1) datanode2, datanode3
-> Seq Scan on t1ng1
(10 rows)
select sum(c1), avg(c1), count(c1), c2,c3 from t1ng1 group by 4,5 order by 1,2,3 limit 5;
sum | avg | count | c2 | c3
-------+----------------------+-------+----+----
12300 | 246.0000000000000000 | 50 | 1 | 1
12350 | 247.0000000000000000 | 50 | 2 | 2
12400 | 248.0000000000000000 | 50 | 3 | 3
12450 | 249.0000000000000000 | 50 | 4 | 4
12500 | 250.0000000000000000 | 50 | 0 | 5
(5 rows)
-- processing on group1 but t1ng1 is distributed on ng1, so redistribute any way
explain (costs off) select sum(c1), avg(c1), count(c1), c2 from t1ng1 group by 4 order by 1,2,3;
QUERY PLAN
-----------------------------------------------------------------
Streaming (type: GATHER)
Merge Sort Key: (sum(c1)), (avg(c1)), (count(c1))
Node/s: All datanodes
-> Sort
Sort Key: (sum(c1)), (avg(c1)), (count(c1))
-> HashAggregate
Group By Key: c2
-> Streaming(type: REDISTRIBUTE ng: ng1->group1)
Spawn on: (ng1) datanode2, datanode3
-> Seq Scan on t1ng1
(10 rows)
select sum(c1), avg(c1), count(c1), c2 from t1ng1 group by 4 order by 1,2,3 limit 5;
sum | avg | count | c2
-------+----------------------+-------+----
24850 | 248.5000000000000000 | 100 | 1
24950 | 249.5000000000000000 | 100 | 2
25050 | 250.5000000000000000 | 100 | 3
25150 | 251.5000000000000000 | 100 | 4
25250 | 252.5000000000000000 | 100 | 0
(5 rows)
-- processing on group1 but t1ng1 is distributed on ng1, so redistribute any way
explain (costs off) select sum(c1), avg(c1), count(c1), c1 from t1ng1 group by 4 order by 1,2,3;
QUERY PLAN
-----------------------------------------------------
Streaming (type: GATHER)
Merge Sort Key: (sum(c1)), (avg(c1)), (count(c1))
Node/s: (GenGroup) datanode2, datanode3
-> Sort
Sort Key: (sum(c1)), (avg(c1)), (count(c1))
-> HashAggregate
Group By Key: c1
-> Seq Scan on t1ng1
(8 rows)
select sum(c1), avg(c1), count(c1), c1 from t1ng1 group by 4 order by 1,2,3 limit 5;
sum | avg | count | c1
-----+------------------------+-------+----
1 | 1.00000000000000000000 | 1 | 1
2 | 2.0000000000000000 | 1 | 2
3 | 3.0000000000000000 | 1 | 3
4 | 4.0000000000000000 | 1 | 4
5 | 5.0000000000000000 | 1 | 5
(5 rows)
set expected_computing_nodegroup = 'ng1';
-- processing on ng1 and t1ng1 is distributed on ng1, but grouping key is c2,c3 so have to redistribution
explain (costs off) select sum(c1), avg(c1), count(c1), c2,c3 from t1ng1 group by 4,5 order by 1,2,3;
QUERY PLAN
--------------------------------------------------------------------------------------------
Sort
Sort Key: (pg_catalog.sum((sum(c1)))), (pg_catalog.avg((avg(c1)))), (count((count(c1))))
-> HashAggregate
Group By Key: c2, c3
-> Streaming (type: GATHER)
Node/s: (GenGroup) datanode2, datanode3
-> HashAggregate
Group By Key: c2, c3
-> Seq Scan on t1ng1
(9 rows)
select sum(c1), avg(c1), count(c1), c2,c3 from t1ng1 group by 4,5 order by 1,2,3 limit 5;
sum | avg | count | c2 | c3
-------+----------------------+-------+----+----
12300 | 246.0000000000000000 | 50 | 1 | 1
12350 | 247.0000000000000000 | 50 | 2 | 2
12400 | 248.0000000000000000 | 50 | 3 | 3
12450 | 249.0000000000000000 | 50 | 4 | 4
12500 | 250.0000000000000000 | 50 | 0 | 5
(5 rows)
-- processing on ng1 and t1ng1 is distributed on ng1, but grouping key is c2 so have to redistribution
explain (costs off) select sum(c1), avg(c1), count(c1), c2 from t1ng1 group by 4 order by 1,2,3;
QUERY PLAN
----------------------------------------------------------
Streaming (type: GATHER)
Merge Sort Key: (sum(c1)), (avg(c1)), (count(c1))
Node/s: (GenGroup) datanode2, datanode3
-> Sort
Sort Key: (sum(c1)), (avg(c1)), (count(c1))
-> HashAggregate
Group By Key: c2
-> Streaming(type: REDISTRIBUTE)
Spawn on: (ng1) datanode2, datanode3
-> Seq Scan on t1ng1
(10 rows)
select sum(c1), avg(c1), count(c1), c2 from t1ng1 group by 4 order by 1,2,3 limit 5;
sum | avg | count | c2
-------+----------------------+-------+----
24850 | 248.5000000000000000 | 100 | 1
24950 | 249.5000000000000000 | 100 | 2
25050 | 250.5000000000000000 | 100 | 3
25150 | 251.5000000000000000 | 100 | 4
25250 | 252.5000000000000000 | 100 | 0
(5 rows)
-- processing on ng1 and t1ng1 is distributed on ng1, and grouping key c1 so we can avoid redistribution :-)
explain (costs off) select sum(c1), avg(c1), count(c1), c1 from t1ng1 group by 4 order by 1,2,3;
QUERY PLAN
-----------------------------------------------------
Streaming (type: GATHER)
Merge Sort Key: (sum(c1)), (avg(c1)), (count(c1))
Node/s: (GenGroup) datanode2, datanode3
-> Sort
Sort Key: (sum(c1)), (avg(c1)), (count(c1))
-> HashAggregate
Group By Key: c1
-> Seq Scan on t1ng1
(8 rows)
select sum(c1), avg(c1), count(c1), c1 from t1ng1 group by 4 order by 1,2,3 limit 5;
sum | avg | count | c1
-----+------------------------+-------+----
1 | 1.00000000000000000000 | 1 | 1
2 | 2.0000000000000000 | 1 | 2
3 | 3.0000000000000000 | 1 | 3
4 | 4.0000000000000000 | 1 | 4
5 | 5.0000000000000000 | 1 | 5
(5 rows)
set expected_computing_nodegroup = 'ng2';
-- processing on ng2 but t1ng1 is distributed on ng1, so redistribute any way
explain (costs off) select sum(c1), avg(c1), count(c1), c2,c3 from t1ng1 group by 4,5 order by 1,2,3;
QUERY PLAN
--------------------------------------------------------------------------------------------
Sort
Sort Key: (pg_catalog.sum((sum(c1)))), (pg_catalog.avg((avg(c1)))), (count((count(c1))))
-> HashAggregate
Group By Key: c2, c3
-> Streaming (type: GATHER)
Node/s: (GenGroup) datanode2, datanode3
-> HashAggregate
Group By Key: c2, c3
-> Seq Scan on t1ng1
(9 rows)
select sum(c1), avg(c1), count(c1), c2,c3 from t1ng1 group by 4,5 order by 1,2,3 limit 5;
sum | avg | count | c2 | c3
-------+----------------------+-------+----+----
12300 | 246.0000000000000000 | 50 | 1 | 1
12350 | 247.0000000000000000 | 50 | 2 | 2
12400 | 248.0000000000000000 | 50 | 3 | 3
12450 | 249.0000000000000000 | 50 | 4 | 4
12500 | 250.0000000000000000 | 50 | 0 | 5
(5 rows)
-- processing on ng2 but t1ng1 is distributed on ng1, so redistribute any way
explain (costs off) select sum(c1), avg(c1), count(c1), c2 from t1ng1 group by 4 order by 1,2,3;
QUERY PLAN
-----------------------------------------------------------------
Streaming (type: GATHER)
Merge Sort Key: (sum(c1)), (avg(c1)), (count(c1))
Node/s: (GenGroup) datanode1, datanode4, datanode2, datanode3
-> Sort
Sort Key: (sum(c1)), (avg(c1)), (count(c1))
-> HashAggregate
Group By Key: c2
-> Streaming(type: REDISTRIBUTE ng: ng1->ng2)
Spawn on: (ng1) datanode2, datanode3
-> Seq Scan on t1ng1
(10 rows)
select sum(c1), avg(c1), count(c1), c2 from t1ng1 group by 4 order by 1,2,3 limit 5;
sum | avg | count | c2
-------+----------------------+-------+----
24850 | 248.5000000000000000 | 100 | 1
24950 | 249.5000000000000000 | 100 | 2
25050 | 250.5000000000000000 | 100 | 3
25150 | 251.5000000000000000 | 100 | 4
25250 | 252.5000000000000000 | 100 | 0
(5 rows)
-- processing on ng2 but t1ng1 is distributed on ng1, so redistribute any way
explain (costs off) select sum(c1), avg(c1), count(c1), c1 from t1ng1 group by 4 order by 1,2,3;
QUERY PLAN
-----------------------------------------------------
Streaming (type: GATHER)
Merge Sort Key: (sum(c1)), (avg(c1)), (count(c1))
Node/s: (GenGroup) datanode2, datanode3
-> Sort
Sort Key: (sum(c1)), (avg(c1)), (count(c1))
-> HashAggregate
Group By Key: c1
-> Seq Scan on t1ng1
(8 rows)
select sum(c1), avg(c1), count(c1), c1 from t1ng1 group by 4 order by 1,2,3 limit 5;
sum | avg | count | c1
-----+------------------------+-------+----
1 | 1.00000000000000000000 | 1 | 1
2 | 2.0000000000000000 | 1 | 2
3 | 3.0000000000000000 | 1 | 3
4 | 4.0000000000000000 | 1 | 4
5 | 5.0000000000000000 | 1 | 5
(5 rows)
set expected_computing_nodegroup = 'ng3';
-- processing on ng3 but t1ng1 is distributed on ng1, so redistribute any way
explain (costs off) select sum(c1), avg(c1), count(c1), c2,c3 from t1ng1 group by 4,5 order by 1,2,3;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------
Streaming (type: GATHER)
Merge Sort Key: (sum(c1)), (avg(c1)), (count(c1))
Node/s: (GenGroup) datanode1, datanode2, datanode3, datanode4, datanode5, datanode6, datanode7, datanode8
-> Sort
Sort Key: (sum(c1)), (avg(c1)), (count(c1))
-> HashAggregate
Group By Key: c2, c3
-> Streaming(type: REDISTRIBUTE ng: ng1->ng3)
Spawn on: (ng1) datanode2, datanode3
-> Seq Scan on t1ng1
(10 rows)
select sum(c1), avg(c1), count(c1), c2,c3 from t1ng1 group by 4,5 order by 1,2,3 limit 5;
sum | avg | count | c2 | c3
-------+----------------------+-------+----+----
12300 | 246.0000000000000000 | 50 | 1 | 1
12350 | 247.0000000000000000 | 50 | 2 | 2
12400 | 248.0000000000000000 | 50 | 3 | 3
12450 | 249.0000000000000000 | 50 | 4 | 4
12500 | 250.0000000000000000 | 50 | 0 | 5
(5 rows)
-- processing on ng3 but t1ng1 is distributed on ng1, so redistribute any way
explain (costs off) select sum(c1), avg(c1), count(c1), c2 from t1ng1 group by 4 order by 1,2,3;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------
Streaming (type: GATHER)
Merge Sort Key: (sum(c1)), (avg(c1)), (count(c1))
Node/s: (GenGroup) datanode1, datanode2, datanode3, datanode4, datanode5, datanode6, datanode7, datanode8
-> Sort
Sort Key: (sum(c1)), (avg(c1)), (count(c1))
-> HashAggregate
Group By Key: c2
-> Streaming(type: REDISTRIBUTE ng: ng1->ng3)
Spawn on: (ng1) datanode2, datanode3
-> Seq Scan on t1ng1
(10 rows)
select sum(c1), avg(c1), count(c1), c2 from t1ng1 group by 4 order by 1,2,3 limit 5;
sum | avg | count | c2
-------+----------------------+-------+----
24850 | 248.5000000000000000 | 100 | 1
24950 | 249.5000000000000000 | 100 | 2
25050 | 250.5000000000000000 | 100 | 3
25150 | 251.5000000000000000 | 100 | 4
25250 | 252.5000000000000000 | 100 | 0
(5 rows)
-- processing on ng3 but t1ng1 is distributed on ng1, so redistribute any way
explain (costs off) select sum(c1), avg(c1), count(c1), c1 from t1ng1 group by 4 order by 1,2,3;
QUERY PLAN
-----------------------------------------------------
Streaming (type: GATHER)
Merge Sort Key: (sum(c1)), (avg(c1)), (count(c1))
Node/s: (GenGroup) datanode2, datanode3
-> Sort
Sort Key: (sum(c1)), (avg(c1)), (count(c1))
-> HashAggregate
Group By Key: c1
-> Seq Scan on t1ng1
(8 rows)
select sum(c1), avg(c1), count(c1), c1 from t1ng1 group by 4 order by 1,2,3 limit 5;
sum | avg | count | c1
-----+------------------------+-------+----
1 | 1.00000000000000000000 | 1 | 1
2 | 2.0000000000000000 | 1 | 2
3 | 3.0000000000000000 | 1 | 3
4 | 4.0000000000000000 | 1 | 4
5 | 5.0000000000000000 | 1 | 5
(5 rows)
drop table t1ng1;
reset expected_computing_nodegroup;
drop node group ng1;
drop node group ng2;
drop node group ng3;
drop schema nodegroup_agg_test cascade;