[SERVER-12866] explain should re-run all plans for that query but NOT mutate the cache Created: 24/Feb/14  Updated: 11/Jul/16  Resolved: 28/Feb/14

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.6.0-rc0
Fix Version/s: 2.6.0-rc1

Type: Bug Priority: Minor - P4
Reporter: David Storch Assignee: Benety Goh
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-12830 query does not select best index - us... Closed
is related to SERVER-12711 cached plan runner should provide exp... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

New semantics for explain():

explain should re-run all plans for that query but NOT mutate the cache.

----------

In a full explain, the "allPlans" field can report the index bounds used when the query shape was cached. This is misleading, as it appears that some of the alternative plans used the wrong index bounds:

> t = db.t
test.t
> t.drop()
true
> t.ensureIndex({a: 1})
WriteResult({ "nInserted" : 1 })
> t.ensureIndex({a: 1, b: 1})
WriteResult({ "nInserted" : 1 })
> t.find({a: "foo"}).explain()
{
	"cursor" : "BtreeCursor a_1",
	"isMultiKey" : false,
	"n" : 0,
	"nscannedObjects" : 0,
	"nscanned" : 0,
	"nscannedObjectsAllPlans" : 0,
	"nscannedAllPlans" : 0,
	"scanAndOrder" : false,
	"indexOnly" : false,
	"nYields" : 0,
	"nChunkSkips" : 0,
	"millis" : 1,
	"indexBounds" : {
		"a" : [
			[
				"foo",
				"foo"
			]
		]
	},
	"server" : "localhost:27017",
	"filterSet" : false
}
> t.find({a: "bar"}).explain(true)
{
	"cursor" : "BtreeCursor a_1",
	"isMultiKey" : false,
	"n" : 0,
	"nscannedObjects" : 0,
	"nscanned" : 0,
	"nscannedObjectsAllPlans" : 0,
	"nscannedAllPlans" : 0,
	"scanAndOrder" : false,
	"indexOnly" : false,
	"nYields" : 0,
	"nChunkSkips" : 0,
	"millis" : 0,
	"indexBounds" : {
		"a" : [
			[
				"bar",
				"bar"
			]
		]
	},
	"allPlans" : [
		{
			"cursor" : "BtreeCursor a_1",
			"isMultiKey" : false,
			"n" : 0,
			"nscannedObjects" : 0,
			"nscanned" : 0,
			"scanAndOrder" : false,
			"indexOnly" : false,
			"nChunkSkips" : 0,
			"indexBounds" : {
				"a" : [
					[
						"bar",
						"bar"
					]
				]
			}
		},
		{
			"cursor" : "BtreeCursor a_1_b_1",
			"isMultiKey" : false,
			"n" : 0,
			"nscannedObjects" : 0,
			"nscanned" : 0,
			"scanAndOrder" : false,
			"indexOnly" : false,
			"nChunkSkips" : 0,
			"indexBounds" : {
				"a" : [
					[
						"foo",
						"foo"
					]
				],
				"b" : [
					[
						{
							"$minElement" : 1
						},
						{
							"$maxElement" : 1
						}
					]
				]
			}
		},
		{
			"cursor" : "BasicCursor",
			"isMultiKey" : false,
			"n" : 0,
			"nscannedObjects" : 0,
			"nscanned" : 0,
			"scanAndOrder" : false,
			"indexOnly" : false,
			"nChunkSkips" : 0
		}
	],
	"server" : "localhost:27017",
	"filterSet" : false,
	"stats" : {

In the above example, the second plan reported in "allPlans" reports index bounds using "foo" rather than "bar".



 Comments   
Comment by Githook User [ 28/Feb/14 ]

Author:

{u'username': u'benety', u'name': u'Benety Goh', u'email': u'benety@mongodb.com'}

Message: SERVER-12866 explain queries should not mutate the cache
Branch: master
https://github.com/mongodb/mongo/commit/7851431d5b4b1dc0a5df17c1f7964d2bfc3ff623

Comment by Githook User [ 28/Feb/14 ]

Author:

{u'username': u'benety', u'name': u'Benety Goh', u'email': u'benety@mongodb.com'}

Message: SERVER-12866 added explain to canonical query constructor
Branch: master
https://github.com/mongodb/mongo/commit/4b936ef90766ab327ea71468002c07e3020b94d7

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