[SERVER-18309] Sparse indexes should not be assigned to {$in: [null, ...]} predicates Created: 04/May/15  Updated: 18/May/16  Resolved: 16/Jun/15

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

Type: Bug Priority: Major - P3
Reporter: J Rassi Assignee: David Storch
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Backwards Compatibility: Minor Change
Operating System: ALL
Sprint: Quint Iteration 5
Participants:

 Description   

Sparse indexes are incorrectly assigned to {$in: [null, ...]} predicates. As a consequence, {$in: [null, ...]} queries can omit documents from the result set that are missing the value of the given field, if a sparse index is assigned to the $in predicate.

Reproduce as follows:

> db.foo.drop()
true
> db.foo.ensureIndex({a: 1}, {sparse: true})
{
	"createdCollectionAutomatically" : true,
	"numIndexesBefore" : 1,
	"numIndexesAfter" : 2,
	"ok" : 1
}
> db.foo.insert({})
WriteResult({ "nInserted" : 1 })
> db.foo.find({a: {$in: [null]}}) // No results: unexpected.
> db.foo.find({a: {$in: [null]}}).hint({$natural: 1}) // 1 result: expected.
{ "_id" : ObjectId("55477a258aa4f4cc73af71a5") }



 Comments   
Comment by Githook User [ 16/Jun/15 ]

Author:

{u'username': u'coollog', u'name': u'Qingyang Chen', u'email': u'qingyang.chen@10gen.com'}

Message: SERVER-18309 have {$in: [.., null, ..]} not use sparse indexes

Closes #979

Signed-off-by: Jason Rassi <rassi@10gen.com>
Branch: master
https://github.com/mongodb/mongo/commit/2b4474715604697acacca70c7f7647947b2c82f1

Generated at Thu Feb 08 03:47:15 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.