1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-08 14:22:09 +03:00

feat(optimizer): temporary shield optimizer with a session variable

This commit is contained in:
drrtuy
2025-06-16 16:37:03 +00:00
parent 98cb6dddee
commit e57832ee64
5 changed files with 59 additions and 58 deletions

View File

@@ -9209,7 +9209,7 @@ int cs_get_derived_plan(ha_columnstore_derived_handler* handler, THD* /*thd*/, S
}
int cs_get_select_plan(ha_columnstore_select_handler* handler, THD* /*thd*/, SCSEP& csep, gp_walk_info& gwi,
int cs_get_select_plan(ha_columnstore_select_handler* handler, THD* thd, SCSEP& csep, gp_walk_info& gwi,
bool isSelectLexUnit)
{
SELECT_LEX& select_lex = handler->select_lex ? *handler->select_lex : *handler->lex_unit->first_select();
@@ -9241,12 +9241,15 @@ int cs_get_select_plan(ha_columnstore_select_handler* handler, THD* /*thd*/, SCS
// Derived table projection and filter optimization.
derivedTableOptimization(&gwi, csep);
bool csepWasOptimized = optimizer::optimizeCSEP(*csep);
if (csep->traceOn() && csepWasOptimized)
if (get_unstable_optimizer(thd))
{
cerr << "---------------- cs_get_select_plan optimized EXECUTION PLAN ----------------" << endl;
cerr << *csep << endl;
cerr << "-------------- EXECUTION PLAN END --------------\n" << endl;
bool csepWasOptimized = optimizer::optimizeCSEP(*csep);
if (csep->traceOn() && csepWasOptimized)
{
cerr << "---------------- cs_get_select_plan optimized EXECUTION PLAN ----------------" << endl;
cerr << *csep << endl;
cerr << "-------------- EXECUTION PLAN END --------------\n" << endl;
}
}
return 0;

View File

@@ -269,6 +269,7 @@ st_mysql_sys_var* mcs_system_variables[] = {
MYSQL_SYSVAR(pron),
MYSQL_SYSVAR(max_allowed_in_values),
MYSQL_SYSVAR(innodb_queries_use_mcs),
MYSQL_SYSVAR(unstable_optimizer),
NULL};
st_mysql_show_var mcs_status_variables[] = {{"columnstore_version", (char*)&cs_version, SHOW_CHAR},

View File

@@ -175,4 +175,7 @@ const char* get_pron(THD* thd);
void set_pron(THD* thd, char* value);
ulong get_max_allowed_in_values(THD* thd);
void set_max_allowed_in_values(THD* thd, ulong value);
void set_max_allowed_in_values(THD* thd, ulong value);
bool get_unstable_optimizer(THD* thd);
void set_unstable_optimizer(THD* thd, bool value);

View File

@@ -110,7 +110,7 @@ bool tableIsInUnion(const execplan::CalpontSystemCatalog::TableAliasName& table,
bool matchParallelCES(execplan::CalpontSelectExecutionPlan& csep)
{
auto tables = csep.tableList();
// This is leaf and there are no other tables at this level.
// This is leaf and there are no other tables at this level in neither UNION, nor derived table.
// WIP filter out CSEPs with orderBy, groupBy, having
// WIP filter out CSEPs with nonSimpleColumns in projection
return tables.size() == 1 && !tables[0].isColumnstore() && !tableIsInUnion(tables[0], csep);
@@ -142,13 +142,14 @@ void applyParallelCES(execplan::CalpontSelectExecutionPlan& csep)
if (!table.isColumnstore())
{
auto derivedSCEP = csep.cloneWORecursiveSelects();
// need to intro a level
// need to add a level here
std::string alias = aliasPrefix + table.schema + "_" + table.table;
derivedSCEP->location(execplan::CalpontSelectExecutionPlan::FROM);
derivedSCEP->subType(execplan::CalpontSelectExecutionPlan::FROM_SUBS);
derivedSCEP->derivedTbAlias(alias);
// TODO: hardcoded for now
size_t parallelFactor = 2;
auto additionalUnionVec = makeUnionFromTable(parallelFactor, csep);
derivedSCEP->unionVec().insert(derivedSCEP->unionVec().end(), additionalUnionVec.begin(), additionalUnionVec.end());
@@ -166,23 +167,15 @@ void applyParallelCES(execplan::CalpontSelectExecutionPlan& csep)
}
}
// WIP need to work with existing derived tables
newDerivedTableList.push_back(derivedSCEP);
// WIP
execplan::CalpontSystemCatalog::TableAliasName tn = execplan::make_aliasview("", "", alias, "");
newTableList.push_back(tn);
}
}
// SimpleColumn* sc = new SimpleColumn("test", "i1", "i", false, csep.sessionID());
// string alias(table->alias.c_ptr());
// sc->timeZone(csep.timeZone());
// sc->partitions(getPartitions(table));
// boost::shared_ptr<SimpleColumn> spsc(sc);
// csep.columnMap().insert({"`test`.`i1`.`i`", spsc});
// There must be no derived at this point.
csep.derivedTableList(newDerivedTableList);
// Replace table list with new table list populated with union units
csep.tableList(newTableList);
}
}