You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-30 19:23:07 +03:00
feat(optimizer): rewrite rule refactoring
This commit is contained in:
@ -9241,7 +9241,7 @@ CalpontSelectExecutionPlan::SelectList makeUnionFromTable(const size_t numberOfL
|
|||||||
unionVec.reserve(numberOfLegs);
|
unionVec.reserve(numberOfLegs);
|
||||||
for (size_t i = 0; i < numberOfLegs; ++i)
|
for (size_t i = 0; i < numberOfLegs; ++i)
|
||||||
{
|
{
|
||||||
unionVec.emplace_back(csep.cloneWORecursiveSelects());
|
unionVec.push_back(csep.cloneWORecursiveSelects());
|
||||||
}
|
}
|
||||||
|
|
||||||
return unionVec;
|
return unionVec;
|
||||||
@ -9249,9 +9249,6 @@ CalpontSelectExecutionPlan::SelectList makeUnionFromTable(const size_t numberOfL
|
|||||||
|
|
||||||
void applyParallelCES(CalpontSelectExecutionPlan& csep)
|
void applyParallelCES(CalpontSelectExecutionPlan& csep)
|
||||||
{
|
{
|
||||||
std::cout << "applyParallelCES" << std::endl;
|
|
||||||
std::cout << "original unionVec size " << csep.unionVec().size() << std::endl;
|
|
||||||
|
|
||||||
auto tables = csep.tableList();
|
auto tables = csep.tableList();
|
||||||
for (auto it = tables.begin(); it != tables.end(); ++it)
|
for (auto it = tables.begin(); it != tables.end(); ++it)
|
||||||
{
|
{
|
||||||
@ -9262,53 +9259,49 @@ void applyParallelCES(CalpontSelectExecutionPlan& csep)
|
|||||||
csep.unionVec().insert(csep.unionVec().end(), additionalUnionVec.begin(), additionalUnionVec.end());
|
csep.unionVec().insert(csep.unionVec().end(), additionalUnionVec.begin(), additionalUnionVec.end());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "modified CSEP" << std::endl;
|
|
||||||
std::cout << "unionVec size " << csep.unionVec().size() << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Rule
|
struct Rule
|
||||||
{
|
{
|
||||||
Rule(std::string&& name, bool (*match)(CalpontSelectExecutionPlan&),
|
Rule(std::string&& name, bool (*matchRule)(CalpontSelectExecutionPlan&),
|
||||||
void (*apply)(CalpontSelectExecutionPlan&))
|
void (*applyRule)(CalpontSelectExecutionPlan&))
|
||||||
: name(name), match(match), apply(apply) {};
|
: name(name), matchRule(matchRule), applyRule(applyRule) {};
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
bool (*match)(CalpontSelectExecutionPlan&);
|
bool (*matchRule)(CalpontSelectExecutionPlan&);
|
||||||
void (*apply)(CalpontSelectExecutionPlan&);
|
void (*applyRule)(CalpontSelectExecutionPlan&);
|
||||||
bool walk(CalpontSelectExecutionPlan& csep)
|
bool apply(CalpontSelectExecutionPlan& csep)
|
||||||
{
|
{
|
||||||
bool rewrite = false;
|
bool rewrite = false;
|
||||||
for (auto& table : csep.derivedTableList())
|
for (auto& table : csep.derivedTableList())
|
||||||
{
|
{
|
||||||
auto csepLocal = *dynamic_cast<execplan::CalpontSelectExecutionPlan*>(table.get());
|
auto& csepLocal = *dynamic_cast<execplan::CalpontSelectExecutionPlan*>(table.get());
|
||||||
if (match(csepLocal))
|
if (matchRule(csepLocal))
|
||||||
{
|
{
|
||||||
apply(csepLocal);
|
applyRule(csepLocal);
|
||||||
rewrite = true;
|
rewrite = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rewrite |= walk(csepLocal);
|
rewrite |= apply(csepLocal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& unionUnit : csep.unionVec())
|
for (auto& unionUnit : csep.unionVec())
|
||||||
{
|
{
|
||||||
auto unionUnitLocal = *dynamic_cast<execplan::CalpontSelectExecutionPlan*>(unionUnit.get());
|
auto& unionUnitLocal = *dynamic_cast<execplan::CalpontSelectExecutionPlan*>(unionUnit.get());
|
||||||
|
|
||||||
if (match(unionUnitLocal))
|
if (matchRule(unionUnitLocal))
|
||||||
{
|
{
|
||||||
apply(unionUnitLocal);
|
applyRule(unionUnitLocal);
|
||||||
rewrite = true;
|
rewrite = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rewrite |= walk(unionUnitLocal);
|
rewrite |= apply(unionUnitLocal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (match(csep))
|
if (matchRule(csep))
|
||||||
{
|
{
|
||||||
apply(csep);
|
apply(csep);
|
||||||
rewrite = true;
|
rewrite = true;
|
||||||
@ -9341,9 +9334,9 @@ int cs_get_select_plan(ha_columnstore_select_handler* handler, THD* /*thd*/, SCS
|
|||||||
return status;
|
return status;
|
||||||
|
|
||||||
#ifdef DEBUG_WALK_COND
|
#ifdef DEBUG_WALK_COND
|
||||||
cerr << "---------------- cs_get_select_plan EXECUTION PLAN ----------------" << endl;
|
// cerr << "---------------- cs_get_select_plan EXECUTION PLAN ----------------" << endl;
|
||||||
cerr << *csep << endl;
|
// cerr << *csep << endl;
|
||||||
cerr << "-------------- EXECUTION PLAN END --------------\n" << endl;
|
// cerr << "-------------- EXECUTION PLAN END --------------\n" << endl;
|
||||||
#endif
|
#endif
|
||||||
// Derived table projection and filter optimization.
|
// Derived table projection and filter optimization.
|
||||||
derivedTableOptimization(&gwi, csep);
|
derivedTableOptimization(&gwi, csep);
|
||||||
@ -9359,9 +9352,14 @@ int cs_get_select_plan(ha_columnstore_select_handler* handler, THD* /*thd*/, SCS
|
|||||||
Rule parallelCES{"parallelCES", matchParallelCES, applyParallelCES};
|
Rule parallelCES{"parallelCES", matchParallelCES, applyParallelCES};
|
||||||
|
|
||||||
{
|
{
|
||||||
parallelCES.walk(*csep);
|
parallelCES.apply(*csep);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cerr << "---------------- cs_get_select_plan rewritten EXECUTION PLAN ----------------" << endl;
|
||||||
|
cerr << *csep << endl;
|
||||||
|
cerr << "-------------- EXECUTION PLAN END --------------\n" << endl;
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user