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

Incorrect query results on $gte null with sparse index

    • Query Optimization
    • Fully Compatible
    • ALL
    • v8.0, v7.3, v7.0, v6.0, v5.0
    • 200

      Bernard made a very insightful comment in a code review which lead us to realize this behavior:

      db.c.drop();
      db.c.insert({b: 1});
      
      const query = {a: {$gte: null}};
      // Returns the document. {b:1}
      printjson(db.c.find(query).toArray());
      
      db.c.createIndex({a: 1}, {sparse: true});
      
      // Returns nothing.
      printjson(db.c.find(query).toArray());
      

      On a query like {a: {$gte: null}}, the planner may choose to use a sparse index on 'a', even though the results should include documents which don't have an 'a' field (and therefore, don't have a key in the sparse index).

      I plan on fixing this as part of SERVER-36731, but we should probably do a special fix for older branches. [EDIT: We should decide which behavior is correct before changing anything].

            Assignee:
            ruoxin.xu@mongodb.com Ruoxin Xu
            Reporter:
            ian.boros@mongodb.com Ian Boros
            Votes:
            0 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated:
              Resolved: