1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-01 06:46:55 +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

@ -159,6 +159,9 @@ class CalpontSelectExecutionPlan : public CalpontExecutionPlan
*/ */
~CalpontSelectExecutionPlan() override; ~CalpontSelectExecutionPlan() override;
/**
* Clones this CSEP without recursive selects for optimizer purposes
*/
execplan::SCSEP cloneWORecursiveSelects(); execplan::SCSEP cloneWORecursiveSelects();
/** /**
* Access and mutator methods * Access and mutator methods

View File

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

View File

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