diff --git a/dbcon/mysql/ha_mcs_impl_if.h b/dbcon/mysql/ha_mcs_impl_if.h index aed13d202..6baa7fd74 100644 --- a/dbcon/mysql/ha_mcs_impl_if.h +++ b/dbcon/mysql/ha_mcs_impl_if.h @@ -118,6 +118,7 @@ typedef std::tr1::unordered_map TableOuterJoinMap; using ColumnName = std::string; using ColumnStatisticsMap = std::unordered_map; using TableStatisticsMap = std::unordered_map; +using TableAliasMap = std::unordered_map; // This structure is used to store MDB AST -> CSEP translation context. // There is a column statistics for some columns in a query. diff --git a/dbcon/mysql/rbo_apply_parallel_ces.cpp b/dbcon/mysql/rbo_apply_parallel_ces.cpp index 14b9c22bd..b9accfb3b 100644 --- a/dbcon/mysql/rbo_apply_parallel_ces.cpp +++ b/dbcon/mysql/rbo_apply_parallel_ces.cpp @@ -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(*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(*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(*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