@@ -277,8 +277,7 @@ void Optimizer::initializeRules(ExecutionPlan* plan,
277277
278278// @brief the actual optimization
279279void Optimizer::createPlans (std::unique_ptr<ExecutionPlan> plan,
280- QueryOptions const & queryOptions,
281- bool estimateAllPlans) {
280+ QueryOptions const & queryOptions) {
282281 _runOnlyRequiredRules = false ;
283282 ExecutionPlan* initialPlan = plan.get ();
284283
@@ -416,7 +415,7 @@ void Optimizer::createPlans(std::unique_ptr<ExecutionPlan> plan,
416415
417416 finalizePlans ();
418417
419- estimateCosts (queryOptions, estimateAllPlans );
418+ estimateCosts (queryOptions);
420419
421420 // Best plan should not have forced hints left.
422421 // note: this method will throw in case the plan still contains
@@ -467,29 +466,18 @@ void Optimizer::checkForcedIndexHints() {
467466 TRI_ASSERT (!_plans.list .empty ());
468467}
469468
470- void Optimizer::estimateCosts (QueryOptions const & queryOptions,
471- bool estimateAllPlans) {
472- if (estimateAllPlans || _plans.size () > 1 ||
473- queryOptions.profile >= ProfileLevel::Blocks) {
474- // if profiling is turned on, we must do the cost estimation here
475- // because the cost estimation must be done while the transaction
476- // is still running
477- for (auto & plan : _plans.list ) {
478- plan.first ->invalidateCost ();
479- plan.first ->getCost ();
480- // this value is cached in the plan, so formally this step is
481- // unnecessary, but for the sake of cleanliness...
482- }
483-
484- if (_plans.size () > 1 ) {
485- // only sort plans when necessary
486- std::sort (_plans.list .begin (), _plans.list .end (),
487- [](PlanList::Entry const & a, PlanList::Entry const & b) -> bool {
488- return a.first ->getCost ().estimatedCost <
489- b.first ->getCost ().estimatedCost ;
490- });
491- }
469+ void Optimizer::estimateCosts (QueryOptions const & queryOptions) {
470+ // Invalidate all plans and get new estimates before doing anything
471+ for (auto & plan : _plans.list ) {
472+ plan.first ->invalidateCost ();
473+ plan.first ->getCost ();
492474 }
475+
476+ std::sort (_plans.list .begin (), _plans.list .end (),
477+ [](PlanList::Entry const & a, PlanList::Entry const & b) -> bool {
478+ return a.first ->getCost ().estimatedCost <
479+ b.first ->getCost ().estimatedCost ;
480+ });
493481}
494482
495483void Optimizer::disableRule (ExecutionPlan* plan, int level) {
0 commit comments