[SERVER-7899] Projections that could utilize a covered index do not Created: 11/Dec/12  Updated: 07/Mar/14  Resolved: 11/Dec/12

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

Type: Improvement Priority: Major - P3
Reporter: Vince Garcia Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

When a query's projection includes fields that are covered by an index, the covering index is not used.

Notice in this example that the first query is indexOnly: false, but the second (hinted) query is indexOnly: true.

c = db.c;
c.drop();
 
c.ensureIndex({_id: 1, a: 1});
 
c.save({_id: "i", a: "x"});
 
c.find({_id: "i"}, {a: 1}).explain();
/*
{
	"cursor" : "BtreeCursor _id_",
	"isMultiKey" : false,
	"n" : 1,
	"nscannedObjects" : 1,
	"nscanned" : 1,
	"nscannedObjectsAllPlans" : 1,
	"nscannedAllPlans" : 1,
	"scanAndOrder" : false,
	"indexOnly" : false,
	"nYields" : 0,
	"nChunkSkips" : 0,
	"millis" : 0,
	"indexBounds" : {
		"_id" : [
			[
				"i",
				"i"
			]
		]
	},
	"server" : "..."
}
*/
 
c.find({_id: "i"}, {a: 1}).hint({_id: 1, a: 1}).explain();
/*
{
	"cursor" : "BtreeCursor _id_1_a_1",
	"isMultiKey" : false,
	"n" : 1,
	"nscannedObjects" : 1,
	"nscanned" : 1,
	"nscannedObjectsAllPlans" : 1,
	"nscannedAllPlans" : 1,
	"scanAndOrder" : false,
	"indexOnly" : true,
	"nYields" : 0,
	"nChunkSkips" : 0,
	"millis" : 0,
	"indexBounds" : {
		"_id" : [
			[
				"i",
				"i"
			]
		],
		"a" : [
			[
				{
					"$minElement" : 1
				},
				{
					"$maxElement" : 1
				}
			]
		]
	},
	"server" : "..."
}
*/



 Comments   
Comment by Eliot Horowitz (Inactive) [ 11/Dec/12 ]

See SERVER-2109

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