[SERVER-15924] planCacheListPlans command can report incorrect averageScore and stdDevScore in "feedback" section Created: 03/Nov/14  Updated: 14/Apr/15  Resolved: 14/Apr/15

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.6.5, 2.7.8
Fix Version/s: None

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

Issue Links:
Related
is related to SERVER-15124 Eviction algorithm for bad cached pla... Closed
is related to SERVER-15225 CachedPlanStage should execute for tr... Closed
Operating System: ALL
Steps To Reproduce:

> t.drop();
> for (var i = 0; i < 20; i++) { t.insert({_id: i, a: i, b: 1}); }
> t.ensureIndex({a: 1});
> t.ensureIndex({b: 1});
 
// Run a query twice. The first run causes a plan to be cached. The second
// adds a feedback entry.
> t.find({a: {$lt: 3}, b: 1}).next()
> t.find({a: {$lt: 3}, b: 1}).next()
 
// Get the plan cache entry.
> t.getPlanCache().getPlansByQuery({a: {$lt: 3}, b: 1})
[
   ...
		"feedback" : {
			"nfeedback" : 1,
			"averageScore" : 0, // XXX: incorrect!
			"stdDevScore" : 0, // XXX: incorrect!
			"scores" : [
				{
					"score" : 1.7503
				}
			]
		},
		"filterSet" : false
	},
   ...
]
 
// After running the query a few more times, the average and std dev are computed.
> for (var i = 0; i < 20; i++) { t.find({a: {$lt: 3}, b: 1}).next(); }
> t.getPlanCache().getPlansByQuery({a: {$lt: 3}, b: 1})
[
   ...
		"feedback" : {
			"nfeedback" : 20,
			"averageScore" : 1.7502999999999997,
			"stdDevScore" : 2.278129578503827e-16,
			"scores" : [
				{
					"score" : 1.7503
				},
				{
					"score" : 1.7503
				},
				{
					"score" : 1.7503
				},
				{
					"score" : 1.7503
				},
				{
					"score" : 1.7503
				},
				{
					"score" : 1.7503
				},
				{
					"score" : 1.7503
				},
				{
					"score" : 1.7503
				},
				{
					"score" : 1.7503
				},
				{
					"score" : 1.7503
				},
				{
					"score" : 1.7503
				},
				{
					"score" : 1.7503
				},
				{
					"score" : 1.7503
				},
				{
					"score" : 1.7503
				},
				{
					"score" : 1.7503
				},
				{
					"score" : 1.7503
				},
				{
					"score" : 1.7503
				},
				{
					"score" : 1.7503
				},
				{
					"score" : 1.7503
				},
				{
					"score" : 1.7503
				}
			]
		},
   ...
]

Participants:

 Description   

The planCacheListPlans command, also exposed via the getPlansByQuery shell helper displays the plan that has been cached for a particular query shape. Each time that a cached plan is reused for another instance of the query shape, stats about the performance of the query are tracked. These stats are used to update the "feedback" section of the planCacheListPlans output. This section shows how many times the cached plan was used, as well as the scores for each use of the plan.

The "averageScore" and "stdDevScore" fields are statistics taken over the history of scores for each run of the cached plan. These statistics are first computed once the plan has been used some small number of times, n. (Currently n defaults to 20.) The list plans command, however, reports the average and standard deviation as 0 even before these values have been computed. See "Steps to Reproduce" for details.



 Comments   
Comment by David Storch [ 14/Apr/15 ]

The {[avgScore}} and stdDevScore fields were removed from the plan cache commands output as part of SERVER-15225 (commit 81a1f70b87b3f37), so this ticket is no longer relevant. Closing as Gone Away.

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