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

Explain("allPlansExecution") does not honour limit() if batchSize() is not specified

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Duplicate
    • Affects Version/s: 3.0.12
    • Fix Version/s: None
    • Component/s: Querying
    • Labels:
      None
    • Operating System:
      ALL

      Description

      On MongoDB 3.0 if limit(value) is specified and value > 101, the explain("allPlansExecution") will only work through 101 documents:

      > db.testcol.explain("allPlansExecution").find({a: {$gte: 200}}).limit(500)
      {
      	"queryPlanner" : {
      		"plannerVersion" : 1,
      		"namespace" : "test.testcol",
      		"indexFilterSet" : false,
      		"parsedQuery" : {
      			"a" : {
      				"$gte" : 200
      			}
      		},
      		"winningPlan" : {
      			"stage" : "LIMIT",
      			"limitAmount" : 0,
      			"inputStage" : {
      				"stage" : "FETCH",
      				"inputStage" : {
      					"stage" : "IXSCAN",
      					"keyPattern" : {
      						"a" : 1
      					},
      					"indexName" : "a_1",
      					"isMultiKey" : false,
      					"direction" : "forward",
      					"indexBounds" : {
      						"a" : [
      							"[200.0, inf.0]"
      						]
      					}
      				}
      			}
      		},
      		"rejectedPlans" : [ ]
      	},
      	"executionStats" : {
      		"executionSuccess" : true,
      		"nReturned" : 101,
      		"executionTimeMillis" : 0,
      		"totalKeysExamined" : 101,
      		"totalDocsExamined" : 101,
      		"executionStages" : {
      			"stage" : "LIMIT",
      			"nReturned" : 101,
      			"executionTimeMillisEstimate" : 0,
      			"works" : 102,
      			"advanced" : 101,
      			"needTime" : 0,
      			"needFetch" : 0,
      			"saveState" : 0,
      			"restoreState" : 0,
      			"isEOF" : 1,
      			"invalidates" : 0,
      			"limitAmount" : 0,
      			"inputStage" : {
      				"stage" : "FETCH",
      				"nReturned" : 101,
      				"executionTimeMillisEstimate" : 0,
      				"works" : 101,
      				"advanced" : 101,
      				"needTime" : 0,
      				"needFetch" : 0,
      				"saveState" : 0,
      				"restoreState" : 0,
      				"isEOF" : 0,
      				"invalidates" : 0,
      				"docsExamined" : 101,
      				"alreadyHasObj" : 0,
      				"inputStage" : {
      					"stage" : "IXSCAN",
      					"nReturned" : 101,
      					"executionTimeMillisEstimate" : 0,
      					"works" : 101,
      					"advanced" : 101,
      					"needTime" : 0,
      					"needFetch" : 0,
      					"saveState" : 0,
      					"restoreState" : 0,
      					"isEOF" : 0,
      					"invalidates" : 0,
      					"keyPattern" : {
      						"a" : 1
      					},
      					"indexName" : "a_1",
      					"isMultiKey" : false,
      					"direction" : "forward",
      					"indexBounds" : {
      						"a" : [
      							"[200.0, inf.0]"
      						]
      					},
      					"keysExamined" : 101,
      					"dupsTested" : 0,
      					"dupsDropped" : 0,
      					"seenInvalidated" : 0,
      					"matchTested" : 0
      				}
      			}
      		},
      		"allPlansExecution" : [ ]
      	},
      	"serverInfo" : {
      		"host" : "mubuntu",
      		"port" : 9088,
      		"version" : "3.0.9",
      		"gitVersion" : "20d60d3491908f1ae252fe452300de3978a040c7"
      	},
      	"ok" : 1
      }
      

      If batchSize(value) is specified, the limit(value) will take effect:

      > db.testcol.explain("allPlansExecution").find({a: {$gte: 200}}).limit(500).batchSize(500)
      {
      	"queryPlanner" : {
      		"plannerVersion" : 1,
      		"namespace" : "test.testcol",
      		"indexFilterSet" : false,
      		"parsedQuery" : {
      			"a" : {
      				"$gte" : 200
      			}
      		},
      		"winningPlan" : {
      			"stage" : "LIMIT",
      			"limitAmount" : 0,
      			"inputStage" : {
      				"stage" : "FETCH",
      				"inputStage" : {
      					"stage" : "IXSCAN",
      					"keyPattern" : {
      						"a" : 1
      					},
      					"indexName" : "a_1",
      					"isMultiKey" : false,
      					"direction" : "forward",
      					"indexBounds" : {
      						"a" : [
      							"[200.0, inf.0]"
      						]
      					}
      				}
      			}
      		},
      		"rejectedPlans" : [ ]
      	},
      	"executionStats" : {
      		"executionSuccess" : true,
      		"nReturned" : 500,
      		"executionTimeMillis" : 0,
      		"totalKeysExamined" : 500,
      		"totalDocsExamined" : 500,
      		"executionStages" : {
      			"stage" : "LIMIT",
      			"nReturned" : 500,
      			"executionTimeMillisEstimate" : 0,
      			"works" : 501,
      			"advanced" : 500,
      			"needTime" : 0,
      			"needFetch" : 0,
      			"saveState" : 3,
      			"restoreState" : 3,
      			"isEOF" : 1,
      			"invalidates" : 0,
      			"limitAmount" : 0,
      			"inputStage" : {
      				"stage" : "FETCH",
      				"nReturned" : 500,
      				"executionTimeMillisEstimate" : 0,
      				"works" : 500,
      				"advanced" : 500,
      				"needTime" : 0,
      				"needFetch" : 0,
      				"saveState" : 3,
      				"restoreState" : 3,
      				"isEOF" : 0,
      				"invalidates" : 0,
      				"docsExamined" : 500,
      				"alreadyHasObj" : 0,
      				"inputStage" : {
      					"stage" : "IXSCAN",
      					"nReturned" : 500,
      					"executionTimeMillisEstimate" : 0,
      					"works" : 500,
      					"advanced" : 500,
      					"needTime" : 0,
      					"needFetch" : 0,
      					"saveState" : 3,
      					"restoreState" : 3,
      					"isEOF" : 0,
      					"invalidates" : 0,
      					"keyPattern" : {
      						"a" : 1
      					},
      					"indexName" : "a_1",
      					"isMultiKey" : false,
      					"direction" : "forward",
      					"indexBounds" : {
      						"a" : [
      							"[200.0, inf.0]"
      						]
      					},
      					"keysExamined" : 500,
      					"dupsTested" : 0,
      					"dupsDropped" : 0,
      					"seenInvalidated" : 0,
      					"matchTested" : 0
      				}
      			}
      		},
      		"allPlansExecution" : [ ]
      	},
      	"serverInfo" : {
      		"host" : "mubuntu",
      		"port" : 9088,
      		"version" : "3.0.9",
      		"gitVersion" : "20d60d3491908f1ae252fe452300de3978a040c7"
      	},
      	"ok" : 1
      }
      

      Limit() works fine with explain("allPlansExecution") on 3.2.6.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              dmitry.ryabtsev Dmitry Ryabtsev
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: