Skip to content

Commit

Permalink
Fixed CBO Level 1 and Level 2 (#12321)
Browse files Browse the repository at this point in the history
Co-authored-by: Hor911 <hor911@ydb.tech>
  • Loading branch information
pavelvelikhov and Hor911 authored Dec 5, 2024
1 parent d91df89 commit b2203a9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ydb/library/yql/dq/opt/dq_cbo_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void _DqOptimizeEquiJoinWithCosts(const std::function<IOptimizerNew*()>& optFact
auto rel = std::make_shared<TRelOptimizerNode>(TString(label), stats);
rels.push_back(rel);
};
auto res = DqOptimizeEquiJoinWithCosts(equiJoin, ctx, typeCtx, 1, *opt, providerCollect);
auto res = DqOptimizeEquiJoinWithCosts(equiJoin, ctx, typeCtx, 2, *opt, providerCollect);
UNIT_ASSERT(equiJoin.Ptr() != res.Ptr());
UNIT_ASSERT(equiJoin.Ptr()->ChildrenSize() == res.Ptr()->ChildrenSize());
UNIT_ASSERT(equiJoin.Maybe<TCoEquiJoin>());
Expand Down
2 changes: 1 addition & 1 deletion ydb/library/yql/dq/opt/dq_opt_join_cost_based.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ TExprBase DqOptimizeEquiJoinWithCosts(
int& equiJoinCounter,
const TOptimizerHints& hints
) {
if (optLevel == 0) {
if (optLevel <= 1) {
return node;
}

Expand Down
7 changes: 5 additions & 2 deletions ydb/library/yql/dq/opt/dq_opt_stat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,10 @@ void InferStatisticsForAsList(const TExprNode::TPtr& input, TTypeAnnotationConte
if (input->ChildrenSize() && input->Child(0)->IsCallable("AsStruct")) {
nAttrs = input->Child(0)->ChildrenSize();
}
typeCtx->SetStats(input.Get(), std::make_shared<TOptimizerStatistics>(
EStatisticsType::BaseTable, nRows, nAttrs, nRows*nAttrs, 0.0));
auto outputStats = std::make_shared<TOptimizerStatistics>(
EStatisticsType::BaseTable, nRows, nAttrs, nRows*nAttrs, 0.0);
outputStats->StorageType = EStorageType::RowStorage;
typeCtx->SetStats(input.Get(), outputStats);
}

/***
Expand All @@ -580,6 +582,7 @@ bool InferStatisticsForListParam(const TExprNode::TPtr& input, TTypeAnnotationCo
int nRows = 100;
int nAttrs = maybeStructType.Cast().Ptr()->ChildrenSize();
auto resStats = std::make_shared<TOptimizerStatistics>(EStatisticsType::BaseTable, nRows, nAttrs, nRows*nAttrs, 0.0);
resStats->StorageType = EStorageType::RowStorage;
typeCtx->SetStats(input.Get(), resStats);
}
}
Expand Down
2 changes: 1 addition & 1 deletion ydb/library/yql/providers/dq/opt/logical_optimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class TDqsLogicalOptProposalTransformer : public TOptimizeTransformerBase {
rels.push_back(rel);
};

return DqOptimizeEquiJoinWithCosts(node, ctx, TypesCtx, 1, *opt, providerCollect);
return DqOptimizeEquiJoinWithCosts(node, ctx, TypesCtx, 2, *opt, providerCollect);
} else {
return node;
}
Expand Down

0 comments on commit b2203a9

Please sign in to comment.