Queries that can use a compound index to provide a sort on a subset of fields in the key pattern are sometimes given an unnecessary in-memory sort if an equality predicate is given on the sort field.
Reproduce with:
> db.foo.ensureIndex({a:1,b:1}) { "createdCollectionAutomatically" : true, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 } > db.foo.find({a:1}).sort({b:1}).explain().scanAndOrder false // CORRECT > db.foo.find({a:1,b:{$gt:0}}).sort({b:1}).explain().scanAndOrder false // CORRECT > db.foo.find({a:1,b:/hello/}).sort({b:1}).explain().scanAndOrder false // CORRECT > db.foo.find({a:1,b:1}).sort({b:1}).explain().scanAndOrder true // INCORRECT
- is related to
-
SERVER-14034 Sorted $in query with large number of elements can't use merge sort
- Closed