summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/plan_ranker.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/query/plan_ranker.cpp')
-rw-r--r--src/mongo/db/query/plan_ranker.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/mongo/db/query/plan_ranker.cpp b/src/mongo/db/query/plan_ranker.cpp
index e2ac018a67e..01dc6d3cd90 100644
--- a/src/mongo/db/query/plan_ranker.cpp
+++ b/src/mongo/db/query/plan_ranker.cpp
@@ -27,6 +27,7 @@
*/
#include <algorithm>
+#include <math.h>
#include <vector>
#include <utility>
@@ -107,6 +108,14 @@ namespace mongo {
std::stable_sort(scoresAndCandidateindices.begin(), scoresAndCandidateindices.end(),
scoreComparator);
+ // Determine whether plans tied for the win.
+ if (scoresAndCandidateindices.size() > 1) {
+ double bestScore = scoresAndCandidateindices[0].first;
+ double runnerUpScore = scoresAndCandidateindices[1].first;
+ static const double epsilon = 1e-10;
+ why->tieForBest = fabs(bestScore - runnerUpScore) < epsilon;
+ }
+
// Update results in 'why'
// Stats and scores in 'why' are sorted in descending order by score.
why->stats.clear();