Fix automaticCE's explain when there is a backup plan involved

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

      Multiplanner takes a backup plan to get executed if the winning plan has a blocking sort for those cases in which the blocking sort exceeds the allocated memory space. When that happens and automaticCE is the selected planRankerMode two things happen:
      1. If the blocking sort plan can be executed, the backup plan is never output in the explain output since when we extract it from multiplanner, it has not been yet rejected.
      1. If the blocking sort cannot be executed and the backup plan is actually executed, the blocking sort is still output as winning and there's no trace of the backup one, which is indeed the one that was executed.

      Repro steps from matt.boros@mongodb.com

      const coll = db.coll;
      coll.drop();
      
      const q = [{$sort : {a : 1}}, {$match : {t : 1}}];
      const docs = [];
      for (let i = 0; i < 100; i++) {
      	docs.push({});
      }
      assert.commandWorked(coll.insert(docs));
      assert.commandWorked(coll.createIndex({a: 1}))
      assert.commandWorked(coll.createIndex({t: 1}))
      jsTestLog(coll.explain().aggregate(q))
      // with featureFlagCostBasedRanker: off, it shows 1 winning plan, 1 rejected
      // with featureFlagCostBasedRanker: on, it shows 1 winning plan, 0 rejected
      

            Assignee:
            Unassigned
            Reporter:
            Carlos Alonso Pérez
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: