[SERVER-24547] Explain("allPlansExecution") does not honour limit() if batchSize() is not specified Created: 14/Jun/16  Updated: 14/Jul/16  Resolved: 21/Jun/16

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 3.0.12
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Dmitry Ryabtsev 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-17577 Allow the query system to make use of... Closed
Operating System: ALL
Participants:

 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.



 Comments   
Comment by Ramon Fernandez Marina [ 21/Jun/16 ]

If I understand correctly, this was a limitation of the system in v3.0 that was fixed in SERVER-17577, so I'm going to mark this ticket as a duplicate of SERVER-17577. MongoDB 3.2 distinguish between limit and batchSize.

Regards,
Ramón.

Generated at Thu Feb 08 04:06:40 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.