[SERVER-3491] queries that require nothing from document scans documents anyway on indexed queries Created: 27/Jul/11  Updated: 29/Aug/11  Resolved: 27/Jul/11

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

Type: Bug Priority: Major - P3
Reporter: ttt Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

centos x64, mongo-10gen-server-1.8.2-mongodb_1 rpm


Operating System: Linux
Participants:

 Description   

> db.index.find(

{ subdomain: "sub.domain.com"}

,

{ __id:1}

).explain();
{
"cursor" : "BtreeCursor subdomain_1_folder_1_name_1",
"nscanned" : 2002,
"nscannedObjects" : 2002,
"n" : 2002,
"millis" : 6,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
"subdomain" : [
[
"sub.domain.com",
"sub.domain.com"
]
],
"folder" : [
[

{ "$minElement" : 1 }

,

{ "$maxElement" : 1 }

]
],
"name" : [
[

{ "$minElement" : 1 }

,

{ "$maxElement" : 1 }

]
]
}
}

> db.index.find(

{ subdomain: "sub.domain.org", folder: "" }

,

{subdomain:1}

).explain();
{
"cursor" : "BtreeCursor subdomain_1_folder_1_name_1",
"nscanned" : 1583,
"nscannedObjects" : 1583,
"n" : 1583,
"millis" : 9,
"nYields" : 2,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
"subdomain" : [
[
"sub.domain.org",
"sub.domain.org"
]
],
"folder" : [
[
"",
""
]
],
"name" : [
[

{ "$minElement" : 1 }

,

{ "$maxElement" : 1 }

]
]
}
}

mongo returns __id in both queries anyway, does that mean mongod needs to scan for objectid in objects and uses some other reference in indexes? i'm confused - it shouldn't touch objects at all for queries like this.



 Comments   
Comment by ttt [ 27/Jul/11 ]

i see. now that i exclude _id, indexOnly is true, but why would "nscannedObjects" be equal to "nscanned"? how do i get sure that only index is used?

> db.index.find(

{ subdomain: "sub.domain.org", folder: "" }

,{_id:0,subdomain:1,folder:1,name:1} ).explain();
{
"cursor" : "BtreeCursor subdomain_1_folder_1_name_1",
"nscanned" : 1583,
"nscannedObjects" : 1583,
"n" : 1583,
"millis" : 6,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : true,
"indexBounds" : {
"subdomain" : [
[
"sub.domain.org",
"sub.domain.org"
]
],
"folder" : [
[
"",
""
]
],
"name" : [
[

{ "$minElement" : 1 }

,

{ "$maxElement" : 1 }

]
]
}
}

Comment by Scott Hernandez (Inactive) [ 27/Jul/11 ]

You must exclude _id to use the indexed only. See the docs here: http://www.mongodb.org/display/DOCS/Retrieving+a+Subset+of+Fields#RetrievingaSubsetofFields-CoveredIndexes

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