summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/plan_ranker.cpp
diff options
context:
space:
mode:
authorXiangyu Yao <xiangyu.yao@mongodb.com>2019-07-10 18:38:15 -0400
committerXiangyu Yao <xiangyu.yao@mongodb.com>2019-07-10 18:38:15 -0400
commit135c88363bdb5e7b353825f3fec4aa0d7db80571 (patch)
tree2c0d9dfc909ae4a68085792b719ff8a0fdc9f454 /src/mongo/db/query/plan_ranker.cpp
parentcb3b6c8b2a28190560906db4d78ef833eec44425 (diff)
downloadmongo-135c88363bdb5e7b353825f3fec4aa0d7db80571.tar.gz
Revert "SERVER-41279 Eliminate failed plans from consideration during query planning"
This reverts commit 6bba6446e632b557ccc03834d4d48e90336679fc.
Diffstat (limited to 'src/mongo/db/query/plan_ranker.cpp')
-rw-r--r--src/mongo/db/query/plan_ranker.cpp52
1 files changed, 17 insertions, 35 deletions
diff --git a/src/mongo/db/query/plan_ranker.cpp b/src/mongo/db/query/plan_ranker.cpp
index 2970428be3b..ff2e636a28a 100644
--- a/src/mongo/db/query/plan_ranker.cpp
+++ b/src/mongo/db/query/plan_ranker.cpp
@@ -65,9 +65,10 @@ using std::endl;
using std::vector;
// static
-StatusWith<std::unique_ptr<PlanRankingDecision>> PlanRanker::pickBestPlan(
- const vector<CandidatePlan>& candidates) {
+size_t PlanRanker::pickBestPlan(const vector<CandidatePlan>& candidates, PlanRankingDecision* why) {
invariant(!candidates.empty());
+ invariant(why);
+
// A plan that hits EOF is automatically scored above
// its peers. If multiple plans hit EOF during the same
// set of round-robin calls to work(), then all such plans
@@ -88,44 +89,28 @@ StatusWith<std::unique_ptr<PlanRankingDecision>> PlanRanker::pickBestPlan(
// Holds (score, candidateInndex).
// Used to derive scores and candidate ordering.
vector<std::pair<double, size_t>> scoresAndCandidateindices;
- vector<size_t> failed;
// Compute score for each tree. Record the best.
for (size_t i = 0; i < statTrees.size(); ++i) {
- if (!candidates[i].failed) {
- LOG(5) << "Scoring plan " << i << ":" << endl
- << redact(candidates[i].solution->toString()) << "Stats:\n"
- << redact(Explain::statsToBSON(*statTrees[i]).jsonString(Strict, true));
- LOG(2) << "Scoring query plan: " << Explain::getPlanSummary(candidates[i].root)
- << " planHitEOF=" << statTrees[i]->common.isEOF;
-
- double score = scoreTree(statTrees[i].get());
- LOG(5) << "score = " << score;
- if (statTrees[i]->common.isEOF) {
- LOG(5) << "Adding +" << eofBonus << " EOF bonus to score.";
- score += 1;
- }
-
- scoresAndCandidateindices.push_back(std::make_pair(score, i));
- } else {
- failed.push_back(i);
- LOG(2) << "Not scording plan: " << Explain::getPlanSummary(candidates[i].root)
- << " because the plan failed.";
+ LOG(5) << "Scoring plan " << i << ":" << endl
+ << redact(candidates[i].solution->toString()) << "Stats:\n"
+ << redact(Explain::statsToBSON(*statTrees[i]).jsonString(Strict, true));
+ LOG(2) << "Scoring query plan: " << Explain::getPlanSummary(candidates[i].root)
+ << " planHitEOF=" << statTrees[i]->common.isEOF;
+
+ double score = scoreTree(statTrees[i].get());
+ LOG(5) << "score = " << score;
+ if (statTrees[i]->common.isEOF) {
+ LOG(5) << "Adding +" << eofBonus << " EOF bonus to score.";
+ score += 1;
}
- }
-
- // If there isn't a viable plan we should error.
- if (scoresAndCandidateindices.size() == 0U) {
- return {ErrorCodes::Error(31157),
- "No viable plan was found because all candidate plans failed."};
+ scoresAndCandidateindices.push_back(std::make_pair(score, i));
}
// Sort (scores, candidateIndex). Get best child and populate candidate ordering.
std::stable_sort(
scoresAndCandidateindices.begin(), scoresAndCandidateindices.end(), scoreComparator);
- auto why = std::make_unique<PlanRankingDecision>();
-
// Determine whether plans tied for the win.
if (scoresAndCandidateindices.size() > 1U) {
double bestScore = scoresAndCandidateindices[0].first;
@@ -139,7 +124,6 @@ StatusWith<std::unique_ptr<PlanRankingDecision>> PlanRanker::pickBestPlan(
why->stats.clear();
why->scores.clear();
why->candidateOrder.clear();
- why->failedCandidates = std::move(failed);
for (size_t i = 0; i < scoresAndCandidateindices.size(); ++i) {
double score = scoresAndCandidateindices[i].first;
size_t candidateIndex = scoresAndCandidateindices[i].second;
@@ -171,11 +155,9 @@ StatusWith<std::unique_ptr<PlanRankingDecision>> PlanRanker::pickBestPlan(
why->scores.push_back(score);
why->candidateOrder.push_back(candidateIndex);
}
- for (auto& i : why->failedCandidates) {
- why->stats.push_back(std::move(statTrees[i]));
- }
- return StatusWith<std::unique_ptr<PlanRankingDecision>>(std::move(why));
+ size_t bestChild = scoresAndCandidateindices[0].second;
+ return bestChild;
}
// TODO: Move this out. This is a signal for ranking but will become its own complicated