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

"isCached" in explain can be true for more than one plan when using distinct scan

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Optimization
    • ALL
    • Hide
      
      const coll = db.coll;
      assert(coll.drop())
      assert.commandWorked(coll.insert({a: 1}))
      assert.commandWorked(coll.createIndex({a: 1}))
      assert.commandWorked(coll.createIndex({a: 1, b: 1}))
      
      q = [
          {$sort: {a: 1}},
          {$group: {_id: "$a"}}
      ]
      
      for(let i = 0; i < 10; i++){
          coll.aggregate(q).toArray();
      }
      
      jsTestLog(coll.explain().aggregate(q));
      
      Show
      const coll = db.coll; assert (coll.drop()) assert .commandWorked(coll.insert({a: 1})) assert .commandWorked(coll.createIndex({a: 1})) assert .commandWorked(coll.createIndex({a: 1, b: 1})) q = [ {$sort: {a: 1}}, {$group: {_id: "$a" }} ] for (let i = 0; i < 10; i++){ coll.aggregate(q).toArray(); } jsTestLog(coll.explain().aggregate(q));
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Using the query

      [
          {$sort: {a: 1}},
          {$group: {_id: "$a"}}
      ]
      

      and indexes

      {a: 1}
      {a: 1, b: 1}
      

      With default flags, we only consider one plan, and the "isCached" value is correct in explain.

      With the featureFlagShardFilteringDistinctScan flag enabled, we multiplan two plans (a distinct scan for each index), and one plan gets cached. When explain is run, they're both listed as "isCached: true"

      isCached should only be true for one plan, since a query can only have one chosen solution in the cache.

            Assignee:
            henri.nikku@mongodb.com Henri Nikku
            Reporter:
            matt.boros@mongodb.com Matt Boros
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              None
              None
              None
              None