[SERVER-14627] explain().allPlans lists only the chosen query plan Created: 21/Jul/14  Updated: 10/Dec/14  Resolved: 21/Jul/14

Status: Closed
Project: Core Server
Component/s: Diagnostics, Querying
Affects Version/s: 2.7.3
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: J Rassi 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-14610 Detailed explain does not list reject... Closed
Operating System: ALL
Participants:

 Description   

The below query generates three candidate query plans, but explain().allPlans only lists the one chosen. getPlansByQuery() correctly lists all three.

Reproduces in master, and in 2.6.2/2.6.3. Does not reproduce on 2.6.1 or earlier. (edit: does not reproduce on the 2.6 branch; I somehow had my 2.6.x binaries on my machine replaced with binaries from 2.7.x).

> db.foo.drop()
true
> db.foo.ensureIndex({b:1})
{
	"createdCollectionAutomatically" : true,
	"numIndexesBefore" : 1,
	"numIndexesAfter" : 2,
	"ok" : 1
}
> db.foo.ensureIndex({a:1})
{
	"createdCollectionAutomatically" : false,
	"numIndexesBefore" : 2,
	"numIndexesAfter" : 3,
	"ok" : 1
}
> db.foo.insert({a:1,b:2})
WriteResult({ "nInserted" : 1 })
> db.foo.insert({a:1,b:2})
WriteResult({ "nInserted" : 1 })
> db.foo.insert({a:1,b:2})
WriteResult({ "nInserted" : 1 })
> db.foo.find({a:1,b:1}).itcount()
0
> db.foo.getPlanCache().getPlansByQuery({a:1,b:1},{},{}).length
3
> db.foo.find({a:1,b:1}).explain(true)
{
	"cursor" : "BtreeCursor b_1",
	"isMultiKey" : false,
	"n" : 0,
	"nscannedObjects" : 0,
	"nscanned" : 0,
	"nscannedObjectsAllPlans" : 0,
	"nscannedAllPlans" : 0,
	"scanAndOrder" : false,
	"indexOnly" : false,
	"nYields" : 0,
	"nChunkSkips" : 0,
	"millis" : 0,
	"indexBounds" : {
		"b" : [
			[
				1,
				1
			]
		]
	},
	"allPlans" : [
		{
			"cursor" : "BtreeCursor b_1",
			"isMultiKey" : false,
			"n" : 0,
			"nscannedObjects" : 0,
			"nscanned" : 0,
			"scanAndOrder" : false,
			"indexOnly" : false,
			"nChunkSkips" : 0,
			"indexBounds" : {
				"b" : [
					[
						1,
						1
					]
				]
			}
		}
	],
	"server" : "Rassi-MacBook-Pro.local:27017",
	"filterSet" : false,
	"stats" : {
		"type" : "KEEP_MUTATIONS",
		"works" : 2,
		"yields" : 0,
		"unyields" : 0,
		"invalidates" : 0,
		"advanced" : 0,
		"needTime" : 0,
		"isEOF" : 1,
		"children" : [
			{
				"type" : "FETCH",
				"works" : 1,
				"yields" : 0,
				"unyields" : 0,
				"invalidates" : 0,
				"advanced" : 0,
				"needTime" : 0,
				"isEOF" : 1,
				"alreadyHasObj" : 0,
				"forcedFetches" : 0,
				"matchTested" : 0,
				"children" : [
					{
						"type" : "IXSCAN",
						"works" : 1,
						"yields" : 0,
						"unyields" : 0,
						"invalidates" : 0,
						"advanced" : 0,
						"needTime" : 0,
						"isEOF" : 1,
						"keyPattern" : "{ b: 1.0 }",
						"isMultiKey" : 0,
						"boundsVerbose" : "field #0['b']: [1.0, 1.0]",
						"yieldMovedCursor" : 0,
						"dupsTested" : 0,
						"dupsDropped" : 0,
						"seenInvalidated" : 0,
						"matchTested" : 0,
						"keysExamined" : 0,
						"children" : [ ]
					}
				]
			}
		]
	}
}
>


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