Skip to content

Commit 373467c

Browse files
authored
Don't count ToFlow children twice & print BlockCombineHashed as Aggregation (#11245)
1 parent 6a4b739 commit 373467c

File tree

14 files changed

+51
-182
lines changed

14 files changed

+51
-182
lines changed

ydb/core/kqp/opt/kqp_query_plan.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,8 @@ class TxPlanSerializer {
954954
operatorId = Visit(maybeCondense.Cast(), planNode);
955955
} else if (auto maybeCombiner = TMaybeNode<TCoCombineCore>(node)) {
956956
operatorId = Visit(maybeCombiner.Cast(), planNode);
957+
} else if (auto maybeBlockCombine = TMaybeNode<TCoBlockCombineHashed>(node)) {
958+
operatorId = Visit(maybeBlockCombine.Cast(), planNode);
957959
} else if (auto maybeSort = TMaybeNode<TCoSort>(node)) {
958960
operatorId = Visit(maybeSort.Cast(), planNode);
959961
} else if (auto maybeTop = TMaybeNode<TCoTop>(node)) {
@@ -1026,6 +1028,8 @@ class TxPlanSerializer {
10261028
} else {
10271029
operatorId = Visit(olapTable, planNode);
10281030
}
1031+
} else if (TMaybeNode<TCoToFlow>(node)) {
1032+
// do nothing
10291033
} else {
10301034
for (const auto& child : node->Children()) {
10311035
if(!child->IsLambda()) {
@@ -1168,6 +1172,40 @@ class TxPlanSerializer {
11681172
return AddOperator(planNode, "Aggregate", std::move(op));
11691173
}
11701174

1175+
std::variant<ui32, TArgContext> Visit(const TCoBlockCombineHashed& blockCombine, TQueryPlanNode& planNode) {
1176+
1177+
static const THashMap<TString, TString> aggregations = {
1178+
{"count", "COUNT"},
1179+
{"count_all", "COUNT"},
1180+
{"min", "MIN"},
1181+
{"max", "MAX"},
1182+
{"avg", "AVG"},
1183+
{"sum", "SUM"}
1184+
};
1185+
1186+
TOperator op;
1187+
op.Properties["Name"] = "Aggregate";
1188+
op.Properties["GroupBy"] = NPlanUtils::PrettyExprStr(blockCombine.Keys());
1189+
1190+
if (blockCombine.Aggregations().Ref().IsList()) {
1191+
TVector<TString> aggrs;
1192+
for (ui32 index = 0; index < blockCombine.Aggregations().Ref().ChildrenSize(); index++) {
1193+
auto child = blockCombine.Aggregations().Ref().Child(index);
1194+
if (child && child->IsList() && child->ChildrenSize() >= 2) {
1195+
auto callable = child->Child(0);
1196+
if (callable->ChildrenSize() >= 1) {
1197+
if (auto aggrName = TMaybeNode<TCoAtom>(callable->Child(0))) {
1198+
aggrs.push_back(aggregations.Value(aggrName.Cast().StringValue(), "??"));
1199+
}
1200+
}
1201+
}
1202+
}
1203+
op.Properties["Aggregation"] = JoinStrings(std::move(aggrs), ",");
1204+
}
1205+
1206+
return AddOperator(planNode, "Aggregate", std::move(op));
1207+
}
1208+
11711209
std::variant<ui32, TArgContext> Visit(const TCoSort& sort, TQueryPlanNode& planNode) {
11721210
TOperator op;
11731211
op.Properties["Name"] = "Sort";

ydb/tests/functional/canonical/canondata/test_sql.TestCanonicalFolder1.test_case_join_group_by_lookup.script-script_/join_group_by_lookup.script.plan

+1-14
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,8 @@
3535
"PlanNodeType": "Connection",
3636
"Plans": [
3737
{
38-
"Node Type": "TopSort-TopSort",
38+
"Node Type": "TopSort",
3939
"Operators": [
40-
{
41-
"Inputs": [
42-
{
43-
"InternalOperatorId": 1
44-
},
45-
{
46-
"ExternalPlanNodeId": 7
47-
}
48-
],
49-
"Limit": "1001",
50-
"Name": "TopSort",
51-
"TopSortBy": ""
52-
},
5340
{
5441
"Inputs": [
5542
{

ydb/tests/functional/suite_tests/canondata/test_postgres.TestPGSQL.test_sql_suite_plan-jointest_coalesce-and-join.test_/query_1.plan

+1-14
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,8 @@
2929
"PlanNodeType": "Connection",
3030
"Plans": [
3131
{
32-
"Node Type": "TopSort-TopSort",
32+
"Node Type": "TopSort",
3333
"Operators": [
34-
{
35-
"Inputs": [
36-
{
37-
"InternalOperatorId": 1
38-
},
39-
{
40-
"ExternalPlanNodeId": 9
41-
}
42-
],
43-
"Limit": "1001",
44-
"Name": "TopSort",
45-
"TopSortBy": "argument.qr.y"
46-
},
4734
{
4835
"Inputs": [
4936
{

ydb/tests/functional/suite_tests/canondata/test_postgres.TestPGSQL.test_sql_suite_plan-jointest_coalesce-and-join.test_/query_2.plan

+1-14
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,8 @@
2929
"PlanNodeType": "Connection",
3030
"Plans": [
3131
{
32-
"Node Type": "TopSort-TopSort",
32+
"Node Type": "TopSort",
3333
"Operators": [
34-
{
35-
"Inputs": [
36-
{
37-
"InternalOperatorId": 1
38-
},
39-
{
40-
"ExternalPlanNodeId": 5
41-
}
42-
],
43-
"Limit": "1001",
44-
"Name": "TopSort",
45-
"TopSortBy": "argument.a.y"
46-
},
4734
{
4835
"Inputs": [
4936
{

ydb/tests/functional/suite_tests/canondata/test_postgres.TestPGSQL.test_sql_suite_plan-jointest_coalesce-and-join.test_/query_3.plan

+1-14
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,8 @@
2929
"PlanNodeType": "Connection",
3030
"Plans": [
3131
{
32-
"Node Type": "TopSort-TopSort",
32+
"Node Type": "TopSort",
3333
"Operators": [
34-
{
35-
"Inputs": [
36-
{
37-
"InternalOperatorId": 1
38-
},
39-
{
40-
"ExternalPlanNodeId": 5
41-
}
42-
],
43-
"Limit": "1001",
44-
"Name": "TopSort",
45-
"TopSortBy": "argument.pv.x"
46-
},
4734
{
4835
"Inputs": [
4936
{

ydb/tests/functional/suite_tests/canondata/test_postgres.TestPGSQL.test_sql_suite_plan-jointest_coalesce-and-join.test_/query_4.plan

+1-14
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,8 @@
2929
"PlanNodeType": "Connection",
3030
"Plans": [
3131
{
32-
"Node Type": "TopSort-TopSort",
32+
"Node Type": "TopSort",
3333
"Operators": [
34-
{
35-
"Inputs": [
36-
{
37-
"InternalOperatorId": 1
38-
},
39-
{
40-
"ExternalPlanNodeId": 5
41-
}
42-
],
43-
"Limit": "1001",
44-
"Name": "TopSort",
45-
"TopSortBy": "argument.yy.pkyy"
46-
},
4734
{
4835
"Inputs": [
4936
{

ydb/tests/functional/suite_tests/canondata/test_postgres.TestPGSQL.test_sql_suite_plan-jointest_join1.test_/query_1.plan

+1-14
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,8 @@
2929
"PlanNodeType": "Connection",
3030
"Plans": [
3131
{
32-
"Node Type": "TopSort-TopSort",
32+
"Node Type": "TopSort",
3333
"Operators": [
34-
{
35-
"Inputs": [
36-
{
37-
"InternalOperatorId": 1
38-
},
39-
{
40-
"ExternalPlanNodeId": 5
41-
}
42-
],
43-
"Limit": "1001",
44-
"Name": "TopSort",
45-
"TopSortBy": ""
46-
},
4734
{
4835
"Inputs": [
4936
{

ydb/tests/functional/suite_tests/canondata/test_postgres.TestPGSQL.test_sql_suite_plan-jointest_join1.test_/query_2.plan

+1-14
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,8 @@
2929
"PlanNodeType": "Connection",
3030
"Plans": [
3131
{
32-
"Node Type": "TopSort-TopSort",
32+
"Node Type": "TopSort",
3333
"Operators": [
34-
{
35-
"Inputs": [
36-
{
37-
"InternalOperatorId": 1
38-
},
39-
{
40-
"ExternalPlanNodeId": 5
41-
}
42-
],
43-
"Limit": "1001",
44-
"Name": "TopSort",
45-
"TopSortBy": ""
46-
},
4734
{
4835
"Inputs": [
4936
{

ydb/tests/functional/suite_tests/canondata/test_postgres.TestPGSQL.test_sql_suite_plan-jointest_join1.test_/query_3.plan

+1-14
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,8 @@
2929
"PlanNodeType": "Connection",
3030
"Plans": [
3131
{
32-
"Node Type": "TopSort-TopSort",
32+
"Node Type": "TopSort",
3333
"Operators": [
34-
{
35-
"Inputs": [
36-
{
37-
"InternalOperatorId": 1
38-
},
39-
{
40-
"ExternalPlanNodeId": 5
41-
}
42-
],
43-
"Limit": "1001",
44-
"Name": "TopSort",
45-
"TopSortBy": ""
46-
},
4734
{
4835
"Inputs": [
4936
{

ydb/tests/functional/suite_tests/canondata/test_postgres.TestPGSQL.test_sql_suite_plan-jointest_join1.test_/query_5.plan

+1-14
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,8 @@
2929
"PlanNodeType": "Connection",
3030
"Plans": [
3131
{
32-
"Node Type": "TopSort-TopSort",
32+
"Node Type": "TopSort",
3333
"Operators": [
34-
{
35-
"Inputs": [
36-
{
37-
"InternalOperatorId": 1
38-
},
39-
{
40-
"ExternalPlanNodeId": 5
41-
}
42-
],
43-
"Limit": "1001",
44-
"Name": "TopSort",
45-
"TopSortBy": ""
46-
},
4734
{
4835
"Inputs": [
4936
{

ydb/tests/functional/suite_tests/canondata/test_postgres.TestPGSQL.test_sql_suite_plan-jointest_join1.test_/query_7.plan

+1-14
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,8 @@
2929
"PlanNodeType": "Connection",
3030
"Plans": [
3131
{
32-
"Node Type": "TopSort-TopSort",
32+
"Node Type": "TopSort",
3333
"Operators": [
34-
{
35-
"Inputs": [
36-
{
37-
"InternalOperatorId": 1
38-
},
39-
{
40-
"ExternalPlanNodeId": 5
41-
}
42-
],
43-
"Limit": "1001",
44-
"Name": "TopSort",
45-
"TopSortBy": ""
46-
},
4734
{
4835
"Inputs": [
4936
{

ydb/tests/functional/suite_tests/canondata/test_postgres.TestPGSQL.test_sql_suite_plan-jointest_join1.test_/query_8.plan

+1-14
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,8 @@
2929
"PlanNodeType": "Connection",
3030
"Plans": [
3131
{
32-
"Node Type": "TopSort-TopSort",
32+
"Node Type": "TopSort",
3333
"Operators": [
34-
{
35-
"Inputs": [
36-
{
37-
"InternalOperatorId": 1
38-
},
39-
{
40-
"ExternalPlanNodeId": 5
41-
}
42-
],
43-
"Limit": "1001",
44-
"Name": "TopSort",
45-
"TopSortBy": ""
46-
},
4734
{
4835
"Inputs": [
4936
{

ydb/tests/functional/suite_tests/canondata/test_postgres.TestPGSQL.test_sql_suite_plan-jointest_join3.test_/query_2.plan

+1-14
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,8 @@
2929
"PlanNodeType": "Connection",
3030
"Plans": [
3131
{
32-
"Node Type": "TopSort-TopSort",
32+
"Node Type": "TopSort",
3333
"Operators": [
34-
{
35-
"Inputs": [
36-
{
37-
"InternalOperatorId": 1
38-
},
39-
{
40-
"ExternalPlanNodeId": 5
41-
}
42-
],
43-
"Limit": "1001",
44-
"Name": "TopSort",
45-
"TopSortBy": "argument.p.k"
46-
},
4734
{
4835
"Inputs": [
4936
{

ydb/tests/functional/suite_tests/canondata/test_postgres.TestPGSQL.test_sql_suite_plan-jointest_join4.test_/query_13.plan

+1-14
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,8 @@
2929
"PlanNodeType": "Connection",
3030
"Plans": [
3131
{
32-
"Node Type": "TopSort-TopSort",
32+
"Node Type": "TopSort",
3333
"Operators": [
34-
{
35-
"Inputs": [
36-
{
37-
"InternalOperatorId": 1
38-
},
39-
{
40-
"ExternalPlanNodeId": 5
41-
}
42-
],
43-
"Limit": "1001",
44-
"Name": "TopSort",
45-
"TopSortBy": ""
46-
},
4734
{
4835
"Inputs": [
4936
{

0 commit comments

Comments
 (0)