summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authora-romanov <[email protected]>2023-08-21 11:06:57 +0300
committera-romanov <[email protected]>2023-08-21 12:50:37 +0300
commit690f7c373e2476ad0b37f3980f7df49c3c3b4ee1 (patch)
treeab86cc2c550eb72c73e700b8c4be47c398b35b4f
parent619eea5881bf9fe8461a09ad5ca20233075ba358 (diff)
Suppress ordered input of DqJoin.
-rw-r--r--ydb/library/yql/dq/opt/dq_opt_join.cpp42
-rw-r--r--ydb/library/yql/dq/opt/dq_opt_join.h2
-rw-r--r--ydb/library/yql/providers/dq/opt/physical_optimize.cpp5
3 files changed, 49 insertions, 0 deletions
diff --git a/ydb/library/yql/dq/opt/dq_opt_join.cpp b/ydb/library/yql/dq/opt/dq_opt_join.cpp
index 56a9092845a..993829b6dcf 100644
--- a/ydb/library/yql/dq/opt/dq_opt_join.cpp
+++ b/ydb/library/yql/dq/opt/dq_opt_join.cpp
@@ -425,6 +425,48 @@ TExprBase DqRewriteEquiJoin(const TExprBase& node, EHashJoinMode mode, TExprCont
return projection;
}
+TDqJoin DqSuppressSortOnJoinInput(const TDqJoin& join, TExprContext& ctx) {
+ const bool lOrdered = join.LeftInput().Ref().GetConstraint<TSortedConstraintNode>() || join.LeftInput().Ref().GetConstraint<TChoppedConstraintNode>();
+ const bool rOrdered = join.RightInput().Ref().GetConstraint<TSortedConstraintNode>() || join.RightInput().Ref().GetConstraint<TChoppedConstraintNode>();
+
+ if (lOrdered && rOrdered)
+ return Build<TDqJoin>(ctx, join.Pos())
+ .LeftInput<TCoUnordered>()
+ .Input(join.LeftInput())
+ .Build()
+ .RightInput<TCoUnordered>()
+ .Input(join.RightInput())
+ .Build()
+ .LeftLabel(join.RightLabel())
+ .RightLabel(join.LeftLabel())
+ .JoinType(join.JoinType())
+ .JoinKeys(join.JoinKeys())
+ .Done();
+ else if (lOrdered)
+ return Build<TDqJoin>(ctx, join.Pos())
+ .LeftInput<TCoUnordered>()
+ .Input(join.LeftInput())
+ .Build()
+ .RightInput(join.RightInput())
+ .LeftLabel(join.RightLabel())
+ .RightLabel(join.LeftLabel())
+ .JoinType(join.JoinType())
+ .JoinKeys(join.JoinKeys())
+ .Done();
+ else if (rOrdered)
+ return Build<TDqJoin>(ctx, join.Pos())
+ .LeftInput(join.LeftInput())
+ .RightInput<TCoUnordered>()
+ .Input(join.RightInput())
+ .Build()
+ .LeftLabel(join.RightLabel())
+ .RightLabel(join.LeftLabel())
+ .JoinType(join.JoinType())
+ .JoinKeys(join.JoinKeys())
+ .Done();
+ return join;
+}
+
TExprBase DqRewriteRightJoinToLeft(const TExprBase node, TExprContext& ctx) {
if (!node.Maybe<TDqJoin>()) {
return node;
diff --git a/ydb/library/yql/dq/opt/dq_opt_join.h b/ydb/library/yql/dq/opt/dq_opt_join.h
index 85268016708..b5b8213bcc9 100644
--- a/ydb/library/yql/dq/opt/dq_opt_join.h
+++ b/ydb/library/yql/dq/opt/dq_opt_join.h
@@ -18,4 +18,6 @@ NNodes::TExprBase DqBuildHashJoin(const NNodes::TDqJoin& join, EHashJoinMode mod
NNodes::TExprBase DqBuildJoinDict(const NNodes::TDqJoin& join, TExprContext& ctx);
+NNodes::TDqJoin DqSuppressSortOnJoinInput(const NNodes::TDqJoin& node, TExprContext& ctx);
+
}
diff --git a/ydb/library/yql/providers/dq/opt/physical_optimize.cpp b/ydb/library/yql/providers/dq/opt/physical_optimize.cpp
index 18a5478a9d8..d3cbaddc15e 100644
--- a/ydb/library/yql/providers/dq/opt/physical_optimize.cpp
+++ b/ydb/library/yql/providers/dq/opt/physical_optimize.cpp
@@ -42,6 +42,7 @@ public:
AddHandler(0, &TCoTakeBase::Match, HNDL(BuildTakeOrTakeSkipStage<false>));
AddHandler(0, &TCoLength::Match, HNDL(RewriteLengthOfStageOutput<false>));
AddHandler(0, &TCoExtendBase::Match, HNDL(BuildExtendStage));
+ AddHandler(0, &TDqJoin::Match, HNDL(SuppressSortOnJoinInput));
AddHandler(0, &TDqJoin::Match, HNDL(RewriteRightJoinToLeft));
AddHandler(0, &TDqJoin::Match, HNDL(RewriteLeftPureJoin<false>));
AddHandler(0, &TDqJoin::Match, HNDL(BuildJoin<false>));
@@ -236,6 +237,10 @@ protected:
return DqRewriteRightJoinToLeft(node, ctx);
}
+ TMaybeNode<TExprBase> SuppressSortOnJoinInput(TExprBase node, TExprContext& ctx) {
+ return DqSuppressSortOnJoinInput(node.Cast<TDqJoin>(),ctx);
+ }
+
template <bool IsGlobal>
TMaybeNode<TExprBase> RewriteLeftPureJoin(TExprBase node, TExprContext& ctx, const TGetParents& getParents) {
return DqRewriteLeftPureJoin(node, ctx, *getParents(), IsGlobal);