Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ydb/core/kqp/opt/logical/kqp_opt_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions ydb/library/yql/core/cbo/cbo_hints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class TOptimizerHintsParser {
}

void JoinAlgo() {
Keyword({"("});

i32 beginPos = Pos + 1;

Keyword({"("});

i32 labelsBeginPos = Pos + 1;
TVector<TString> labels = CollectLabels();
Expand All @@ -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;
}
}
Expand Down
6 changes: 3 additions & 3 deletions ydb/library/yql/core/cbo/cbo_optimizer_new.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)});
}
};

Expand Down
15 changes: 6 additions & 9 deletions ydb/library/yql/dq/opt/dq_opt_dphyp_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,19 +420,20 @@ 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;

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;
Expand All @@ -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;
Expand Down