[SERVER-8424] Do result projections on covered indexes only use the index? Created: 31/Jan/13  Updated: 15/Feb/13  Resolved: 31/Jan/13

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

Type: Question Priority: Major - P3
Reporter: Jon Hoffman Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

for a collection "foo" with index

{x:1}

, will a query like db.foo.find({},{_id:0,x1}).hint(

{x:1}

) touch the data? or will it be completely answered via the data stored in the index?

The explain verifies that it's "indexOnly", but I'm not sure what that means wrt to the actual results:

> db.foo.find({},{_id:0,x:1}).hint({x:1}).explain()
{
	"cursor" : "BtreeCursor x_1",
	"isMultiKey" : false,
	"n" : 100,
	"nscannedObjects" : 100,
	"nscanned" : 100,
	"nscannedObjectsAllPlans" : 100,
	"nscannedAllPlans" : 100,
	"scanAndOrder" : false,
	"indexOnly" : true,
	"nYields" : 0,
	"nChunkSkips" : 0,
	"millis" : 0,
	"indexBounds" : {
		"x" : [
			[
				{
					"$minElement" : 1
				},
				{
					"$maxElement" : 1
				}
			]
		]
	},
	"server" : "hoffrocket.local:27017"
}



 Comments   
Comment by Scott Hernandez (Inactive) [ 06/Feb/13 ]

Unfortunately covered index queries don't work with any embedded fields (if you use dot notation projection). I can link the related feature request if you would lkie.

Comment by Jon Hoffman [ 06/Feb/13 ]

I noticed that result projections aren't effective on indexes of subkeys on "_id". Am I doing something wrong?

> db.a.save({_id:{a:3,b:1}})
> db.a.save({_id:{a:2,b:1}})
> db.a.save({_id:{a:1,b:1}})
> db.a.ensureIndex({"_id.a":1})
> db.a.find({},{_id:0,"_id.a":1}).hint({"_id.a":1})
{ }
{ }
{ }
> db.a.find({},{"_id.a":1}).hint({"_id.a":1})
{ "_id" : { "a" : 1, "b" : 1 } }
{ "_id" : { "a" : 2, "b" : 1 } }
{ "_id" : { "a" : 3, "b" : 1 } }
> db.a.find({},{"_id.a":1}).hint({"_id.a":1}).explain()
{
	"cursor" : "BtreeCursor _id.a_1",
	"isMultiKey" : false,
	"n" : 3,
	"nscannedObjects" : 3,
	"nscanned" : 3,
	"nscannedObjectsAllPlans" : 3,
	"nscannedAllPlans" : 3,
	"scanAndOrder" : false,
	"indexOnly" : false,
	"nYields" : 0,
	"nChunkSkips" : 0,
	"millis" : 0,
	"indexBounds" : {
		"_id.a" : [
			[
				{
					"$minElement" : 1
				},
				{
					"$maxElement" : 1
				}
			]
		]
	},
	"server" : "hoffrocket.local:27017"
}

Comment by Scott Hernandez (Inactive) [ 31/Jan/13 ]

Yes, this does as you expect. "indexOnly" means that the query and results all came from the index and no document was used.

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