From bd219cc4af1aa4561f55a1d43f6c6063e8580fff Mon Sep 17 00:00:00 2001 From: drrtuy Date: Tue, 29 Jul 2025 18:53:50 +0000 Subject: [PATCH] feat(cbo,rules,QA): clean SC iface usage in various places --- dbcon/execplan/calpontselectexecutionplan.cpp | 5 +- dbcon/execplan/simplecolumn.cpp | 15 ++--- dbcon/mysql/rbo_apply_parallel_ces.cpp | 57 ++----------------- 3 files changed, 15 insertions(+), 62 deletions(-) diff --git a/dbcon/execplan/calpontselectexecutionplan.cpp b/dbcon/execplan/calpontselectexecutionplan.cpp index 9114b8cdf..8b2ea4973 100644 --- a/dbcon/execplan/calpontselectexecutionplan.cpp +++ b/dbcon/execplan/calpontselectexecutionplan.cpp @@ -1018,9 +1018,10 @@ execplan::SCSEP CalpontSelectExecutionPlan::cloneForTableWORecursiveSelects( for (const auto& rc : fReturnedCols) { rc->setSimpleColumnList(); - for (auto* sc : rc->simpleColumnList()) + for (auto* simpleColumn : rc->simpleColumnList()) { - if (targetTableAlias.weakerEq(*sc->singleTable())) + auto tableAlias = simpleColumn->singleTable(); + if (tableAlias && targetTableAlias.weakerEq(*tableAlias)) { newReturnedCols.push_back(SRCP(rc->clone())); } diff --git a/dbcon/execplan/simplecolumn.cpp b/dbcon/execplan/simplecolumn.cpp index c100638ae..c37e9fe14 100644 --- a/dbcon/execplan/simplecolumn.cpp +++ b/dbcon/execplan/simplecolumn.cpp @@ -529,7 +529,8 @@ void SimpleColumn::setDerivedTable() std::optional SimpleColumn::singleTable() { - return {CalpontSystemCatalog::TableAliasName(fSchemaName, fTableName, fTableAlias, fViewName)}; + return { + CalpontSystemCatalog::TableAliasName(fSchemaName, fTableName, fTableAlias, fViewName, fisColumnStore)}; } // @todo move to inline @@ -759,21 +760,21 @@ void SimpleColumn::setSimpleColumnList() } } -std::optional sameTableCheck(std::vector simpleColumnList) +std::optional sameTableCheck( + std::vector simpleColumnList) { std::optional tan; for (SimpleColumn* simpleColumn : simpleColumnList) { - CalpontSystemCatalog::TableAliasName stan( - simpleColumn->schemaName(), simpleColumn->tableName(), - simpleColumn->tableAlias(), simpleColumn->viewName()); - + CalpontSystemCatalog::TableAliasName stan(simpleColumn->schemaName(), simpleColumn->tableName(), + simpleColumn->tableAlias(), simpleColumn->viewName()); + if (!tan.has_value()) tan = stan; else if (stan != tan) return std::nullopt; } - + return tan; } diff --git a/dbcon/mysql/rbo_apply_parallel_ces.cpp b/dbcon/mysql/rbo_apply_parallel_ces.cpp index e50738ae0..6cb5d7638 100644 --- a/dbcon/mysql/rbo_apply_parallel_ces.cpp +++ b/dbcon/mysql/rbo_apply_parallel_ces.cpp @@ -201,6 +201,7 @@ std::optional> populateRangeBounds(execplan::SimpleColumn* FilterRangeBounds bounds; // Loop over buckets to produce filter ranges + // NB Currently Histogram_json_hb has the last bucket that has end as its start for (size_t i = 0; i < numberOfUnionUnits - 1; ++i) { auto bucket = columnStatistics.get_json_histogram().begin() + i * numberOfBucketsPerUnionUnit; @@ -210,15 +211,6 @@ std::optional> populateRangeBounds(execplan::SimpleColumn* bounds.push_back({currentLowerBound, currentUpperBound}); } - // Add last range - // NB despite the fact that currently Histogram_json_hb has the last bucket that has end as its start - // auto lastBucket = - // columnStatistics.get_json_histogram().begin() + (numberOfUnionUnits - 1) * - // numberOfBucketsPerUnionUnit; - // T currentLowerBound = *(uint32_t*)lastBucket->start_value.data(); - // T currentUpperBound = *(uint32_t*)columnStatistics.get_last_bucket_end_endp().data(); - // bounds.push_back({currentLowerBound, currentUpperBound}); - for (auto& bound : bounds) { std::cout << "Bound: " << bound.first << " " << bound.second << std::endl; @@ -351,9 +343,6 @@ bool applyParallelCES(execplan::CalpontSelectExecutionPlan& csep, RBOptimizerCon newSC->schemaName(""); newSC->tableAlias(newTableAlias); newSC->colPosition(colPosition++); - // MB not needed - newSC->oid(0); - newSC->expressionId(4294967295); newSC->alias(rc->alias()); newReturnedColumns.push_back(newSC); } @@ -386,49 +375,11 @@ bool applyParallelCES(execplan::CalpontSelectExecutionPlan& csep, RBOptimizerCon } newReturnedColumns.push_back(rc); } - // This part is not used - // TODO support expressions - // Find SC for the RC - - // auto rcCloned = boost::make_shared(*rc, rc->sessionID()); - // TODO timezone and result type are not copied - // TODO add specific ctor for this functionality - // If there is an alias in the map then it is a new derived table - - // auto sc = dynamic_cast(rc.get()); - // std::vector scs; - - // std::cout << "Processing RC schema " << rc->schemaName() << " table " << rc->tableName() << " alias " - // << rc->tableAlias() << std::endl; - // for (auto& [tableAlias, aliasAndCounter] : tableAliasMap) - // { - // std::cout << "Processing table alias " << tableAlias << " new alias " << aliasAndCounter.first - // << " col position " << aliasAndCounter.second << std::endl; - // } - // auto newTableAliasAndColPositionCounter = - // tableAliasMap.find({sc->schemaName(), sc->tableName(), sc->tableAlias(), "", false}); - // if (newTableAliasAndColPositionCounter == tableAliasMap.end()) - // { - // std::cout << "The RC doesn't belong to any of the derived tables, so leave it intact" << std::endl; - // continue; - // } - // auto& [newTableAlias, colPosition] = newTableAliasAndColPositionCounter->second; - - // sc->tableName(""); - // sc->schemaName(""); - // sc->tableAlias(newTableAlias); - // sc->colPosition(colPosition++); - - // rcCloned->isColumnStore(true); - // 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 + // Remove the filters that are not necessary as they were pushed down to union units. + // But this is inappropriate for some EXISTS filter and join conditions - // WIP hardcoded query + // WIP hardcoded query with lhs,rhs being simple columns if (csep.filters() && csep.filters()->data()) { auto* left = dynamic_cast(csep.filters()->data());