1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +03:00

feat(optimizer): replace simple walk with iterative DFS with convergence

This commit is contained in:
drrtuy
2025-06-16 13:59:29 +00:00
parent 25c7d23c21
commit 98cb6dddee
3 changed files with 22 additions and 3 deletions

View File

@ -21,6 +21,7 @@
namespace optimizer {
// Apply a list of rules to a CSEP
bool optimizeCSEPWithRules(execplan::CalpontSelectExecutionPlan& root, const std::vector<Rule>& rules) {
bool changed = false;
@ -31,6 +32,7 @@ bool optimizeCSEPWithRules(execplan::CalpontSelectExecutionPlan& root, const std
return changed;
}
// high level API call for optimizer
bool optimizeCSEP(execplan::CalpontSelectExecutionPlan& root)
{
optimizer::Rule parallelCES{"parallelCES", optimizer::matchParallelCES, optimizer::applyParallelCES};
@ -40,8 +42,22 @@ bool optimizeCSEP(execplan::CalpontSelectExecutionPlan& root)
return optimizeCSEPWithRules(root, rules);
}
// DFS walk
bool Rule::apply(execplan::CalpontSelectExecutionPlan& csep) const
// Apply iteratively until CSEP is converged by rule
bool Rule::apply(execplan::CalpontSelectExecutionPlan& root) const
{
bool changedThisRound = false;
bool hasBeenApplied = false;
do
{
changedThisRound = walk(root);
hasBeenApplied = changedThisRound;
} while (changedThisRound);
return hasBeenApplied;
}
// DFS walk to match CSEP and apply rules if match
bool Rule::walk(execplan::CalpontSelectExecutionPlan& csep) const
{
bool rewrite = false;
@ -78,7 +94,6 @@ bool Rule::apply(execplan::CalpontSelectExecutionPlan& csep) const
return rewrite;
}
bool tableIsInUnion(const execplan::CalpontSystemCatalog::TableAliasName& table, execplan::CalpontSelectExecutionPlan& csep)
{
return std::any_of(csep.unionVec().begin(), csep.unionVec().end(),

View File

@ -32,6 +32,7 @@ struct Rule
bool (*matchRule)(execplan::CalpontSelectExecutionPlan&);
void (*applyRule)(execplan::CalpontSelectExecutionPlan&);
bool apply(execplan::CalpontSelectExecutionPlan& csep) const;
bool walk(execplan::CalpontSelectExecutionPlan& csep) const;
};
bool matchParallelCES(execplan::CalpontSelectExecutionPlan& csep);