ExportXMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Execution
    • QE 2026-12-07
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Context

      Part of SPM-4775 Phase 1. CBR-ranked queries need candidate plans that the multiplanner (MP) must never see (collection scans when an index exists; classic index intersection). This ticket adds the shared plumbing only; later tickets enable concrete candidates (collection scan, then AND_HASH/AND_SORTED). No user-visible behavior change: nothing sets the new options yet.

      Work

      • Add QueryPlannerParams::cbrOnlyPlannerOptions: option bits enumerated for CBR only. Apply them via an RAII scope only at CBR enumeration sites:
        • getBestCBRPlan re-enumeration (mixed: NoMultiplanningResults, EstimateRankingEffort);
        • PlanRanker::rankPlans enumeration when the strategy is strict costBased.
          MP's enumeration (MP-only, mixed MP phase, subplanner, replanning) is untouched.
      • Tag solutions that exist only because of a CBR-only option (QuerySolution::cbrOnly). This ticket has a single producer, kept minimal so the mechanism can be tested end to end: the collection scan added by a CBR-only INCLUDE_COLLSCAN. It is not tagged when the scan is required, bounded, or provides the sort on a clustered collection, because the planner outputs those scans without the option. In QueryPlanner::plan(), INCLUDE_COLLSCAN is read in one place only, so this collection scan is the only solution the option can add.
      • MP isolation:
        • Single-solution shortcut decided on non-CBR-only solutions; CBR-only ones are dropped when it fires.
        • When CBR can't pick a single winner, CBR-only solutions are removed from the set handed back for multiplanning and kept in explain as rejected. CBR can't pick a winner when a plan has an unsupported node, or when a sampled index scan estimates to zero keys (SERVER-136193). If CBR's cheapest estimated plan is CBR-only, the cheapest multiplanning-eligible plan takes its place in that set. MP's candidate set is therefore exactly what it would be without CBR-only options (scope non-goal 8).
        • NoMultiplanningResults: if CBR's winner is CBR-only, don't reuse MP's trial (abandonTrialsExceptHashes would tassert 11763501; addRemappedEstimates would tassert 11763502). Return the CBR result so the winner goes through the fresh single-candidate MultiPlanner for works measurement and plan caching, as EstimateRankingEffort already does.
      • Unit tests for each of the above.

      Out of scope

      • Query knob / feature flag that turns on the CBR-only collection scan, and its costing and cache behaviour (next ticket).
      • notablescan: INCLUDE_COLLSCAN outputs an unbounded collection scan under NO_TABLE_SCAN when an indexed plan exists. This is pre-existing and already affects join optimization single-table access. It is tracked in a separate bug (SERVER-139995), which must be fixed before the collection scan knob ticket enables the option. STRICT_NO_TABLE_SCAN (query settings allowedIndexes without $natural) is not affected.
      • CBR-only index intersection: the option bit, planner_access gating, tagging, and the 64-solution cap interaction (intersection ticket). The intersection ticket must also decide how to estimate an intersection plan whose own index scan has a zero sampled estimate: today such a plan is inestimable, so as a CBR-only plan it is always rejected.
      • A shared rule for deciding which plans are CBR-only across all CBR-only options. It will be designed in the intersection ticket, once there is a second kind of CBR-only plan.
      • Rooted $or subplanner.

      Plan cache: the CBR-only winner is cached through the existing single-candidate MultiPlanner (works measured) - covered here. Cache recovery and replanning end-to-end tests come with the collscan ticket. Cache recovery of CBR-only intersection plans needs a fix (planFromCache rebuilds via knob-gated planner_access and silently misses) - tracked in the intersection ticket.

      Acceptance criteria

      • With cbrOnlyPlannerOptions == 0 plans, explain and plan cache are byte-identical to today.
      • With CBR-only INCLUDE_COLLSCAN set in tests: costBased and both mixed strategies can choose the collscan; MP never runs it as a trial candidate, including in the unsupported-node and zero-CE fallbacks; no tasserts; the CBR-chosen collscan is cached via works measurement.

            Assignee:
            Daniel Tabacaru
            Reporter:
            Daniel Tabacaru
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: