From 24635f5cba09678f25c20441e8b604dcd4ce4a39 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 3 Jan 2024 22:49:07 +0100 Subject: [PATCH 1/3] Fix optimizer and return back KQP peephole type check. --- ydb/core/kqp/opt/peephole/kqp_opt_peephole.cpp | 10 +++------- ydb/library/yql/dq/opt/dq_opt_peephole.cpp | 10 ++++++---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/ydb/core/kqp/opt/peephole/kqp_opt_peephole.cpp b/ydb/core/kqp/opt/peephole/kqp_opt_peephole.cpp index b8ac524ff96b..bbb3dd54d221 100644 --- a/ydb/core/kqp/opt/peephole/kqp_opt_peephole.cpp +++ b/ydb/core/kqp/opt/peephole/kqp_opt_peephole.cpp @@ -87,8 +87,7 @@ TStatus ReplaceNonDetFunctionsWithParams(TExprNode::TPtr& input, TExprContext& c class TKqpPeepholeTransformer : public TOptimizeTransformerBase { public: TKqpPeepholeTransformer(TTypeAnnotationContext& typesCtx) - : TOptimizeTransformerBase(nullptr, NYql::NLog::EComponent::ProviderKqp, {}) - , TypesCtx(typesCtx) + : TOptimizeTransformerBase(&typesCtx, NYql::NLog::EComponent::ProviderKqp, {}) { #define HNDL(name) "KqpPeephole-"#name, Hndl(&TKqpPeepholeTransformer::name) AddHandler(0, &TDqReplicate::Match, HNDL(RewriteReplicate)); @@ -134,13 +133,13 @@ class TKqpPeepholeTransformer : public TOptimizeTransformerBase { } TMaybeNode BuildWideReadTable(TExprBase node, TExprContext& ctx) { - TExprBase output = KqpBuildWideReadTable(node, ctx, TypesCtx); + TExprBase output = KqpBuildWideReadTable(node, ctx, *Types); DumpAppliedRule("BuildWideReadTable", node.Ptr(), output.Ptr(), ctx); return output; } TMaybeNode RewriteLength(TExprBase node, TExprContext& ctx) { - TExprBase output = DqPeepholeRewriteLength(node, ctx, TypesCtx); + TExprBase output = DqPeepholeRewriteLength(node, ctx, *Types); DumpAppliedRule("RewriteLength", node.Ptr(), output.Ptr(), ctx); return output; } @@ -150,9 +149,6 @@ class TKqpPeepholeTransformer : public TOptimizeTransformerBase { DumpAppliedRule("RewriteKqpWriteConstraint", node.Ptr(), output.Ptr(), ctx); return output; } - -private: - TTypeAnnotationContext& TypesCtx; }; struct TKqpPeepholePipelineConfigurator : IPipelineConfigurator { diff --git a/ydb/library/yql/dq/opt/dq_opt_peephole.cpp b/ydb/library/yql/dq/opt/dq_opt_peephole.cpp index ed079387ffd8..599beb4d5ba4 100644 --- a/ydb/library/yql/dq/opt/dq_opt_peephole.cpp +++ b/ydb/library/yql/dq/opt/dq_opt_peephole.cpp @@ -513,16 +513,18 @@ NNodes::TExprBase DqPeepholeRewriteJoinDict(const NNodes::TExprBase& node, TExpr auto streamToDict = [&ctx](const TExprBase& input, const TExprNode::TPtr& keySelector) { return Build(ctx, input.Pos()) - .Stream(input) + .Stream() + .Input(input) + .Build() .KeySelector(keySelector) .PayloadSelector() .Args({"item"}) .Body("item") .Build() .Settings() - .Add().Build("Hashed") - .Add().Build("Many") - .Add().Build("Compact") + .Add().Build("Hashed", TNodeFlags::Default) + .Add().Build("Many", TNodeFlags::Default) + .Add().Build("Compact", TNodeFlags::Default) .Build() .Done(); }; From cb555e9d485cf5e04f28e804a628375fe9514945 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 4 Jan 2024 16:57:27 +0100 Subject: [PATCH 2/3] A little fix. --- ydb/library/yql/dq/opt/dq_opt_peephole.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ydb/library/yql/dq/opt/dq_opt_peephole.cpp b/ydb/library/yql/dq/opt/dq_opt_peephole.cpp index 599beb4d5ba4..59c96cdde59d 100644 --- a/ydb/library/yql/dq/opt/dq_opt_peephole.cpp +++ b/ydb/library/yql/dq/opt/dq_opt_peephole.cpp @@ -511,11 +511,9 @@ NNodes::TExprBase DqPeepholeRewriteJoinDict(const NNodes::TExprBase& node, TExpr rightKeySelector = BuildDictKeySelector(ctx, joinDict.Pos(), rightKeys, keyTypeItems, castKeyRight); } - auto streamToDict = [&ctx](const TExprBase& input, const TExprNode::TPtr& keySelector) { + const auto streamToDict = [&ctx](const TExprBase& input, const TExprNode::TPtr& keySelector) { return Build(ctx, input.Pos()) - .Stream() - .Input(input) - .Build() + .Stream(TCoIterator::Match(input.Raw()) ? TExprBase(ctx.RenameNode(input.Ref(), TCoToFlow::CallableName())) : input) .KeySelector(keySelector) .PayloadSelector() .Args({"item"}) From 8c211936b0007683ec9fd563342636f2e563ce84 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sun, 28 Jan 2024 13:45:44 +0100 Subject: [PATCH 3/3] Canonize test. --- .../query_14.plan | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/ydb/tests/functional/suite_tests/canondata/test_postgres.TestPGSQL.test_sql_suite_plan-jointest_join0.test_/query_14.plan b/ydb/tests/functional/suite_tests/canondata/test_postgres.TestPGSQL.test_sql_suite_plan-jointest_join0.test_/query_14.plan index f309a146c2ef..a32ec829c056 100644 --- a/ydb/tests/functional/suite_tests/canondata/test_postgres.TestPGSQL.test_sql_suite_plan-jointest_join0.test_/query_14.plan +++ b/ydb/tests/functional/suite_tests/canondata/test_postgres.TestPGSQL.test_sql_suite_plan-jointest_join0.test_/query_14.plan @@ -70,7 +70,7 @@ "PlanNodeType": "Connection", "Plans": [ { - "Node Type": "FullJoin (JoinDict)-ConstantExpr", + "Node Type": "FullJoin (JoinDict)", "Operators": [ { "Inputs": [ @@ -78,15 +78,10 @@ "ExternalPlanNodeId": 4 }, { - "InternalOperatorId": 1 + "Other": "ConstantExpression" } ], "Name": "FullJoin (JoinDict)" - }, - { - "Inputs": [], - "Iterator": "[{id: 1}]", - "Name": "Iterator" } ], "PlanNodeId": 5,