Remove "filter" from FETCH stage during null checks

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

      Since the implementation of SERVER-81378 in 8.0, the query $eq: null does not necessitate a "filter" during the FETCH stage. This is because empty arrays and empty subdocuments no longer match the query during IXSCAN, and only matching documents (field missing or field explicitly set to null) are identified during the IXSCAN.

      However, the "filter" is still present as of 8.0.15, and appears unnecessary. Removing this filter may improve performance, as it opens up the possibility for covered queries that perform null checks.

      Below is a repro of this behavior in both 7.0.25-ent and 8.0.15-ent:

      db.queries.drop()
      
      db.queries.insertOne({ "a": null })
      db.queries.insertOne({ "b": 1 })
      db.queries.insertOne({ "a": [] })
      db.queries.insertOne({ "a": {} })
      
      db.queries.createIndex({ "a": 1 })
      
      db.queries.find({
          "a": { "$eq": null }
      }).explain("executionStats")
      

      In 7.0.25-ent, the explain output contains the following execution stats:

      nReturned: 2,
      totalKeysExamined: 4,
      totalDocsExamined: 3,
      

      In 8.0.15-ent, the explain output has the following:

      nReturned: 2,
      totalKeysExamined: 2,
      totalDocsExamined: 2,
      

            Assignee:
            Unassigned
            Reporter:
            Matthew Javaly
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: