[SERVER-21498] Explain "allPlansExecution" section reports "saveState"/"restoreState" counts incorrectly for the rejected plans Created: 17/Nov/15  Updated: 22/Feb/16  Resolved: 01/Feb/16

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 3.0.7, 3.2.0-rc2
Fix Version/s: 3.3.2

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

Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: QuInt E (01/11/16), Query F (02/01/16)
Participants:

 Description   

Repro as follows:

db.c.drop();
for (var i = 0; i < 10000; ++i) { db.c.insert({_id: i, a: i, b: i}); }
db.c.ensureIndex({a: 1});
db.c.ensureIndex({b: 1});
db.c.find({a: {$gte: 0}, b: {$gte: 0}}).explain('allPlansExecution');

The "allPlansExecution" section of the explain should look something like this:

		"allPlansExecution" : [
			{
				"nReturned" : 101,
				"executionTimeMillisEstimate" : 10,
				"totalKeysExamined" : 101,
				"totalDocsExamined" : 101,
				"executionStages" : {
					"stage" : "FETCH",
					"filter" : {
						"b" : {
							"$gte" : 0
						}
					},
					"nReturned" : 101,
					"executionTimeMillisEstimate" : 10,
					"works" : 101,
					"advanced" : 101,
					"needTime" : 0,
					"needYield" : 0,
					"saveState" : 79,
					"restoreState" : 79,
					"isEOF" : 0,
					"invalidates" : 0,
					"docsExamined" : 101,
					"alreadyHasObj" : 0,
					"inputStage" : {
						"stage" : "IXSCAN",
						"nReturned" : 101,
						"executionTimeMillisEstimate" : 0,
						"works" : 101,
						"advanced" : 101,
						"needTime" : 0,
						"needYield" : 0,
						"saveState" : 79,
						"restoreState" : 79,
						"isEOF" : 0,
						"invalidates" : 0,
						"keyPattern" : {
							"a" : 1
						},
						"indexName" : "a_1",
						"isMultiKey" : false,
						"isUnique" : false,
						"isSparse" : false,
						"isPartial" : false,
						"indexVersion" : 1,
						"direction" : "forward",
						"indexBounds" : {
							"a" : [
								"[0.0, inf.0]"
							]
						},
						"keysExamined" : 101,
						"dupsTested" : 0,
						"dupsDropped" : 0,
						"seenInvalidated" : 0
					}
				}
			},
			{
				"nReturned" : 101,
				"executionTimeMillisEstimate" : 0,
				"totalKeysExamined" : 101,
				"totalDocsExamined" : 101,
				"executionStages" : {
					"stage" : "FETCH",
					"filter" : {
						"a" : {
							"$gte" : 0
						}
					},
					"nReturned" : 101,
					"executionTimeMillisEstimate" : 0,
					"works" : 101,
					"advanced" : 101,
					"needTime" : 0,
					"needYield" : 0,
					"saveState" : 1,
					"restoreState" : 1,
					"isEOF" : 0,
					"invalidates" : 0,
					"docsExamined" : 101,
					"alreadyHasObj" : 0,
					"inputStage" : {
						"stage" : "IXSCAN",
						"nReturned" : 101,
						"executionTimeMillisEstimate" : 0,
						"works" : 101,
						"advanced" : 101,
						"needTime" : 0,
						"needYield" : 0,
						"saveState" : 1,
						"restoreState" : 1,
						"isEOF" : 0,
						"invalidates" : 0,
						"keyPattern" : {
							"b" : 1
						},
						"indexName" : "b_1",
						"isMultiKey" : false,
						"isUnique" : false,
						"isSparse" : false,
						"isPartial" : false,
						"indexVersion" : 1,
						"direction" : "forward",
						"indexBounds" : {
							"b" : [
								"[0.0, inf.0]"
							]
						},
						"keysExamined" : 101,
						"dupsTested" : 0,
						"dupsDropped" : 0,
						"seenInvalidated" : 0
					}
				}
			}
		]

Note that the second plan in the "allPlansExecution" array has saveState/restoreState counts of 1, whereas the first plan has saveState/restoreState counts of 79. The value of 79 is incorrect: it counts the number of times that the query yielded during its complete execution. However, this should report only the number of times that the candidate yielded during the plan ranking trial period. Although the rejected plans are saved and restored while the winning plan is executed (after being rejected by the plan ranker), these save/restore pairs should not be reported in the allPlansExecution output.



 Comments   
Comment by Githook User [ 01/Feb/16 ]

Author:

{u'username': u'cswanson310', u'name': u'Charlie Swanson', u'email': u'charlie.swanson@mongodb.com'}

Message: SERVER-21498 Fix stats reporting of losing plans.

Ensures fields such as 'saveState' and 'restoreState' contained in the
'allPlansExecution' section reflect the statistics captured during the
trial period, not the execution period.
Branch: master
https://github.com/mongodb/mongo/commit/9fe5143e053a967186c95586c2435107fbe48022

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