aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpilik <pudge1000-7@ydb.tech>2024-09-26 13:45:50 +0300
committerGitHub <noreply@github.com>2024-09-26 13:45:50 +0300
commit0e1b9d0cb50f63563a741d69876a4db73b64ed00 (patch)
treeb35fc186397f0fc4edac01d8859e231444433a07
parent77c68bdaea836c4436834f995b5357889acb6e9d (diff)
downloadydb-0e1b9d0cb50f63563a741d69876a4db73b64ed00.tar.gz
[CBO] Ignore IsJoinApplicable with hints. Improve hints warning messages (#9770)
-rw-r--r--ydb/core/kqp/opt/logical/kqp_opt_log.cpp6
-rw-r--r--ydb/library/yql/core/cbo/cbo_hints.cpp6
-rw-r--r--ydb/library/yql/core/cbo/cbo_optimizer_new.h6
-rw-r--r--ydb/library/yql/dq/opt/dq_opt_dphyp_solver.h15
4 files changed, 16 insertions, 17 deletions
diff --git a/ydb/core/kqp/opt/logical/kqp_opt_log.cpp b/ydb/core/kqp/opt/logical/kqp_opt_log.cpp
index 445cd1252a..125af82b54 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 @@ public:
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 2efa74242f..8d6e45de71 100644
--- a/ydb/library/yql/core/cbo/cbo_hints.cpp
+++ b/ydb/library/yql/core/cbo/cbo_hints.cpp
@@ -46,9 +46,9 @@ private:
}
void JoinAlgo() {
- Keyword({"("});
-
i32 beginPos = Pos + 1;
+
+ Keyword({"("});
i32 labelsBeginPos = Pos + 1;
TVector<TString> labels = CollectLabels();
@@ -65,7 +65,7 @@ private:
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;
}
}
diff --git a/ydb/library/yql/core/cbo/cbo_optimizer_new.h b/ydb/library/yql/core/cbo/cbo_optimizer_new.h
index 9d6950be64..7f009a61d5 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<TString> JoinLabels;
- EJoinAlgoType JoinHint;
+ EJoinAlgoType Algo;
TString StringRepr;
bool Applied = false;
};
TVector<TJoinAlgoHint> Hints;
- void PushBack(TVector<TString> labels, EJoinAlgoType joinHint, TString stringRepr) {
- Hints.push_back({.JoinLabels = std::move(labels), .JoinHint = joinHint, .StringRepr = std::move(stringRepr)});
+ void PushBack(TVector<TString> 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 142e97bab4..32ae0fb96f 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 <typename TNodeSet> std::shared_ptr<TJoinOptimizerNodeInternal> TDPHypS
const TVector<TString>& 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<double>::infinity();
EJoinAlgoType bestAlgo = EJoinAlgoType::Undefined;
bool bestJoinIsReversed = false;
@@ -429,10 +434,6 @@ template <typename TNodeSet> std::shared_ptr<TJoinOptimizerNodeInternal> 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 <typename TNodeSet> std::shared_ptr<TJoinOptimizerNodeInternal> 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;