Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-14627

explain().allPlans lists only the chosen query plan

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.7.3
    • Component/s: Diagnostics, Querying
    • None
    • ALL

      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" : [ ]
      					}
      				]
      			}
      		]
      	}
      }
      >
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            rassi J Rassi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: