[SERVER-19511] Distinct command with no predicate can miss results when distinct field is first key pattern element of partial index Created: 21/Jul/15  Updated: 19/Sep/15  Resolved: 10/Aug/15

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

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

Issue Links:
Related
is related to SERVER-17854 Allow $or predicates to be indexed by... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Quint Iteration 7
Participants:

 Description   

Distinct commands with no query predicate are incorrectly able to use a partial index, if the distinct field is the first element of the index key pattern. As a result, these distinct commands can miss results.

Reproduce as follows:

> db.foo.drop()
true
> db.foo.insert({a: 1, b: 1})
WriteResult({ "nInserted" : 1 })
> db.foo.distinct("a")
[ 1 ] // expected
> db.foo.ensureIndex({a: 1}, {partialFilterExpression: {b: 2}})
{
	"createdCollectionAutomatically" : false,
	"numIndexesBefore" : 1,
	"numIndexesAfter" : 2,
	"ok" : 1
}
> db.foo.distinct("a")
[ ] // unexpected



 Comments   
Comment by Githook User [ 10/Aug/15 ]

Author:

{u'username': u'jrassi', u'name': u'Jason Rassi', u'email': u'rassi@10gen.com'}

Message: SERVER-19511 Fast distinct w/ no predicate shouldn't use partial index
Branch: master
https://github.com/mongodb/mongo/commit/55f6c3a09f96aabe7c933d9262cf011c7776fd60

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