[SERVER-13908] Whole index scan on sparse index should be able to provide a sort Created: 12/May/14  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Querying
Affects Version/s: 2.6.1
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: J Rassi Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-10801 Allow compound geo indexes to be able... Backlog
Assigned Teams:
Query Optimization
Participants:

 Description   

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.


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