-
Type:
New Feature
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: 2.6.1
-
Component/s: Querying
-
None
-
Query Optimization
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Sparse indexes can generally be used to answer queries that include a "non-sparse" predicate on an indexed field.
This is not the case, however, for query plans that perform a whole index scan to provide a sort. These query plans should be able to use sparse indexes if a "non-sparse" predicate is given on an indexed field.
> db.foo.dropIndexes()
{
"nIndexesWas" : 2,
"msg" : "non-_id indexes dropped for collection",
"ok" : 1
}
> db.foo.ensureIndex({a:1,b:1},{sparse:true})
{
"createdCollectionAutomatically" : true,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
> db.foo.find({a:1,b:1}).sort({a:1}).explain().cursor
BtreeCursor a_1_b_1 // Bounded index scan; sparse index is used.
> db.foo.find({b:1}).sort({a:1}).explain().cursor
BasicCursor // Whole index scan; sparse index not used.
- related to
-
SERVER-10801 Allow compound geo indexes to be able to provide sort
-
- Backlog
-