Skip to content

Commit 0e1b9d0

Browse files
authored
[CBO] Ignore IsJoinApplicable with hints. Improve hints warning messages (#9770)
1 parent 77c68bd commit 0e1b9d0

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

ydb/core/kqp/opt/logical/kqp_opt_log.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ class TKqpLogicalOptTransformer : public TOptimizeTransformerBase {
9292
TStatus DoTransform(TExprNode::TPtr input, TExprNode::TPtr& output, TExprContext& ctx) override {
9393
auto status = TOptimizeTransformerBase::DoTransform(input, output, ctx);
9494

95-
for (const auto& hint: KqpCtx.GetOptimizerHints().GetUnappliedString()) {
96-
ctx.AddWarning(YqlIssue({}, TIssuesIds::YQL_UNUSED_HINT, "Unapplied hint: " + hint));
95+
if (status == TStatus::Ok) {
96+
for (const auto& hint: KqpCtx.GetOptimizerHints().GetUnappliedString()) {
97+
ctx.AddWarning(YqlIssue({}, TIssuesIds::YQL_UNUSED_HINT, "Unapplied hint: " + hint));
98+
}
9799
}
98100

99101
return status;

ydb/library/yql/core/cbo/cbo_hints.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ class TOptimizerHintsParser {
4646
}
4747

4848
void JoinAlgo() {
49-
Keyword({"("});
50-
5149
i32 beginPos = Pos + 1;
50+
51+
Keyword({"("});
5252

5353
i32 labelsBeginPos = Pos + 1;
5454
TVector<TString> labels = CollectLabels();
@@ -65,7 +65,7 @@ class TOptimizerHintsParser {
6565

6666
for (const auto& [joinAlgo, joinAlgoStr]: Zip(joinAlgos, joinAlgosStr)) {
6767
if (reqJoinAlgoStr == joinAlgoStr) {
68-
Hints.JoinAlgoHints->PushBack(std::move(labels), joinAlgo, "JoinOrder" + Text.substr(beginPos, Pos - beginPos + 1));
68+
Hints.JoinAlgoHints->PushBack(std::move(labels), joinAlgo, "JoinAlgo" + Text.substr(beginPos, Pos - beginPos + 1));
6969
return;
7070
}
7171
}

ydb/library/yql/core/cbo/cbo_optimizer_new.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ struct TCardinalityHints {
101101
struct TJoinAlgoHints {
102102
struct TJoinAlgoHint {
103103
TVector<TString> JoinLabels;
104-
EJoinAlgoType JoinHint;
104+
EJoinAlgoType Algo;
105105
TString StringRepr;
106106
bool Applied = false;
107107
};
108108

109109
TVector<TJoinAlgoHint> Hints;
110110

111-
void PushBack(TVector<TString> labels, EJoinAlgoType joinHint, TString stringRepr) {
112-
Hints.push_back({.JoinLabels = std::move(labels), .JoinHint = joinHint, .StringRepr = std::move(stringRepr)});
111+
void PushBack(TVector<TString> labels, EJoinAlgoType algo, TString stringRepr) {
112+
Hints.push_back({.JoinLabels = std::move(labels), .Algo = algo, .StringRepr = std::move(stringRepr)});
113113
}
114114
};
115115

ydb/library/yql/dq/opt/dq_opt_dphyp_solver.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -420,19 +420,20 @@ template <typename TNodeSet> std::shared_ptr<TJoinOptimizerNodeInternal> TDPHypS
420420
const TVector<TString>& rightJoinKeys,
421421
IProviderContext& ctx,
422422
TCardinalityHints::TCardinalityHint* maybeCardHint,
423-
TJoinAlgoHints::TJoinAlgoHint* maybeJoinHint
423+
TJoinAlgoHints::TJoinAlgoHint* maybeJoinAlgoHint
424424
) {
425+
if (maybeJoinAlgoHint) {
426+
maybeJoinAlgoHint->Applied = true;
427+
return MakeJoinInternal(left, right, joinConditions, leftJoinKeys, rightJoinKeys, joinKind, maybeJoinAlgoHint->Algo, leftAny, rightAny, ctx, maybeCardHint);
428+
}
429+
425430
double bestCost = std::numeric_limits<double>::infinity();
426431
EJoinAlgoType bestAlgo = EJoinAlgoType::Undefined;
427432
bool bestJoinIsReversed = false;
428433

429434
for (auto joinAlgo : AllJoinAlgos) {
430435
if (ctx.IsJoinApplicable(left, right, joinConditions, leftJoinKeys, rightJoinKeys, joinAlgo, joinKind)){
431436
auto cost = ctx.ComputeJoinStats(*left->Stats, *right->Stats, leftJoinKeys, rightJoinKeys, joinAlgo, joinKind, maybeCardHint).Cost;
432-
if (maybeJoinHint && joinAlgo == maybeJoinHint->JoinHint) {
433-
cost = -1;
434-
maybeJoinHint->Applied = true;
435-
}
436437
if (cost < bestCost) {
437438
bestCost = cost;
438439
bestAlgo = joinAlgo;
@@ -443,10 +444,6 @@ template <typename TNodeSet> std::shared_ptr<TJoinOptimizerNodeInternal> TDPHypS
443444
if (isCommutative) {
444445
if (ctx.IsJoinApplicable(right, left, reversedJoinConditions, rightJoinKeys, leftJoinKeys, joinAlgo, joinKind)){
445446
auto cost = ctx.ComputeJoinStats(*right->Stats, *left->Stats, rightJoinKeys, leftJoinKeys, joinAlgo, joinKind, maybeCardHint).Cost;
446-
if (maybeJoinHint && joinAlgo == maybeJoinHint->JoinHint) {
447-
cost = -1;
448-
maybeJoinHint->Applied = true;
449-
}
450447
if (cost < bestCost) {
451448
bestCost = cost;
452449
bestAlgo = joinAlgo;

0 commit comments

Comments
 (0)