Planner leaves {$exists: true} on a wildcard field to be evaluated post-fetch when using CWI

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Optimization
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      Consider this example:

      db.test.createIndex({"a.$**": 1})
      // IXSCAN with "$_path" : ["[\"a.b\", \"a.b\"]", "[\"a.b.\", \"a.b/\")"] + FETCH without filter
      db.test.find({'a.b': {$exists: true}}).explain()
      
      db.test.dropIndexes()
      db.test.createIndex({"a.$**": 1, b: 1})
      // IXSCAN with "$_path" : ["[\"a.b\", \"a.b\"]", "[\"a.b.\", \"a.b/\")"] + FETCH with {$exists: true}
      db.test.find({'a.b': {$exists: true}}).explain()
      

      In the above example, this behavior is unlikely to cause significant issues because the index scan already filters out all keys where `a.b` doesn't exist. However, when the wildcard part doesn't come first in the compound index, this behavior can trigger the limitation described in SERVER-83322 and prevent $exists: true from being evaluated using the CWI.

            Assignee:
            Unassigned
            Reporter:
            Henri Nikku
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: