You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-08-01 06:46:55 +03:00
feat(optimizer): add session switch to optionally enable optimizer
This commit is contained in:
@ -9197,11 +9197,12 @@ int cs_get_derived_plan(ha_columnstore_derived_handler* handler, THD* /*thd*/, S
|
|||||||
else if (status < 0)
|
else if (status < 0)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
#ifdef DEBUG_WALK_COND
|
if (csep->traceOn())
|
||||||
cerr << "---------------- cs_get_derived_plan EXECUTION PLAN ----------------" << endl;
|
{
|
||||||
cerr << *csep << endl;
|
cerr << "---------------- cs_get_derived_plan EXECUTION PLAN ----------------" << endl;
|
||||||
cerr << "-------------- EXECUTION PLAN END --------------\n" << endl;
|
cerr << *csep << endl;
|
||||||
#endif
|
cerr << "-------------- EXECUTION PLAN END --------------\n" << endl;
|
||||||
|
}
|
||||||
// Derived table projection and filter optimization.
|
// Derived table projection and filter optimization.
|
||||||
derivedTableOptimization(&gwi, csep);
|
derivedTableOptimization(&gwi, csep);
|
||||||
return 0;
|
return 0;
|
||||||
@ -9230,25 +9231,24 @@ int cs_get_select_plan(ha_columnstore_select_handler* handler, THD* /*thd*/, SCS
|
|||||||
else if (status < 0)
|
else if (status < 0)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
// #ifdef DEBUG_WALK_COND
|
if (csep->traceOn())
|
||||||
cerr << "---------------- cs_get_select_plan EXECUTION PLAN ----------------" << endl;
|
{
|
||||||
cerr << *csep << endl;
|
cerr << "---------------- cs_get_select_plan EXECUTION PLAN ----------------" << endl;
|
||||||
cerr << "-------------- EXECUTION PLAN END --------------\n" << endl;
|
cerr << *csep << endl;
|
||||||
// #endif
|
cerr << "-------------- EXECUTION PLAN END --------------\n" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
// Derived table projection and filter optimization.
|
// Derived table projection and filter optimization.
|
||||||
derivedTableOptimization(&gwi, csep);
|
derivedTableOptimization(&gwi, csep);
|
||||||
|
|
||||||
optimizer::Rule parallelCES{"parallelCES", optimizer::matchParallelCES, optimizer::applyParallelCES};
|
bool csepWasOptimized = optimizer::optimizeCSEP(*csep);
|
||||||
|
if (csep->traceOn() && csepWasOptimized)
|
||||||
{
|
{
|
||||||
parallelCES.apply(*csep);
|
cerr << "---------------- cs_get_select_plan optimized EXECUTION PLAN ----------------" << endl;
|
||||||
|
cerr << *csep << endl;
|
||||||
|
cerr << "-------------- EXECUTION PLAN END --------------\n" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
cerr << "---------------- cs_get_select_plan rewritten EXECUTION PLAN ----------------" << endl;
|
|
||||||
cerr << *csep << endl;
|
|
||||||
cerr << "-------------- EXECUTION PLAN END --------------\n" << endl;
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,7 +224,9 @@ static my_bool innodb_queries_use_mcs;
|
|||||||
static MYSQL_SYSVAR_BOOL(innodb_queries_use_mcs, innodb_queries_use_mcs,
|
static MYSQL_SYSVAR_BOOL(innodb_queries_use_mcs, innodb_queries_use_mcs,
|
||||||
PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY,
|
PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY,
|
||||||
"Direct all InnoDB-only queries into MCS via Select Handler.", NULL, NULL, FALSE);
|
"Direct all InnoDB-only queries into MCS via Select Handler.", NULL, NULL, FALSE);
|
||||||
|
static MYSQL_THDVAR_BOOL(unstable_optimizer, PLUGIN_VAR_RQCMDARG,
|
||||||
|
"Apply optimizer rules after translation from SELECT_LEX/UNION", NULL, NULL, FALSE);
|
||||||
|
|
||||||
st_mysql_sys_var* mcs_system_variables[] = {
|
st_mysql_sys_var* mcs_system_variables[] = {
|
||||||
MYSQL_SYSVAR(compression_type),
|
MYSQL_SYSVAR(compression_type),
|
||||||
MYSQL_SYSVAR(fe_conn_info_ptr),
|
MYSQL_SYSVAR(fe_conn_info_ptr),
|
||||||
@ -663,6 +665,15 @@ void set_max_allowed_in_values(THD* thd, ulong value)
|
|||||||
THDVAR(thd, max_allowed_in_values) = value;
|
THDVAR(thd, max_allowed_in_values) = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool get_unstable_optimizer(THD* thd)
|
||||||
|
{
|
||||||
|
return (thd == NULL) ? 0 : THDVAR(thd, unstable_optimizer);
|
||||||
|
}
|
||||||
|
void set_unstable_optimizer(THD* thd, bool value)
|
||||||
|
{
|
||||||
|
THDVAR(thd, unstable_optimizer) = value;
|
||||||
|
}
|
||||||
|
|
||||||
bool get_innodb_queries_uses_mcs()
|
bool get_innodb_queries_uses_mcs()
|
||||||
{
|
{
|
||||||
return SYSVAR(innodb_queries_use_mcs);
|
return SYSVAR(innodb_queries_use_mcs);
|
||||||
|
@ -21,36 +21,52 @@
|
|||||||
|
|
||||||
namespace optimizer {
|
namespace optimizer {
|
||||||
|
|
||||||
bool Rule::apply(execplan::CalpontSelectExecutionPlan& csep)
|
bool optimizeCSEPWithRules(execplan::CalpontSelectExecutionPlan& root, const std::vector<Rule>& rules) {
|
||||||
|
|
||||||
|
bool changed = false;
|
||||||
|
for (const auto& rule : rules)
|
||||||
|
{
|
||||||
|
changed |= rule.apply(root);
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool optimizeCSEP(execplan::CalpontSelectExecutionPlan& root)
|
||||||
|
{
|
||||||
|
optimizer::Rule parallelCES{"parallelCES", optimizer::matchParallelCES, optimizer::applyParallelCES};
|
||||||
|
|
||||||
|
std::vector<Rule> rules = {parallelCES};
|
||||||
|
|
||||||
|
return optimizeCSEPWithRules(root, rules);
|
||||||
|
}
|
||||||
|
|
||||||
|
// DFS walk
|
||||||
|
bool Rule::apply(execplan::CalpontSelectExecutionPlan& csep) const
|
||||||
{
|
{
|
||||||
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* csepPtr = dynamic_cast<execplan::CalpontSelectExecutionPlan*>(table.get());
|
||||||
if (matchRule(csepLocal))
|
if (!csepPtr)
|
||||||
{
|
{
|
||||||
applyRule(csepLocal);
|
continue;
|
||||||
rewrite = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rewrite |= apply(csepLocal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto& csepLocal = *csepPtr;
|
||||||
|
rewrite |= apply(csepLocal);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& unionUnit : csep.unionVec())
|
for (auto& unionUnit : csep.unionVec())
|
||||||
{
|
{
|
||||||
auto& unionUnitLocal = *dynamic_cast<execplan::CalpontSelectExecutionPlan*>(unionUnit.get());
|
auto* unionUnitPtr = dynamic_cast<execplan::CalpontSelectExecutionPlan*>(unionUnit.get());
|
||||||
|
if (!unionUnitPtr)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (matchRule(unionUnitLocal))
|
auto& unionUnitLocal = *unionUnitPtr;
|
||||||
{
|
rewrite |= apply(unionUnitLocal);
|
||||||
applyRule(unionUnitLocal);
|
|
||||||
rewrite = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rewrite |= apply(unionUnitLocal);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matchRule(csep))
|
if (matchRule(csep))
|
||||||
|
@ -31,10 +31,11 @@ struct Rule
|
|||||||
std::string name;
|
std::string name;
|
||||||
bool (*matchRule)(execplan::CalpontSelectExecutionPlan&);
|
bool (*matchRule)(execplan::CalpontSelectExecutionPlan&);
|
||||||
void (*applyRule)(execplan::CalpontSelectExecutionPlan&);
|
void (*applyRule)(execplan::CalpontSelectExecutionPlan&);
|
||||||
bool apply(execplan::CalpontSelectExecutionPlan& csep);
|
bool apply(execplan::CalpontSelectExecutionPlan& csep) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool matchParallelCES(execplan::CalpontSelectExecutionPlan& csep);
|
bool matchParallelCES(execplan::CalpontSelectExecutionPlan& csep);
|
||||||
void applyParallelCES(execplan::CalpontSelectExecutionPlan& csep);
|
void applyParallelCES(execplan::CalpontSelectExecutionPlan& csep);
|
||||||
|
bool optimizeCSEP(execplan::CalpontSelectExecutionPlan& root);
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user