diff --git a/dbcon/mysql/ha_mcs_execplan.cpp b/dbcon/mysql/ha_mcs_execplan.cpp index 01ab0e52c..0fde2aedc 100644 --- a/dbcon/mysql/ha_mcs_execplan.cpp +++ b/dbcon/mysql/ha_mcs_execplan.cpp @@ -5287,7 +5287,7 @@ void extractColumnStatistics(TABLE_LIST* table_ptr, gp_walk_info& gwi) } else { - auto columnStatisticsVec = columnStatisticsMapIt->second.second; + auto& columnStatisticsVec = columnStatisticsMapIt->second.getHistograms(); columnStatisticsVec.push_back(histogram); } } diff --git a/dbcon/mysql/ha_mcs_impl_if.h b/dbcon/mysql/ha_mcs_impl_if.h index d778fb800..5ccdb65e9 100644 --- a/dbcon/mysql/ha_mcs_impl_if.h +++ b/dbcon/mysql/ha_mcs_impl_if.h @@ -119,9 +119,31 @@ typedef dmlpackage::TableValuesMap TableValuesMap; typedef std::map> TableMap; typedef std::tr1::unordered_map> TableOnExprList; typedef std::tr1::unordered_map TableOuterJoinMap; + +struct ColumnStatistics +{ + ColumnStatistics(execplan::SimpleColumn column, std::vector histograms) + : column(column), histograms(histograms) + { + } + ColumnStatistics() = default; + + execplan::SimpleColumn column; + std::vector histograms; + + std::vector& getHistograms() + { + return histograms; + } + + execplan::SimpleColumn& getColumn() + { + return column; + } +}; + using ColumnName = std::string; -using ColumnStatisticsMap = - std::unordered_map>>; +using ColumnStatisticsMap = std::unordered_map; using TableStatisticsMap = std::unordered_map; diff --git a/dbcon/rbo/rbo_apply_parallel_ces.cpp b/dbcon/rbo/rbo_apply_parallel_ces.cpp index dc421ea59..d85c95609 100644 --- a/dbcon/rbo/rbo_apply_parallel_ces.cpp +++ b/dbcon/rbo/rbo_apply_parallel_ces.cpp @@ -238,11 +238,12 @@ std::optional> chooseKeyC } // TODO take some column and some stats for it!!! - for (auto& [columnName, scAndStatisticsVec] : tableColumnsStatisticsIt->second) + for (auto& [columnName, columnStatistics] : tableColumnsStatisticsIt->second) { - auto& [sc, columnStatisticsVec] = scAndStatisticsVec; - auto* columnStatistics = chooseStatisticsToUse(columnStatisticsVec); - return {{sc, columnStatistics}}; + auto& sc = columnStatistics.getColumn(); + auto& columnStatisticsVec = columnStatistics.getHistograms(); + auto* bestColumnStatistics = chooseStatisticsToUse(columnStatisticsVec); + return {{sc, bestColumnStatistics}}; } return std::nullopt; @@ -262,7 +263,7 @@ bool parallelCESFilter(execplan::CalpontSelectExecutionPlan& csep, optimizer::RB // Returns optional with bounds if successful, nullopt otherwise template std::optional> populateRangeBounds(Histogram_json_hb* columnStatistics, - optimizer::RBOptimizerContext& ctx) + size_t& maxParallelFactor) { details::FilterRangeBounds bounds; @@ -280,7 +281,6 @@ std::optional> populateRangeBounds(Histogram_json_ }; // Get parallel factor from context - size_t maxParallelFactor = ctx.getCesOptimizationParallelFactor(); size_t numberOfUnionUnits = std::min(columnStatistics->get_json_histogram().size(), maxParallelFactor); size_t numberOfBucketsPerUnionUnit = columnStatistics->get_json_histogram().size() / numberOfUnionUnits; @@ -343,7 +343,8 @@ execplan::CalpontSelectExecutionPlan::SelectList makeUnionFromTable( std::cout << "makeUnionFromTable RC front " << csep.returnedCols().front()->toString() << std::endl; // TODO char and other numerical types support - auto boundsOpt = populateRangeBounds(columnStatistics, ctx); + size_t configuredMaxParallelFactor = ctx.getCesOptimizationParallelFactor(); + auto boundsOpt = populateRangeBounds(columnStatistics, configuredMaxParallelFactor); if (!boundsOpt.has_value()) { return unionVec; diff --git a/dbcon/rbo/rulebased_optimizer.h b/dbcon/rbo/rulebased_optimizer.h index 2ea075197..b2856e906 100644 --- a/dbcon/rbo/rulebased_optimizer.h +++ b/dbcon/rbo/rulebased_optimizer.h @@ -145,4 +145,4 @@ bool optimizeCSEP(execplan::CalpontSelectExecutionPlan& root, RBOptimizerContext std::string getRewrittenSubTableAlias(const execplan::CalpontSystemCatalog::TableAliasName& table, const RBOptimizerContext& ctx); -} \ No newline at end of file +} // namespace optimizer \ No newline at end of file