[SERVER-37164] Incorrect query results on $gte null with sparse index Created: 17/Sep/18  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Ian Boros Assignee: Backlog - Query Execution
Resolution: Unresolved Votes: 0
Labels: mql-semantics, query-44-grooming
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-44376 Indexed $gte/lte does not produce sup... Closed
Assigned Teams:
Query Execution
Operating System: ALL
Participants:

 Description   

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].


Generated at Thu Feb 08 04:45:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.