diff options
| author | Vitaly Stoyan <[email protected]> | 2022-06-25 01:28:56 +0300 |
|---|---|---|
| committer | Vitaly Stoyan <[email protected]> | 2022-06-25 01:28:56 +0300 |
| commit | d362d692242721c003d1002fc959b459eef9fe9d (patch) | |
| tree | 818da179cf89c5ad684e99ad6a53d56972e015f4 | |
| parent | 78f5df6c67aaf7898dc41af27b66109f893f98cc (diff) | |
YQL-14728 rotate cross joins in any subtree
ref:57e910b6c3372857c57597808f334fde700e25d2
| -rw-r--r-- | ydb/library/yql/core/common_opt/yql_co_flow2.cpp | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/ydb/library/yql/core/common_opt/yql_co_flow2.cpp b/ydb/library/yql/core/common_opt/yql_co_flow2.cpp index 315dbb398ed..0300178d89b 100644 --- a/ydb/library/yql/core/common_opt/yql_co_flow2.cpp +++ b/ydb/library/yql/core/common_opt/yql_co_flow2.cpp @@ -423,15 +423,39 @@ public: {} TExprNode::TPtr Run() { - auto pos = JoinTree->Pos(); - GatherCross(JoinTree); + auto joinTree = RotateCrossJoin(JoinTree->Pos(), JoinTree); + auto newJoinTree = std::get<0>(AddLink(joinTree)); + YQL_ENSURE(Updated); + return newJoinTree; + } + +private: + TExprNode::TPtr RotateCrossJoin(TPositionHandle pos, TExprNode::TPtr joinTree) { + if (joinTree->Child(0)->Content() != "Cross") { + auto children = joinTree->ChildrenList(); + auto& left = children[1]; + auto& right = children[2]; + + if (!left->IsAtom()) { + left = RotateCrossJoin(pos, left); + } + + if (!right->IsAtom()) { + right = RotateCrossJoin(pos, right); + } + + return Ctx.ChangeChildren(*joinTree, std::move(children)); + } + + CrossJoins.clear(); + RestJoins.clear(); + GatherCross(joinTree); auto inCross1 = FindPtr(CrossJoins, Labels[0]); auto inCross2 = FindPtr(CrossJoins, Labels[1]); - auto joinTree = JoinTree; if (inCross1 || inCross2) { if (inCross1 && inCross2) { // make them a leaf - joinTree = MakeCrossJoin(pos, Ctx.NewAtom(pos, Labels[0]), Ctx.NewAtom(pos, Labels[1]), Ctx); + joinTree = MakeCrossJoin(pos, Ctx.NewAtom(pos, Labels[0]), Ctx.NewAtom(pos, Labels[1]), Ctx); for (auto label : CrossJoins) { if (label != Labels[0] && label != Labels[1]) { joinTree = MakeCrossJoin(pos, joinTree, Ctx.NewAtom(pos, label), Ctx); @@ -466,12 +490,9 @@ public: } } - auto newJoinTree = std::get<0>(AddLink(joinTree)); - YQL_ENSURE(Updated); - return newJoinTree; + return joinTree; } -private: TExprNode::TPtr AddRestJoins(TPositionHandle pos, TExprNode::TPtr joinTree, TExprNode::TPtr exclude) { for (auto join : RestJoins) { if (join == exclude) { |
