-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.4.4
-
Component/s: Index Maintenance, Querying
-
Environment:OSX, MongoLabs
-
Query Optimization
I have a collection of documents with keys _id, a, and b. I have an index {a:1,b:1}.
When I do find(a).sort(b).limit(5) the index is used, and only 5 documents are scanned.
When I do find(a).sort(b,_id).limit(5) (with or without a hint) it appears the index is only used to match a - as all documents with the matching value for a are scanned (nscanned and nscannedObjects are high).
The behavior I would expect is that it would scan through a and b values enough to get to the limit (5), and then it would stop scanning when it found the next unique b (or a). It would then sort on _id within the scanned records.
- depends on
-
SERVER-3310 Query optimizer should efficiently handle $in and sort with compound index.
- Closed
- is related to
-
SERVER-12533 Include sort (spec) for sort stage in full explain output
- Closed