Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-67576

Make parameterized explode for sort plans work with the SBE plan cache

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.0.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
    • Query Execution
    • Minor Change
    • QE 2023-02-06, QE 2023-02-20, QE 2023-03-06, QE 2023-03-20, QE 2023-04-03
    • 20

      In related ticket SERVER-66459 we plan to implement a quick fix of simply prohibiting query solutions generated by "explode for sort" from getting cached. The work for this ticket is to re-enable the SBE plan cache in combination with explode for sort.

      Doing so could be a bit tricky. One reason is that the decision of whether to explode is done based on analyzing the index bounds. However, there could be various interval evaluation trees (IETs) that could lead to these explodable bounds. We need to make sure that no matter the value of the parameters, the SBE plan is still correct.

      Another complication is that the number of index scans resulting from the explosion can depend on the number of unique values in a $in. But the current SBE plan cache encoding does not incorporate the length of the $in or the number of unique values. Doing so would make the plan cache less effective, since it would result in reduced plan reuse for applications that use $in.

      One idea for how to implement this is to have some kind of runtime explosion. That is, the cached plan itself would not necessarily contain all of the necessary branches beneath the SortedMergeStage. When the plan is recovered from the cache and the input parameter values bound in, we can create the correct number of cloned ixscan branches beneath the sorted merge, each referring to the correct (lowKey, highKey) pair from the runtime environment.

            Assignee:
            rui.liu@mongodb.com Rui Liu
            Reporter:
            david.storch@mongodb.com David Storch
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: