summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/plan_ranker.cpp
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2015-08-10 14:45:12 -0400
committerDavid Storch <david.storch@10gen.com>2015-08-11 12:11:44 -0400
commit3f8b8b495fbe5303bb39dcd2ba5708275f482d2e (patch)
tree2cd0d817023c0ecf61d77db9f5adee91783aa731 /src/mongo/db/query/plan_ranker.cpp
parent8484342532a06f3c578047a446b87498669c7bac (diff)
downloadmongo-3f8b8b495fbe5303bb39dcd2ba5708275f482d2e.tar.gz
SERVER-19835 change SubplanStage to skip creation of a plan cache entry in edge cases
Since the SubplanStage does not benefit from the CachedPlanStage's replanning, it should not create a cache entry if there is a plan ranking tie or if zero results are produced during the plan ranking trial period.
Diffstat (limited to 'src/mongo/db/query/plan_ranker.cpp')
-rw-r--r--src/mongo/db/query/plan_ranker.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/mongo/db/query/plan_ranker.cpp b/src/mongo/db/query/plan_ranker.cpp
index 57717d2427b..b89b9fe3f70 100644
--- a/src/mongo/db/query/plan_ranker.cpp
+++ b/src/mongo/db/query/plan_ranker.cpp
@@ -31,7 +31,7 @@
#include "mongo/platform/basic.h"
#include <algorithm>
-#include <math.h>
+#include <cmath>
#include <vector>
#include <utility>
@@ -111,6 +111,14 @@ size_t PlanRanker::pickBestPlan(const vector<CandidatePlan>& candidates, PlanRan
std::stable_sort(
scoresAndCandidateindices.begin(), scoresAndCandidateindices.end(), scoreComparator);
+ // Determine whether plans tied for the win.
+ if (scoresAndCandidateindices.size() > 1U) {
+ double bestScore = scoresAndCandidateindices[0].first;
+ double runnerUpScore = scoresAndCandidateindices[1].first;
+ const double epsilon = 1e-10;
+ why->tieForBest = std::abs(bestScore - runnerUpScore) < epsilon;
+ }
+
// Update results in 'why'
// Stats and scores in 'why' are sorted in descending order by score.
why->stats.clear();