1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-11-02 06:13:16 +03:00

feat(rbo,rules): change rule matching part

This commit is contained in:
drrtuy
2025-07-21 19:22:41 +00:00
parent 578c2b1db1
commit 595b1baad2
2 changed files with 50 additions and 17 deletions

View File

@@ -54,13 +54,20 @@ bool tableIsInUnion(const execplan::CalpontSystemCatalog::TableAliasName& table,
});
}
bool someAreForeignTables(execplan::CalpontSelectExecutionPlan& csep)
{
return std::any_of(csep.tableList().begin(), csep.tableList().end(),
[](const auto& table) { return !table.isColumnstore(); });
}
bool parallelCESFilter(execplan::CalpontSelectExecutionPlan& csep)
{
auto tables = csep.tableList();
// This is leaf and there are no other tables at this level in neither UNION, nor derived table.
// TODO filter out CSEPs with orderBy, groupBy, having
// Filter out tables that were re-written.
return tables.size() == 1 && !tables[0].isColumnstore() && !tableIsInUnion(tables[0], csep);
// return tables.size() == 1 && !tables[0].isColumnstore() && !tableIsInUnion(tables[0], csep);
return someAreForeignTables(csep);
}
// This routine produces a new ParseTree that is AND(lowerBand <= column, column <= upperBand)
@@ -203,7 +210,7 @@ bool applyParallelCES(execplan::CalpontSelectExecutionPlan& csep, RBOptimizerCon
auto tables = csep.tableList();
execplan::CalpontSelectExecutionPlan::TableList newTableList;
execplan::CalpontSelectExecutionPlan::SelectList newDerivedTableList;
execplan::CalpontSelectExecutionPlan::ReturnedColumnList newReturnedColumns;
cal_impl_if::TableAliasMap tableAliasMap;
bool ruleHasBeenApplied = false;
// ATM Must be only 1 table
@@ -215,7 +222,8 @@ bool applyParallelCES(execplan::CalpontSelectExecutionPlan& csep, RBOptimizerCon
// need to add a level here
std::string tableAlias = RewrittenSubTableAliasPrefix + table.schema + "_" + table.table + "_" +
std::to_string(ctx.uniqueId);
// TODO add original alias to support multiple same name tables
tableAliasMap.insert({{table.schema, table.table}, tableAlias});
derivedSCEP->location(execplan::CalpontSelectExecutionPlan::FROM);
derivedSCEP->subType(execplan::CalpontSelectExecutionPlan::FROM_SUBS);
derivedSCEP->derivedTbAlias(tableAlias);
@@ -225,21 +233,7 @@ bool applyParallelCES(execplan::CalpontSelectExecutionPlan& csep, RBOptimizerCon
derivedSCEP->unionVec().insert(derivedSCEP->unionVec().end(), additionalUnionVec.begin(),
additionalUnionVec.end());
size_t colPosition = 0;
// change parent to derived table columns
for (auto& rc : csep.returnedCols())
{
auto rcCloned = boost::make_shared<execplan::SimpleColumn>(*rc);
// TODO timezone and result type are not copied
// TODO add specific ctor for this functionality
rcCloned->tableName("");
rcCloned->schemaName("");
rcCloned->tableAlias(tableAlias);
rcCloned->colPosition(colPosition++);
rcCloned->resultType(rc->resultType());
newReturnedColumns.push_back(rcCloned);
}
newDerivedTableList.push_back(derivedSCEP);
execplan::CalpontSystemCatalog::TableAliasName tn = execplan::make_aliasview("", "", tableAlias, "");
@@ -250,6 +244,44 @@ bool applyParallelCES(execplan::CalpontSelectExecutionPlan& csep, RBOptimizerCon
ruleHasBeenApplied = true;
}
}
execplan::CalpontSelectExecutionPlan::ReturnedColumnList newReturnedColumns;
size_t colPosition = 0;
// change parent to derived table columns using ScheamAndTableName -> tableAlias map
for (auto& rc : csep.returnedCols())
{
// TODO support expressions
auto rcCloned = boost::make_shared<execplan::SimpleColumn>(*rc);
// TODO timezone and result type are not copied
// TODO add specific ctor for this functionality
auto newTableAlias = tableAliasMap.find({rc->schemaName(), rc->tableName()});
rcCloned->tableName("");
rcCloned->schemaName("");
rcCloned->tableAlias(tableAlias);
rcCloned->colPosition(colPosition++);
rcCloned->resultType(rc->resultType());
newReturnedColumns.push_back(rcCloned);
}
execplan::CalpontSelectExecutionPlan::ReturnedColumnList newReturnedColumns;
size_t colPosition = 0;
// change parent to derived table columns using ScheamAndTableName -> tableAlias map
for (auto& rc : csep.returnedCols())
{
// TODO support expressions
auto rcCloned = boost::make_shared<execplan::SimpleColumn>(*rc);
// TODO timezone and result type are not copied
// TODO add specific ctor for this functionality
auto newTableAlias = tableAliasMap.find({rc->schemaName(), rc->tableName()});
rcCloned->tableName("");
rcCloned->schemaName("");
rcCloned->tableAlias(tableAlias);
rcCloned->colPosition(colPosition++);
rcCloned->resultType(rc->resultType());
newReturnedColumns.push_back(rcCloned);
}
// Remove the filters if necessary using csep.filters(nullptr) as they were pushed down to union units
// But this is inappropriate for EXISTS filter and join conditions
// There must be no derived at this point, so we can replace it with the new derived table list