Skip to content

Commit

Permalink
Don't count ToFlow children twice & print BlockCombineHashed as Aggre…
Browse files Browse the repository at this point in the history
…gation (ydb-platform#11245)
  • Loading branch information
Hor911 authored Nov 4, 2024
1 parent 6a4b739 commit 373467c
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 182 deletions.
38 changes: 38 additions & 0 deletions ydb/core/kqp/opt/kqp_query_plan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,8 @@ class TxPlanSerializer {
operatorId = Visit(maybeCondense.Cast(), planNode);
} else if (auto maybeCombiner = TMaybeNode<TCoCombineCore>(node)) {
operatorId = Visit(maybeCombiner.Cast(), planNode);
} else if (auto maybeBlockCombine = TMaybeNode<TCoBlockCombineHashed>(node)) {
operatorId = Visit(maybeBlockCombine.Cast(), planNode);
} else if (auto maybeSort = TMaybeNode<TCoSort>(node)) {
operatorId = Visit(maybeSort.Cast(), planNode);
} else if (auto maybeTop = TMaybeNode<TCoTop>(node)) {
Expand Down Expand Up @@ -1026,6 +1028,8 @@ class TxPlanSerializer {
} else {
operatorId = Visit(olapTable, planNode);
}
} else if (TMaybeNode<TCoToFlow>(node)) {
// do nothing
} else {
for (const auto& child : node->Children()) {
if(!child->IsLambda()) {
Expand Down Expand Up @@ -1168,6 +1172,40 @@ class TxPlanSerializer {
return AddOperator(planNode, "Aggregate", std::move(op));
}

std::variant<ui32, TArgContext> Visit(const TCoBlockCombineHashed& blockCombine, TQueryPlanNode& planNode) {

static const THashMap<TString, TString> aggregations = {
{"count", "COUNT"},
{"count_all", "COUNT"},
{"min", "MIN"},
{"max", "MAX"},
{"avg", "AVG"},
{"sum", "SUM"}
};

TOperator op;
op.Properties["Name"] = "Aggregate";
op.Properties["GroupBy"] = NPlanUtils::PrettyExprStr(blockCombine.Keys());

if (blockCombine.Aggregations().Ref().IsList()) {
TVector<TString> aggrs;
for (ui32 index = 0; index < blockCombine.Aggregations().Ref().ChildrenSize(); index++) {
auto child = blockCombine.Aggregations().Ref().Child(index);
if (child && child->IsList() && child->ChildrenSize() >= 2) {
auto callable = child->Child(0);
if (callable->ChildrenSize() >= 1) {
if (auto aggrName = TMaybeNode<TCoAtom>(callable->Child(0))) {
aggrs.push_back(aggregations.Value(aggrName.Cast().StringValue(), "??"));
}
}
}
}
op.Properties["Aggregation"] = JoinStrings(std::move(aggrs), ",");
}

return AddOperator(planNode, "Aggregate", std::move(op));
}

std::variant<ui32, TArgContext> Visit(const TCoSort& sort, TQueryPlanNode& planNode) {
TOperator op;
op.Properties["Name"] = "Sort";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,8 @@
"PlanNodeType": "Connection",
"Plans": [
{
"Node Type": "TopSort-TopSort",
"Node Type": "TopSort",
"Operators": [
{
"Inputs": [
{
"InternalOperatorId": 1
},
{
"ExternalPlanNodeId": 7
}
],
"Limit": "1001",
"Name": "TopSort",
"TopSortBy": ""
},
{
"Inputs": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,8 @@
"PlanNodeType": "Connection",
"Plans": [
{
"Node Type": "TopSort-TopSort",
"Node Type": "TopSort",
"Operators": [
{
"Inputs": [
{
"InternalOperatorId": 1
},
{
"ExternalPlanNodeId": 9
}
],
"Limit": "1001",
"Name": "TopSort",
"TopSortBy": "argument.qr.y"
},
{
"Inputs": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,8 @@
"PlanNodeType": "Connection",
"Plans": [
{
"Node Type": "TopSort-TopSort",
"Node Type": "TopSort",
"Operators": [
{
"Inputs": [
{
"InternalOperatorId": 1
},
{
"ExternalPlanNodeId": 5
}
],
"Limit": "1001",
"Name": "TopSort",
"TopSortBy": "argument.a.y"
},
{
"Inputs": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,8 @@
"PlanNodeType": "Connection",
"Plans": [
{
"Node Type": "TopSort-TopSort",
"Node Type": "TopSort",
"Operators": [
{
"Inputs": [
{
"InternalOperatorId": 1
},
{
"ExternalPlanNodeId": 5
}
],
"Limit": "1001",
"Name": "TopSort",
"TopSortBy": "argument.pv.x"
},
{
"Inputs": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,8 @@
"PlanNodeType": "Connection",
"Plans": [
{
"Node Type": "TopSort-TopSort",
"Node Type": "TopSort",
"Operators": [
{
"Inputs": [
{
"InternalOperatorId": 1
},
{
"ExternalPlanNodeId": 5
}
],
"Limit": "1001",
"Name": "TopSort",
"TopSortBy": "argument.yy.pkyy"
},
{
"Inputs": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,8 @@
"PlanNodeType": "Connection",
"Plans": [
{
"Node Type": "TopSort-TopSort",
"Node Type": "TopSort",
"Operators": [
{
"Inputs": [
{
"InternalOperatorId": 1
},
{
"ExternalPlanNodeId": 5
}
],
"Limit": "1001",
"Name": "TopSort",
"TopSortBy": ""
},
{
"Inputs": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,8 @@
"PlanNodeType": "Connection",
"Plans": [
{
"Node Type": "TopSort-TopSort",
"Node Type": "TopSort",
"Operators": [
{
"Inputs": [
{
"InternalOperatorId": 1
},
{
"ExternalPlanNodeId": 5
}
],
"Limit": "1001",
"Name": "TopSort",
"TopSortBy": ""
},
{
"Inputs": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,8 @@
"PlanNodeType": "Connection",
"Plans": [
{
"Node Type": "TopSort-TopSort",
"Node Type": "TopSort",
"Operators": [
{
"Inputs": [
{
"InternalOperatorId": 1
},
{
"ExternalPlanNodeId": 5
}
],
"Limit": "1001",
"Name": "TopSort",
"TopSortBy": ""
},
{
"Inputs": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,8 @@
"PlanNodeType": "Connection",
"Plans": [
{
"Node Type": "TopSort-TopSort",
"Node Type": "TopSort",
"Operators": [
{
"Inputs": [
{
"InternalOperatorId": 1
},
{
"ExternalPlanNodeId": 5
}
],
"Limit": "1001",
"Name": "TopSort",
"TopSortBy": ""
},
{
"Inputs": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,8 @@
"PlanNodeType": "Connection",
"Plans": [
{
"Node Type": "TopSort-TopSort",
"Node Type": "TopSort",
"Operators": [
{
"Inputs": [
{
"InternalOperatorId": 1
},
{
"ExternalPlanNodeId": 5
}
],
"Limit": "1001",
"Name": "TopSort",
"TopSortBy": ""
},
{
"Inputs": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,8 @@
"PlanNodeType": "Connection",
"Plans": [
{
"Node Type": "TopSort-TopSort",
"Node Type": "TopSort",
"Operators": [
{
"Inputs": [
{
"InternalOperatorId": 1
},
{
"ExternalPlanNodeId": 5
}
],
"Limit": "1001",
"Name": "TopSort",
"TopSortBy": ""
},
{
"Inputs": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,8 @@
"PlanNodeType": "Connection",
"Plans": [
{
"Node Type": "TopSort-TopSort",
"Node Type": "TopSort",
"Operators": [
{
"Inputs": [
{
"InternalOperatorId": 1
},
{
"ExternalPlanNodeId": 5
}
],
"Limit": "1001",
"Name": "TopSort",
"TopSortBy": "argument.p.k"
},
{
"Inputs": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,8 @@
"PlanNodeType": "Connection",
"Plans": [
{
"Node Type": "TopSort-TopSort",
"Node Type": "TopSort",
"Operators": [
{
"Inputs": [
{
"InternalOperatorId": 1
},
{
"ExternalPlanNodeId": 5
}
],
"Limit": "1001",
"Name": "TopSort",
"TopSortBy": ""
},
{
"Inputs": [
{
Expand Down

0 comments on commit 373467c

Please sign in to comment.