You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-11-03 17:13:17 +03:00
feat(rbo,rules): change rule matching part
This commit is contained in:
@@ -118,6 +118,7 @@ typedef std::tr1::unordered_map<TABLE_LIST*, uint> TableOuterJoinMap;
|
|||||||
using ColumnName = std::string;
|
using ColumnName = std::string;
|
||||||
using ColumnStatisticsMap = std::unordered_map<ColumnName, Histogram_json_hb>;
|
using ColumnStatisticsMap = std::unordered_map<ColumnName, Histogram_json_hb>;
|
||||||
using TableStatisticsMap = std::unordered_map<SchemaAndTableName, ColumnStatisticsMap, SchemaAndTableNameHash>;
|
using TableStatisticsMap = std::unordered_map<SchemaAndTableName, ColumnStatisticsMap, SchemaAndTableNameHash>;
|
||||||
|
using TableAliasMap = std::unordered_map<SchemaAndTableName, std::string, SchemaAndTableNameHash>;
|
||||||
|
|
||||||
// This structure is used to store MDB AST -> CSEP translation context.
|
// This structure is used to store MDB AST -> CSEP translation context.
|
||||||
// There is a column statistics for some columns in a query.
|
// There is a column statistics for some columns in a query.
|
||||||
|
|||||||
@@ -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)
|
bool parallelCESFilter(execplan::CalpontSelectExecutionPlan& csep)
|
||||||
{
|
{
|
||||||
auto tables = csep.tableList();
|
auto tables = csep.tableList();
|
||||||
// This is leaf and there are no other tables at this level in neither UNION, nor derived table.
|
// 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
|
// TODO filter out CSEPs with orderBy, groupBy, having
|
||||||
// Filter out tables that were re-written.
|
// 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)
|
// 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();
|
auto tables = csep.tableList();
|
||||||
execplan::CalpontSelectExecutionPlan::TableList newTableList;
|
execplan::CalpontSelectExecutionPlan::TableList newTableList;
|
||||||
execplan::CalpontSelectExecutionPlan::SelectList newDerivedTableList;
|
execplan::CalpontSelectExecutionPlan::SelectList newDerivedTableList;
|
||||||
execplan::CalpontSelectExecutionPlan::ReturnedColumnList newReturnedColumns;
|
cal_impl_if::TableAliasMap tableAliasMap;
|
||||||
bool ruleHasBeenApplied = false;
|
bool ruleHasBeenApplied = false;
|
||||||
|
|
||||||
// ATM Must be only 1 table
|
// ATM Must be only 1 table
|
||||||
@@ -215,7 +222,8 @@ bool applyParallelCES(execplan::CalpontSelectExecutionPlan& csep, RBOptimizerCon
|
|||||||
// need to add a level here
|
// need to add a level here
|
||||||
std::string tableAlias = RewrittenSubTableAliasPrefix + table.schema + "_" + table.table + "_" +
|
std::string tableAlias = RewrittenSubTableAliasPrefix + table.schema + "_" + table.table + "_" +
|
||||||
std::to_string(ctx.uniqueId);
|
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->location(execplan::CalpontSelectExecutionPlan::FROM);
|
||||||
derivedSCEP->subType(execplan::CalpontSelectExecutionPlan::FROM_SUBS);
|
derivedSCEP->subType(execplan::CalpontSelectExecutionPlan::FROM_SUBS);
|
||||||
derivedSCEP->derivedTbAlias(tableAlias);
|
derivedSCEP->derivedTbAlias(tableAlias);
|
||||||
@@ -225,21 +233,7 @@ bool applyParallelCES(execplan::CalpontSelectExecutionPlan& csep, RBOptimizerCon
|
|||||||
derivedSCEP->unionVec().insert(derivedSCEP->unionVec().end(), additionalUnionVec.begin(),
|
derivedSCEP->unionVec().insert(derivedSCEP->unionVec().end(), additionalUnionVec.begin(),
|
||||||
additionalUnionVec.end());
|
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);
|
newDerivedTableList.push_back(derivedSCEP);
|
||||||
execplan::CalpontSystemCatalog::TableAliasName tn = execplan::make_aliasview("", "", tableAlias, "");
|
execplan::CalpontSystemCatalog::TableAliasName tn = execplan::make_aliasview("", "", tableAlias, "");
|
||||||
@@ -250,6 +244,44 @@ bool applyParallelCES(execplan::CalpontSelectExecutionPlan& csep, RBOptimizerCon
|
|||||||
ruleHasBeenApplied = true;
|
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
|
// 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
|
// 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
|
// There must be no derived at this point, so we can replace it with the new derived table list
|
||||||
|
|||||||
Reference in New Issue
Block a user