[SERVER-10767] Use index on find all Created: 13/Sep/13  Updated: 13/Sep/13  Resolved: 13/Sep/13

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

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

Issue Links:
Duplicate
duplicates SERVER-2109 Query optimizer should pick plans tha... Closed
Participants:

 Description   

It appears that find all is not using my index. The supposition is that find all may be ignoring indexes other than BasicCursor? It would be advantageous if the query used the covered index without having to resort to a hint.

Sample "Test" Collection Schema

{
 _id: ObjectId(<whatever>),
 a: <whatever>,
 b: <whatever>,
 c: <whatever>,
 d: <whatever>,
 e: {
    f: <whatever>,
    g: <whatever>
 }
}

Index on "Test"

db.test.ensureIndex( { "a": NumberInt(1), "c": NumberInt(1), "_id": NumberInt(1), "d": NumberInt(1) }, 
	             { name: "a_1_c_1__id_1_d_1", background: true } );

Query without hint and query with hint...

> db.test.find({},{d:1}).explain();
{
"cursor" : "BasicCursor",
"isMultiKey" : false,
"n" : 752,
"nscannedObjects" : 752,
"nscanned" : 752,
"nscannedObjectsAllPlans" : 752,
"nscannedAllPlans" : 752,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 4,
"nChunkSkips" : 0,
"millis" : 5,
"indexBounds" : {
	
},
"server" : <whatever>
}
 
> db.test.find({},{d:1}).hint("a_1_c_1__id_1_d_1").explain();
{
"cursor" : "BtreeCursor a_1_c_1__id_1_d_1",
"isMultiKey" : false,
"n" : 752,
"nscannedObjects" : 752,
"nscanned" : 752,
"nscannedObjectsAllPlans" : 752,
"nscannedAllPlans" : 752,
"scanAndOrder" : false,
"indexOnly" : true,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 0,
"indexBounds" : {
 "a" : [ [ { "$minElement" : 1 }, { "$maxElement" : 1 } ] ],
 "c" : [ [ { "$minElement" : 1 }, { "$maxElement" : 1 } ] ],
 "_id" : [ [ { "$minElement" : 1 }, { "$maxElement" : 1 } ] ],
 "d" : [ [ { "$minElement" : 1 }, { "$maxElement" : 1 } ] ]
},
"server" : <whatever>
}

http://stackoverflow.com/questions/18790163/mongodb-index-use-on-find-all-without-hint



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

dup of SERVER-2109

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