• Type: Bug
    • Resolution: Unresolved
    • Priority: Critical - P2
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Optimization
    • ALL
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Currently CostBasedPlanRankingStrategy::rankPlans invokes getBestCBRPlan when CBR is cheaper than MP. Since this is the last call it directly returns the result. If CBR failed, this entails that higher up the stack the callers will check that there are >1 plans, and will invoke MP with the rest of plans.

      This approach is inconsistent with Mixed rankers. Inside mixed rankers, if CBR fails, MP is invoked to continue from where the initial estimation run completed. However, currently the callers have no access to this intermediate state, and in the case of failure they will restart MP from the beginning.

      Suggested fix:

        auto cbrResult = getBestCBRPlan(...);
        if (!cbrResult.isOK()) return cbrResult;                 // hard error
        if (cbrResult.getValue().solutions.size() == 1) {
            mp.emitAccumulatedStats();
            return cbrResult;                                     // CBR chose a winner
        }
        // CBR couldn't cost >1 plan → resume MP where the estimate trial stopped
        return getBestMPPlan(opCtx, mp,
            {.maxNumWorksPerPlan = numWorksPerPlanMP - numWorksPerPlanEst,
             .targetNumResults = numResultsMP});
      
      

            Assignee:
            Unassigned
            Reporter:
            Timour Katchaounov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: