[SERVER-2273] Covered index query scans docs Created: 22/Dec/10  Updated: 22/Dec/10  Resolved: 22/Dec/10

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

Type: Bug Priority: Major - P3
Reporter: Scott Hernandez (Inactive) Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

It seems like it doesn't use the index (no indexOnly) to get data in the last find.

> for (var i = 1; i <= 10000; i++) db.things.save(

{value : i}

);
> db.things.find({value:{$gt: 500}}).explain()
{
"cursor" : "BasicCursor",
"nscanned" : 10000,
"nscannedObjects" : 10000,
"n" : 9500,
"millis" : 15,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {

}
}
> db.things.ensureIndex(

{value:1}

)
> db.things.find({value:{$gt: 500}},

{value:1}

).explain()
{
"cursor" : "BtreeCursor value_1",
"nscanned" : 9500,
"nscannedObjects" : 9500,
"n" : 9500,
"millis" : 19,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" :

{ "value" : [ [ 500, 1.7976931348623157e+308 ] ] }

}



 Comments   
Comment by Eliot Horowitz (Inactive) [ 22/Dec/10 ]

You need to say you don't want the _id index

db.things.find({value:{$gt: 500}},

{value:1,_id:0}

).explain()

Generated at Thu Feb 08 02:59:28 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.