-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Querying
-
Query Optimization
The query planner elects to use a blocking sort for queries where the sort spec doesn't match the index spec, even in the case where there is an equality match predicate on some prefix of the sort spec. In this special case a sort is only truly required on the remaining suffix of the sort spec, for which the index could possibly be used. For example, with an index on {a:1,b:1}:
- db.foo.find({a:2}).sort({a:1,b:1}) - sort uses the index
- db.foo.find({a:2}).sort({a:-1,b:1}) - blocking sort
- db.foo.find({a:2}).sort({a:-1,b:-1}) - sort uses the index
- db.foo.find({a:2}).sort({a:1,b:-1}) - blocking sort
Logically, query 2 is the same as 1, and query 4 is the same as 3