From 4c98180e9ccb2bef1cdfad3f634d78d8aabb11c4 Mon Sep 17 00:00:00 2001 From: Pavel Ivanov Date: Wed, 25 Sep 2024 17:36:26 +0000 Subject: [PATCH 1/2] [CBO] Hints warning messages improvement --- ydb/core/kqp/opt/logical/kqp_opt_log.cpp | 6 ++++-- ydb/library/yql/core/cbo/cbo_hints.cpp | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ydb/core/kqp/opt/logical/kqp_opt_log.cpp b/ydb/core/kqp/opt/logical/kqp_opt_log.cpp index 445cd1252acc..125af82b548b 100644 --- a/ydb/core/kqp/opt/logical/kqp_opt_log.cpp +++ b/ydb/core/kqp/opt/logical/kqp_opt_log.cpp @@ -92,8 +92,10 @@ class TKqpLogicalOptTransformer : public TOptimizeTransformerBase { TStatus DoTransform(TExprNode::TPtr input, TExprNode::TPtr& output, TExprContext& ctx) override { auto status = TOptimizeTransformerBase::DoTransform(input, output, ctx); - for (const auto& hint: KqpCtx.GetOptimizerHints().GetUnappliedString()) { - ctx.AddWarning(YqlIssue({}, TIssuesIds::YQL_UNUSED_HINT, "Unapplied hint: " + hint)); + if (status == TStatus::Ok) { + for (const auto& hint: KqpCtx.GetOptimizerHints().GetUnappliedString()) { + ctx.AddWarning(YqlIssue({}, TIssuesIds::YQL_UNUSED_HINT, "Unapplied hint: " + hint)); + } } return status; diff --git a/ydb/library/yql/core/cbo/cbo_hints.cpp b/ydb/library/yql/core/cbo/cbo_hints.cpp index 2efa74242f71..8d6e45de711b 100644 --- a/ydb/library/yql/core/cbo/cbo_hints.cpp +++ b/ydb/library/yql/core/cbo/cbo_hints.cpp @@ -46,9 +46,9 @@ class TOptimizerHintsParser { } void JoinAlgo() { - Keyword({"("}); - i32 beginPos = Pos + 1; + + Keyword({"("}); i32 labelsBeginPos = Pos + 1; TVector labels = CollectLabels(); @@ -65,7 +65,7 @@ class TOptimizerHintsParser { for (const auto& [joinAlgo, joinAlgoStr]: Zip(joinAlgos, joinAlgosStr)) { if (reqJoinAlgoStr == joinAlgoStr) { - Hints.JoinAlgoHints->PushBack(std::move(labels), joinAlgo, "JoinOrder" + Text.substr(beginPos, Pos - beginPos + 1)); + Hints.JoinAlgoHints->PushBack(std::move(labels), joinAlgo, "JoinAlgo" + Text.substr(beginPos, Pos - beginPos + 1)); return; } } From 5e30f9a40d5c23621a76e623f9f213c126a439ba Mon Sep 17 00:00:00 2001 From: Pavel Ivanov Date: Wed, 25 Sep 2024 18:28:55 +0000 Subject: [PATCH 2/2] [CBO] Hints warning messages improvement --- ydb/library/yql/core/cbo/cbo_optimizer_new.h | 6 +++--- ydb/library/yql/dq/opt/dq_opt_dphyp_solver.h | 15 ++++++--------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/ydb/library/yql/core/cbo/cbo_optimizer_new.h b/ydb/library/yql/core/cbo/cbo_optimizer_new.h index 9d6950be6479..7f009a61d5fd 100644 --- a/ydb/library/yql/core/cbo/cbo_optimizer_new.h +++ b/ydb/library/yql/core/cbo/cbo_optimizer_new.h @@ -101,15 +101,15 @@ struct TCardinalityHints { struct TJoinAlgoHints { struct TJoinAlgoHint { TVector JoinLabels; - EJoinAlgoType JoinHint; + EJoinAlgoType Algo; TString StringRepr; bool Applied = false; }; TVector Hints; - void PushBack(TVector labels, EJoinAlgoType joinHint, TString stringRepr) { - Hints.push_back({.JoinLabels = std::move(labels), .JoinHint = joinHint, .StringRepr = std::move(stringRepr)}); + void PushBack(TVector labels, EJoinAlgoType algo, TString stringRepr) { + Hints.push_back({.JoinLabels = std::move(labels), .Algo = algo, .StringRepr = std::move(stringRepr)}); } }; diff --git a/ydb/library/yql/dq/opt/dq_opt_dphyp_solver.h b/ydb/library/yql/dq/opt/dq_opt_dphyp_solver.h index 142e97bab4f9..32ae0fb96fb6 100644 --- a/ydb/library/yql/dq/opt/dq_opt_dphyp_solver.h +++ b/ydb/library/yql/dq/opt/dq_opt_dphyp_solver.h @@ -420,8 +420,13 @@ template std::shared_ptr TDPHypS const TVector& rightJoinKeys, IProviderContext& ctx, TCardinalityHints::TCardinalityHint* maybeCardHint, - TJoinAlgoHints::TJoinAlgoHint* maybeJoinHint + TJoinAlgoHints::TJoinAlgoHint* maybeJoinAlgoHint ) { + if (maybeJoinAlgoHint) { + maybeJoinAlgoHint->Applied = true; + return MakeJoinInternal(left, right, joinConditions, leftJoinKeys, rightJoinKeys, joinKind, maybeJoinAlgoHint->Algo, leftAny, rightAny, ctx, maybeCardHint); + } + double bestCost = std::numeric_limits::infinity(); EJoinAlgoType bestAlgo = EJoinAlgoType::Undefined; bool bestJoinIsReversed = false; @@ -429,10 +434,6 @@ template std::shared_ptr TDPHypS for (auto joinAlgo : AllJoinAlgos) { if (ctx.IsJoinApplicable(left, right, joinConditions, leftJoinKeys, rightJoinKeys, joinAlgo, joinKind)){ auto cost = ctx.ComputeJoinStats(*left->Stats, *right->Stats, leftJoinKeys, rightJoinKeys, joinAlgo, joinKind, maybeCardHint).Cost; - if (maybeJoinHint && joinAlgo == maybeJoinHint->JoinHint) { - cost = -1; - maybeJoinHint->Applied = true; - } if (cost < bestCost) { bestCost = cost; bestAlgo = joinAlgo; @@ -443,10 +444,6 @@ template std::shared_ptr TDPHypS if (isCommutative) { if (ctx.IsJoinApplicable(right, left, reversedJoinConditions, rightJoinKeys, leftJoinKeys, joinAlgo, joinKind)){ auto cost = ctx.ComputeJoinStats(*right->Stats, *left->Stats, rightJoinKeys, leftJoinKeys, joinAlgo, joinKind, maybeCardHint).Cost; - if (maybeJoinHint && joinAlgo == maybeJoinHint->JoinHint) { - cost = -1; - maybeJoinHint->Applied = true; - } if (cost < bestCost) { bestCost = cost; bestAlgo = joinAlgo;