You've already forked mariadb-columnstore-engine
							
							
				mirror of
				https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
				synced 2025-10-31 18:30:33 +03:00 
			
		
		
		
	chore(format): apply clang-format
This commit is contained in:
		| @@ -978,8 +978,8 @@ extern "C" | ||||
|       return 0; | ||||
|     } | ||||
|  | ||||
|     if (l > TraceSize) | ||||
|       l = TraceSize; | ||||
|     if (l > TraceSize * 100) | ||||
|       l = TraceSize * 100; | ||||
|  | ||||
|     *length = l; | ||||
|     return out->c_str(); | ||||
|   | ||||
| @@ -129,7 +129,6 @@ static void store_query_plan(execplan::SCSEP& csep, PlanType planType) | ||||
|   } | ||||
| } | ||||
|  | ||||
|  | ||||
| static void store_applied_rules(const std::string rboRules) | ||||
| { | ||||
|   cal_connection_info* ci = ensure_conn_info(); | ||||
|   | ||||
| @@ -79,8 +79,8 @@ bool someForeignTablesHasStatisticsAndMbIndex(execplan::CalpontSelectExecutionPl | ||||
|       [&ctx](const auto& table) | ||||
|       { | ||||
|         cal_impl_if::SchemaAndTableName schemaAndTableName = {table.schema, table.table}; | ||||
|         return (!table.isColumnstore() && | ||||
|                 ctx.getGwi().tableStatisticsMap.find(schemaAndTableName) != ctx.getGwi().tableStatisticsMap.end()); | ||||
|         return (!table.isColumnstore() && ctx.getGwi().tableStatisticsMap.find(schemaAndTableName) != | ||||
|                                               ctx.getGwi().tableStatisticsMap.end()); | ||||
|       }); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -29,9 +29,10 @@ | ||||
| namespace optimizer | ||||
| { | ||||
|  | ||||
|    using DerivedToFiltersMap = std::map<std::string, execplan::ParseTree*>; | ||||
| using DerivedToFiltersMap = std::map<std::string, execplan::ParseTree*>; | ||||
|  | ||||
| bool predicatePushdownFilter(execplan::CalpontSelectExecutionPlan& csep, optimizer::RBOptimizerContext& /*ctx*/) | ||||
| bool predicatePushdownFilter(execplan::CalpontSelectExecutionPlan& csep, | ||||
|                              optimizer::RBOptimizerContext& /*ctx*/) | ||||
| { | ||||
|   // The original rule match contains questionable decision to filter out | ||||
|   // queries that contains any UNION UNIT with only derived tables. | ||||
| @@ -40,7 +41,6 @@ bool predicatePushdownFilter(execplan::CalpontSelectExecutionPlan& csep, optimiz | ||||
|   return !csep.tableList().empty(); | ||||
| } | ||||
|  | ||||
|  | ||||
| void setDerivedTable(execplan::ParseTree* n) | ||||
| { | ||||
|   execplan::ParseTree* lhs = n->left(); | ||||
| @@ -75,8 +75,9 @@ void setDerivedTable(execplan::ParseTree* n) | ||||
|   } | ||||
| } | ||||
|  | ||||
| execplan::ParseTree* setDerivedFilter(cal_impl_if::gp_walk_info* gwip, execplan::ParseTree*& n, DerivedToFiltersMap& filterMap, | ||||
|                             const execplan::CalpontSelectExecutionPlan::SelectList& derivedTbList) | ||||
| execplan::ParseTree* setDerivedFilter(cal_impl_if::gp_walk_info* gwip, execplan::ParseTree*& n, | ||||
|                                       DerivedToFiltersMap& filterMap, | ||||
|                                       const execplan::CalpontSelectExecutionPlan::SelectList& derivedTbList) | ||||
| { | ||||
|   if (!(n->derivedTable().empty())) | ||||
|   { | ||||
| @@ -86,7 +87,8 @@ execplan::ParseTree* setDerivedFilter(cal_impl_if::gp_walk_info* gwip, execplan: | ||||
|  | ||||
|     for (uint i = 0; i < derivedTbList.size(); i++) | ||||
|     { | ||||
|       execplan::CalpontSelectExecutionPlan* plan = dynamic_cast<execplan::CalpontSelectExecutionPlan*>(derivedTbList[i].get()); | ||||
|       execplan::CalpontSelectExecutionPlan* plan = | ||||
|           dynamic_cast<execplan::CalpontSelectExecutionPlan*>(derivedTbList[i].get()); | ||||
|  | ||||
|       if (plan->derivedTbAlias() == n->derivedTable()) | ||||
|       { | ||||
| @@ -159,82 +161,83 @@ bool applyPredicatePushdown(execplan::CalpontSelectExecutionPlan& csep, RBOptimi | ||||
|    * that OR involving derived table are emptied and null candidate of each | ||||
|    * stacked filter needs to be reset (not null) | ||||
|    */ | ||||
|    execplan::ParseTree* pt = csep.filters(); | ||||
|    DerivedToFiltersMap derivedTbFilterMap; | ||||
|    auto& derivedTbList = csep.derivedTableList(); | ||||
|    bool hasBeenApplied = false; | ||||
|   execplan::ParseTree* pt = csep.filters(); | ||||
|   DerivedToFiltersMap derivedTbFilterMap; | ||||
|   auto& derivedTbList = csep.derivedTableList(); | ||||
|   bool hasBeenApplied = false; | ||||
|  | ||||
|    if (pt) | ||||
|    { | ||||
|      pt->walk(setDerivedTable); | ||||
|      setDerivedFilter(&ctx.getGwi(), pt, derivedTbFilterMap, derivedTbList); | ||||
|      csep.filters(pt); | ||||
|    } | ||||
|   | ||||
|    // AND the filters of individual stack to the derived table filter tree | ||||
|    // @todo union filters. | ||||
|    // @todo outer join complication | ||||
|    for (uint i = 0; i < derivedTbList.size(); i++) | ||||
|    { | ||||
|      execplan::CalpontSelectExecutionPlan* plan = dynamic_cast<execplan::CalpontSelectExecutionPlan*>(derivedTbList[i].get()); | ||||
|      execplan::CalpontSelectExecutionPlan::ReturnedColumnList derivedColList = plan->returnedCols(); | ||||
|      auto mapIt = derivedTbFilterMap.find(plan->derivedTbAlias()); | ||||
|   | ||||
|      if (mapIt != derivedTbFilterMap.end()) | ||||
|      { | ||||
|        // replace all derived column of this filter with real column from | ||||
|        // derived table projection list. | ||||
|        execplan::ParseTree* mainFilter = new execplan::ParseTree(); | ||||
|        mainFilter->copyTree(*(mapIt->second)); | ||||
|        replaceRefCol(mainFilter, derivedColList); | ||||
|        execplan::ParseTree* derivedFilter = plan->filters(); | ||||
|   | ||||
|        if (derivedFilter) | ||||
|        { | ||||
|          execplan::LogicOperator* op = new execplan::LogicOperator("and"); | ||||
|          execplan::ParseTree* filter = new execplan::ParseTree(op); | ||||
|          filter->left(derivedFilter); | ||||
|          filter->right(mainFilter); | ||||
|          plan->filters(filter); | ||||
|        } | ||||
|        else | ||||
|        { | ||||
|          plan->filters(mainFilter); | ||||
|        } | ||||
|   | ||||
|        // union filter handling | ||||
|        for (uint j = 0; j < plan->unionVec().size(); j++) | ||||
|        { | ||||
|          execplan::CalpontSelectExecutionPlan* unionPlan = | ||||
|              reinterpret_cast<execplan::CalpontSelectExecutionPlan*>(plan->unionVec()[j].get()); | ||||
|          execplan::CalpontSelectExecutionPlan::ReturnedColumnList unionColList = unionPlan->returnedCols(); | ||||
|          execplan::ParseTree* mainFilterForUnion = new execplan::ParseTree(); | ||||
|          mainFilterForUnion->copyTree(*(mapIt->second)); | ||||
|          replaceRefCol(mainFilterForUnion, unionColList); | ||||
|          execplan::ParseTree* unionFilter = unionPlan->filters(); | ||||
|   | ||||
|          if (unionFilter) | ||||
|          { | ||||
|            execplan::LogicOperator* op = new execplan::LogicOperator("and"); | ||||
|            execplan::ParseTree* filter = new execplan::ParseTree(op); | ||||
|            filter->left(unionFilter); | ||||
|            filter->right(mainFilterForUnion); | ||||
|            unionPlan->filters(filter); | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|            unionPlan->filters(mainFilterForUnion); | ||||
|          } | ||||
|        } | ||||
|        hasBeenApplied = true; | ||||
|      } | ||||
|    } | ||||
|   | ||||
|    // clean derivedTbFilterMap because all the filters are copied | ||||
|    for (auto mapIt = derivedTbFilterMap.begin(); mapIt != derivedTbFilterMap.end(); ++mapIt) | ||||
|    { | ||||
|   if (pt) | ||||
|   { | ||||
|     pt->walk(setDerivedTable); | ||||
|     setDerivedFilter(&ctx.getGwi(), pt, derivedTbFilterMap, derivedTbList); | ||||
|     csep.filters(pt); | ||||
|   } | ||||
|  | ||||
|   // AND the filters of individual stack to the derived table filter tree | ||||
|   // @todo union filters. | ||||
|   // @todo outer join complication | ||||
|   for (uint i = 0; i < derivedTbList.size(); i++) | ||||
|   { | ||||
|     execplan::CalpontSelectExecutionPlan* plan = | ||||
|         dynamic_cast<execplan::CalpontSelectExecutionPlan*>(derivedTbList[i].get()); | ||||
|     execplan::CalpontSelectExecutionPlan::ReturnedColumnList derivedColList = plan->returnedCols(); | ||||
|     auto mapIt = derivedTbFilterMap.find(plan->derivedTbAlias()); | ||||
|  | ||||
|     if (mapIt != derivedTbFilterMap.end()) | ||||
|     { | ||||
|       // replace all derived column of this filter with real column from | ||||
|       // derived table projection list. | ||||
|       execplan::ParseTree* mainFilter = new execplan::ParseTree(); | ||||
|       mainFilter->copyTree(*(mapIt->second)); | ||||
|       replaceRefCol(mainFilter, derivedColList); | ||||
|       execplan::ParseTree* derivedFilter = plan->filters(); | ||||
|  | ||||
|       if (derivedFilter) | ||||
|       { | ||||
|         execplan::LogicOperator* op = new execplan::LogicOperator("and"); | ||||
|         execplan::ParseTree* filter = new execplan::ParseTree(op); | ||||
|         filter->left(derivedFilter); | ||||
|         filter->right(mainFilter); | ||||
|         plan->filters(filter); | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|         plan->filters(mainFilter); | ||||
|       } | ||||
|  | ||||
|       // union filter handling | ||||
|       for (uint j = 0; j < plan->unionVec().size(); j++) | ||||
|       { | ||||
|         execplan::CalpontSelectExecutionPlan* unionPlan = | ||||
|             reinterpret_cast<execplan::CalpontSelectExecutionPlan*>(plan->unionVec()[j].get()); | ||||
|         execplan::CalpontSelectExecutionPlan::ReturnedColumnList unionColList = unionPlan->returnedCols(); | ||||
|         execplan::ParseTree* mainFilterForUnion = new execplan::ParseTree(); | ||||
|         mainFilterForUnion->copyTree(*(mapIt->second)); | ||||
|         replaceRefCol(mainFilterForUnion, unionColList); | ||||
|         execplan::ParseTree* unionFilter = unionPlan->filters(); | ||||
|  | ||||
|         if (unionFilter) | ||||
|         { | ||||
|           execplan::LogicOperator* op = new execplan::LogicOperator("and"); | ||||
|           execplan::ParseTree* filter = new execplan::ParseTree(op); | ||||
|           filter->left(unionFilter); | ||||
|           filter->right(mainFilterForUnion); | ||||
|           unionPlan->filters(filter); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|           unionPlan->filters(mainFilterForUnion); | ||||
|         } | ||||
|       } | ||||
|       hasBeenApplied = true; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   // clean derivedTbFilterMap because all the filters are copied | ||||
|   for (auto mapIt = derivedTbFilterMap.begin(); mapIt != derivedTbFilterMap.end(); ++mapIt) | ||||
|   { | ||||
|     delete (*mapIt).second; | ||||
|    } | ||||
|   } | ||||
|  | ||||
|   return hasBeenApplied; | ||||
| } | ||||
|   | ||||
| @@ -35,29 +35,61 @@ class RBOptimizerContext | ||||
| { | ||||
|  public: | ||||
|   RBOptimizerContext() = delete; | ||||
|   RBOptimizerContext(cal_impl_if::gp_walk_info& walk_info, THD& thd, bool logRules, uint cesOptimizationParallelFactor = 50) | ||||
|    : gwi_(walk_info), thd_(thd), logRules_(logRules), cesOptimizationParallelFactor_(cesOptimizationParallelFactor) | ||||
|   RBOptimizerContext(cal_impl_if::gp_walk_info& walk_info, THD& thd, bool logRules, | ||||
|                      uint cesOptimizationParallelFactor = 50) | ||||
|    : gwi_(walk_info) | ||||
|    , thd_(thd) | ||||
|    , logRules_(logRules) | ||||
|    , cesOptimizationParallelFactor_(cesOptimizationParallelFactor) | ||||
|   { | ||||
|   } | ||||
|  | ||||
|   // Accessors | ||||
|   cal_impl_if::gp_walk_info& getGwi() { return gwi_; } | ||||
|   THD& getThd() { return thd_; } | ||||
|   uint64_t getUniqueId() const { return uniqueId_; } | ||||
|   void incrementUniqueId() { ++uniqueId_; } | ||||
|   bool logRulesEnabled() const { return logRules_; } | ||||
|   uint getCesOptimizationParallelFactor() const { return cesOptimizationParallelFactor_; } | ||||
|   cal_impl_if::gp_walk_info& getGwi() | ||||
|   { | ||||
|     return gwi_; | ||||
|   } | ||||
|   THD& getThd() | ||||
|   { | ||||
|     return thd_; | ||||
|   } | ||||
|   uint64_t getUniqueId() const | ||||
|   { | ||||
|     return uniqueId_; | ||||
|   } | ||||
|   void incrementUniqueId() | ||||
|   { | ||||
|     ++uniqueId_; | ||||
|   } | ||||
|   bool logRulesEnabled() const | ||||
|   { | ||||
|     return logRules_; | ||||
|   } | ||||
|   uint getCesOptimizationParallelFactor() const | ||||
|   { | ||||
|     return cesOptimizationParallelFactor_; | ||||
|   } | ||||
|  | ||||
|   // Applied rules API | ||||
|   void addAppliedRule(const std::string& name) { appliedRules_.push_back(name); } | ||||
|   const std::vector<std::string>& getAppliedRules() const { return appliedRules_; } | ||||
|   bool hasAppliedRules() const { return !appliedRules_.empty(); } | ||||
|   void addAppliedRule(const std::string& name) | ||||
|   { | ||||
|     appliedRules_.push_back(name); | ||||
|   } | ||||
|   const std::vector<std::string>& getAppliedRules() const | ||||
|   { | ||||
|     return appliedRules_; | ||||
|   } | ||||
|   bool hasAppliedRules() const | ||||
|   { | ||||
|     return !appliedRules_.empty(); | ||||
|   } | ||||
|   std::string serializeAppliedRules() const | ||||
|   { | ||||
|     std::string out; | ||||
|     for (size_t i = 0; i < appliedRules_.size(); ++i) | ||||
|     { | ||||
|       if (i) out += ","; | ||||
|       if (i) | ||||
|         out += ","; | ||||
|       out += appliedRules_[i]; | ||||
|     } | ||||
|     return out; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user