[DOCS-3187] Difference between nscanned and nscannedObjects is unclear Created: 16/Apr/14  Updated: 16/Mar/15  Resolved: 01/Jul/14

Status: Closed
Project: Documentation
Component/s: manual
Affects Version/s: mongodb-2.6
Fix Version/s: v1.3.7

Type: Improvement Priority: Major - P3
Reporter: Joe Drumgoole (Inactive) Assignee: Tim Slavin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

All


Participants:
Days since reply: 9 years, 20 weeks, 5 days ago

 Description   

On this page http://docs.mongodb.org/manual/reference/method/cursor.explain/#explain-output-fields-core

The explanation of the difference between nscanned and nscannedObjects in the explain plan is unclear.

Need to define the specific differences between the two outputs and give a clear example of a query that will produce different outputs.

e.g.

explain.nscannedObjects
Specifies the total number of documents scanned during the query. The nscannedObjects may be lower than nscanned, such as if the index covers a query. See indexOnly. Additionally, the nscannedObjects may be lower than nscanned in the case of multikey index on an array field with duplicate documents.

explain.nscanned
Specifies the total number of documents or index entries scanned during the database operation. You want n and nscanned to be close in value as possible. The nscanned value may be higher than the nscannedObjects value, such as if the index covers a query. See indexOnly.



 Comments   
Comment by Githook User [ 26/Sep/14 ]

Author:

{u'username': u'kay-kim', u'name': u'kay', u'email': u'kay.kim@10gen.com'}

Message: DOCS-3187 additional tweaks
Branch: master
https://github.com/mongodb/docs/commit/b100d5959a9600df49974c710687febcb200de10

Comment by Githook User [ 26/Sep/14 ]

Author:

{u'username': u'TimSlavinMongoDB', u'name': u'Tim Slavin (MongoDB)', u'email': u'tim.slavin@10gen.com'}

Message: DOCS-3187: provided examples of n, nscanned, nscannedObjects usage

Signed-off-by: kay <kay.kim@10gen.com>
Branch: master
https://github.com/mongodb/docs/commit/c9373ae128c4840eee6cfacec5e2eb0ba8f708b0

Comment by Joe Drumgoole (Inactive) [ 16/Apr/14 ]

This blog has a better explanation:

http://emptysqua.re/blog/optimizing-mongodb-compound-indexes/

"For indexed queries, nscanned is the number of index keys in the range that Mongo scanned, and nscannedObjects is the number of documents it looked at to get to the final result. nscannedObjects includes at least all the documents returned, even if Mongo could tell just by looking at the index that the document was definitely a match. Thus, you can see that nscanned >= nscannedObjects >= n always. For simple queries you want the three numbers to be equal. It means you've created the ideal index and Mongo is using it."

Generated at Thu Feb 08 07:45:11 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.