[DOCS-2323] Comment on: "manual/core/query-optimization.txt" Created: 29/Nov/13  Updated: 03/Nov/17  Resolved: 10/Jan/14

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: 01112017-cleanup

Type: Improvement Priority: Major - P3
Reporter: Docs Collector User (Inactive) Assignee: Kay Kim (Inactive)
Resolution: Won't Fix Votes: 0
Labels: collector-298ba4e7
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Location: http://docs.mongodb.org/manual/core/query-optimization/
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0
Referrer: http://docs.mongodb.org/manual/core/cursors/
Screen Resolution: 1280 x 1024
repo: docs
source: core/query-optimization


Participants:
Days since reply: 10 years, 5 weeks, 5 days ago

 Description   

Issue with the example given for 'Covering a Query'.

The example queries that explain which covers and not covers the query is mixed up.

The example query given for covered query is actually one that is not covered and vice versa.



 Comments   
Comment by Kay Kim (Inactive) [ 10/Jan/14 ]

Hi Roshan –
I believe the example queries are correct.

You can verify via the following:

> db.inventory.insert( { item: "cookies", type: "food" } )
> db.inventory.ensureIndex( { type: 1, item: 1 } )

Run the first query with the explain and you can see that the indexOnly field is true:

> db.inventory.find( { type: "food", item:/^c/ },
...                    { item: 1, _id: 0 } ).explain()
{
	"cursor" : "BtreeCursor type_1_item_1 multi",
	"isMultiKey" : false,
	"n" : 1,
	"nscannedObjects" : 0,
	"nscanned" : 1,
	"nscannedObjectsAllPlans" : 0,
	"nscannedAllPlans" : 1,
	"scanAndOrder" : false,
	"indexOnly" : true,
	"nYields" : 0,
	"nChunkSkips" : 0,
	"millis" : 0,
	"indexBounds" : {
		"type" : [
			[
				"food",
				"food"
			]
		],
		"item" : [
			[
				"c",
				"d"
			],
			[
				/^c/,
				/^c/
			]
		]
	},
	"server" : "bartleby.local:27019"
}

The second query has indexOnly equal to false, because in the projection document, we specify return the item field, but we do not explicitly state to not return the _id field with the _id: 0 specification

> db.inventory.find( { type: "food", item:/^c/ },
...                    { item: 1 } ).explain()
{
	"cursor" : "BtreeCursor type_1_item_1 multi",
	"isMultiKey" : false,
	"n" : 1,
	"nscannedObjects" : 1,
	"nscanned" : 1,
	"nscannedObjectsAllPlans" : 1,
	"nscannedAllPlans" : 1,
	"scanAndOrder" : false,
	"indexOnly" : false,
	"nYields" : 0,
	"nChunkSkips" : 0,
	"millis" : 0,
	"indexBounds" : {
		"type" : [
			[
				"food",
				"food"
			]
		],
		"item" : [
			[
				"c",
				"d"
			],
			[
				/^c/,
				/^c/
			]
		]
	},
	"server" : "bartleby.local:27019"
}

Hope this helps.

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