Skip to content

Commit

Permalink
SERVER-20111 Plan summary should only include the winning plan
Browse files Browse the repository at this point in the history
  • Loading branch information
cswanson310 committed Oct 8, 2015
1 parent 4a42d61 commit 5aefcdd
Show file tree
Hide file tree
Showing 30 changed files with 190 additions and 86 deletions.
4 changes: 2 additions & 2 deletions src/mongo/db/commands/find_and_modify.cpp
Expand Up @@ -73,7 +73,7 @@ const UpdateStats* getUpdateStats(const PlanStageStats* stats) {
// The stats may refer to an update stage, or a projection stage wrapping an update stage.
if (StageType::STAGE_PROJECTION == stats->stageType) {
invariant(stats->children.size() == 1);
stats = stats->children[0];
stats = stats->children[0].get();
}

invariant(StageType::STAGE_UPDATE == stats->stageType);
Expand All @@ -84,7 +84,7 @@ const DeleteStats* getDeleteStats(const PlanStageStats* stats) {
// The stats may refer to a delete stage, or a projection stage wrapping a delete stage.
if (StageType::STAGE_PROJECTION == stats->stageType) {
invariant(stats->children.size() == 1);
stats = stats->children[0];
stats = stats->children[0].get();
}

invariant(StageType::STAGE_DELETE == stats->stageType);
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/exec/and_hash.cpp
Expand Up @@ -490,7 +490,7 @@ unique_ptr<PlanStageStats> AndHashStage::getStats() {
unique_ptr<PlanStageStats> ret = make_unique<PlanStageStats>(_commonStats, STAGE_AND_HASH);
ret->specific = make_unique<AndHashStats>(_specificStats);
for (size_t i = 0; i < _children.size(); ++i) {
ret->children.push_back(_children[i]->getStats().release());
ret->children.emplace_back(_children[i]->getStats());
}

return ret;
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/exec/and_sorted.cpp
Expand Up @@ -290,7 +290,7 @@ unique_ptr<PlanStageStats> AndSortedStage::getStats() {
unique_ptr<PlanStageStats> ret = make_unique<PlanStageStats>(_commonStats, STAGE_AND_SORTED);
ret->specific = make_unique<AndSortedStats>(_specificStats);
for (size_t i = 0; i < _children.size(); ++i) {
ret->children.push_back(_children[i]->getStats().release());
ret->children.emplace_back(_children[i]->getStats());
}

return ret;
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/exec/cached_plan.cpp
Expand Up @@ -319,7 +319,7 @@ std::unique_ptr<PlanStageStats> CachedPlanStage::getStats() {
std::unique_ptr<PlanStageStats> ret =
stdx::make_unique<PlanStageStats>(_commonStats, STAGE_CACHED_PLAN);
ret->specific = stdx::make_unique<CachedPlanStats>(_specificStats);
ret->children.push_back(child()->getStats().release());
ret->children.emplace_back(child()->getStats());

return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/exec/count.cpp
Expand Up @@ -167,7 +167,7 @@ unique_ptr<PlanStageStats> CountStage::getStats() {
unique_ptr<PlanStageStats> ret = make_unique<PlanStageStats>(_commonStats, STAGE_COUNT);
ret->specific = make_unique<CountStats>(_specificStats);
if (!_children.empty()) {
ret->children.push_back(child()->getStats().release());
ret->children.emplace_back(child()->getStats());
}
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/exec/delete.cpp
Expand Up @@ -266,7 +266,7 @@ unique_ptr<PlanStageStats> DeleteStage::getStats() {
_commonStats.isEOF = isEOF();
unique_ptr<PlanStageStats> ret = make_unique<PlanStageStats>(_commonStats, STAGE_DELETE);
ret->specific = make_unique<DeleteStats>(_specificStats);
ret->children.push_back(child()->getStats().release());
ret->children.emplace_back(child()->getStats());
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/exec/fetch.cpp
Expand Up @@ -237,7 +237,7 @@ unique_ptr<PlanStageStats> FetchStage::getStats() {

unique_ptr<PlanStageStats> ret = make_unique<PlanStageStats>(_commonStats, STAGE_FETCH);
ret->specific = make_unique<FetchStats>(_specificStats);
ret->children.push_back(child()->getStats().release());
ret->children.emplace_back(child()->getStats());
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/exec/group.cpp
Expand Up @@ -290,7 +290,7 @@ unique_ptr<PlanStageStats> GroupStage::getStats() {
_commonStats.isEOF = isEOF();
unique_ptr<PlanStageStats> ret = make_unique<PlanStageStats>(_commonStats, STAGE_GROUP);
ret->specific = make_unique<GroupStats>(_specificStats);
ret->children.push_back(child()->getStats().release());
ret->children.emplace_back(child()->getStats());
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/exec/keep_mutations.cpp
Expand Up @@ -125,7 +125,7 @@ unique_ptr<PlanStageStats> KeepMutationsStage::getStats() {
_commonStats.isEOF = isEOF();
unique_ptr<PlanStageStats> ret =
make_unique<PlanStageStats>(_commonStats, STAGE_KEEP_MUTATIONS);
ret->children.push_back(child()->getStats().release());
ret->children.emplace_back(child()->getStats());
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/exec/limit.cpp
Expand Up @@ -99,7 +99,7 @@ unique_ptr<PlanStageStats> LimitStage::getStats() {
_commonStats.isEOF = isEOF();
unique_ptr<PlanStageStats> ret = make_unique<PlanStageStats>(_commonStats, STAGE_LIMIT);
ret->specific = make_unique<LimitStats>(_specificStats);
ret->children.push_back(child()->getStats().release());
ret->children.emplace_back(child()->getStats());
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/exec/merge_sort.cpp
Expand Up @@ -254,7 +254,7 @@ unique_ptr<PlanStageStats> MergeSortStage::getStats() {
unique_ptr<PlanStageStats> ret = make_unique<PlanStageStats>(_commonStats, STAGE_SORT_MERGE);
ret->specific = make_unique<MergeSortStats>(_specificStats);
for (size_t i = 0; i < _children.size(); ++i) {
ret->children.push_back(_children[i]->getStats().release());
ret->children.emplace_back(_children[i]->getStats());
}
return ret;
}
Expand Down
32 changes: 6 additions & 26 deletions src/mongo/db/exec/multi_plan.cpp
Expand Up @@ -342,24 +342,6 @@ Status MultiPlanStage::pickBestPlan(PlanYieldPolicy* yieldPolicy) {
return Status::OK();
}

vector<PlanStageStats*> MultiPlanStage::generateCandidateStats() {
OwnedPointerVector<PlanStageStats> candidateStats;

for (size_t ix = 0; ix < _candidates.size(); ix++) {
if (ix == (size_t)_bestPlanIdx) {
continue;
}
if (ix == (size_t)_backupPlanIdx) {
continue;
}

unique_ptr<PlanStageStats> stats = _candidates[ix].root->getStats();
candidateStats.push_back(stats.release());
}

return candidateStats.release();
}

bool MultiPlanStage::workAllPlans(size_t numResults, PlanYieldPolicy* yieldPolicy) {
bool doneWorking = false;

Expand Down Expand Up @@ -498,15 +480,13 @@ QuerySolution* MultiPlanStage::bestSolution() {
}

unique_ptr<PlanStageStats> MultiPlanStage::getStats() {
if (bestPlanChosen()) {
return _candidates[_bestPlanIdx].root->getStats();
}
if (hasBackupPlan()) {
return _candidates[_backupPlanIdx].root->getStats();
}
_commonStats.isEOF = isEOF();

return make_unique<PlanStageStats>(_commonStats, STAGE_MULTI_PLAN);
unique_ptr<PlanStageStats> ret = make_unique<PlanStageStats>(_commonStats, STAGE_MULTI_PLAN);
ret->specific = make_unique<MultiPlanStats>(_specificStats);
for (auto&& child : _children) {
ret->children.emplace_back(child->getStats());
}
return ret;
}

const SpecificStats* MultiPlanStage::getSpecificStats() const {
Expand Down
6 changes: 0 additions & 6 deletions src/mongo/db/exec/multi_plan.h
Expand Up @@ -150,12 +150,6 @@ class MultiPlanStage final : public PlanStage {
// Used by explain.
//

/**
* Gathers execution stats for all losing plans. Caller takes ownership of
* all pointers in the returned vector.
*/
std::vector<PlanStageStats*> generateCandidateStats();

static const char* kStageType;

private:
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/exec/near.cpp
Expand Up @@ -313,7 +313,7 @@ unique_ptr<PlanStageStats> NearStage::getStats() {
unique_ptr<PlanStageStats> ret = make_unique<PlanStageStats>(_commonStats, _stageType);
ret->specific.reset(_specificStats.clone());
for (size_t i = 0; i < _childrenIntervals.size(); ++i) {
ret->children.push_back(_childrenIntervals[i]->covering->getStats().release());
ret->children.emplace_back(_childrenIntervals[i]->covering->getStats());
}
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/exec/or.cpp
Expand Up @@ -162,7 +162,7 @@ unique_ptr<PlanStageStats> OrStage::getStats() {
unique_ptr<PlanStageStats> ret = make_unique<PlanStageStats>(_commonStats, STAGE_OR);
ret->specific = make_unique<OrStats>(_specificStats);
for (size_t i = 0; i < _children.size(); ++i) {
ret->children.push_back(_children[i]->getStats().release());
ret->children.emplace_back(_children[i]->getStats());
}

return ret;
Expand Down
10 changes: 2 additions & 8 deletions src/mongo/db/exec/plan_stats.h
Expand Up @@ -106,12 +106,6 @@ struct CommonStats {
struct PlanStageStats {
PlanStageStats(const CommonStats& c, StageType t) : stageType(t), common(c) {}

~PlanStageStats() {
for (size_t i = 0; i < children.size(); ++i) {
delete children[i];
}
}

/**
* Make a deep copy.
*/
Expand All @@ -122,7 +116,7 @@ struct PlanStageStats {
}
for (size_t i = 0; i < children.size(); ++i) {
invariant(children[i]);
stats->children.push_back(children[i]->clone());
stats->children.emplace_back(children[i]->clone());
}
return stats;
}
Expand All @@ -137,7 +131,7 @@ struct PlanStageStats {
std::unique_ptr<SpecificStats> specific;

// The stats of the node's children.
std::vector<PlanStageStats*> children;
std::vector<std::unique_ptr<PlanStageStats>> children;

private:
MONGO_DISALLOW_COPYING(PlanStageStats);
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/exec/projection.cpp
Expand Up @@ -244,7 +244,7 @@ unique_ptr<PlanStageStats> ProjectionStage::getStats() {
projStats->projObj = _projObj;
ret->specific = std::move(projStats);

ret->children.push_back(child()->getStats().release());
ret->children.emplace_back(child()->getStats());
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/exec/shard_filter.cpp
Expand Up @@ -136,7 +136,7 @@ unique_ptr<PlanStageStats> ShardFilterStage::getStats() {
_commonStats.isEOF = isEOF();
unique_ptr<PlanStageStats> ret =
make_unique<PlanStageStats>(_commonStats, STAGE_SHARDING_FILTER);
ret->children.push_back(child()->getStats().release());
ret->children.emplace_back(child()->getStats());
ret->specific = make_unique<ShardingFilterStats>(_specificStats);
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/exec/skip.cpp
Expand Up @@ -102,7 +102,7 @@ unique_ptr<PlanStageStats> SkipStage::getStats() {
_specificStats.skip = _toSkip;
unique_ptr<PlanStageStats> ret = make_unique<PlanStageStats>(_commonStats, STAGE_SKIP);
ret->specific = make_unique<SkipStats>(_specificStats);
ret->children.push_back(child()->getStats().release());
ret->children.emplace_back(child()->getStats());
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/exec/sort.cpp
Expand Up @@ -239,7 +239,7 @@ unique_ptr<PlanStageStats> SortStage::getStats() {

unique_ptr<PlanStageStats> ret = make_unique<PlanStageStats>(_commonStats, STAGE_SORT);
ret->specific = make_unique<SortStats>(_specificStats);
ret->children.push_back(child()->getStats().release());
ret->children.emplace_back(child()->getStats());
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/exec/sort_key_generator.cpp
Expand Up @@ -315,7 +315,7 @@ PlanStage::StageState SortKeyGeneratorStage::work(WorkingSetID* out) {

std::unique_ptr<PlanStageStats> SortKeyGeneratorStage::getStats() {
auto ret = stdx::make_unique<PlanStageStats>(_commonStats, STAGE_SORT_KEY_GENERATOR);
ret->children.push_back(child()->getStats().release());
ret->children.emplace_back(child()->getStats());
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/exec/subplan.cpp
Expand Up @@ -532,7 +532,7 @@ PlanStage::StageState SubplanStage::work(WorkingSetID* out) {
unique_ptr<PlanStageStats> SubplanStage::getStats() {
_commonStats.isEOF = isEOF();
unique_ptr<PlanStageStats> ret = make_unique<PlanStageStats>(_commonStats, STAGE_SUBPLAN);
ret->children.push_back(child()->getStats().release());
ret->children.emplace_back(child()->getStats());
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/exec/text.cpp
Expand Up @@ -106,7 +106,7 @@ unique_ptr<PlanStageStats> TextStage::getStats() {

unique_ptr<PlanStageStats> ret = make_unique<PlanStageStats>(_commonStats, STAGE_TEXT);
ret->specific = make_unique<TextStats>(_specificStats);
ret->children.push_back(child()->getStats().release());
ret->children.emplace_back(child()->getStats());
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/exec/text_match.cpp
Expand Up @@ -65,7 +65,7 @@ std::unique_ptr<PlanStageStats> TextMatchStage::getStats() {

unique_ptr<PlanStageStats> ret = make_unique<PlanStageStats>(_commonStats, STAGE_TEXT_MATCH);
ret->specific = make_unique<TextMatchStats>(_specificStats);
ret->children.push_back(child()->getStats().release());
ret->children.emplace_back(child()->getStats());

return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions src/mongo/db/exec/text_or.cpp
Expand Up @@ -122,8 +122,8 @@ std::unique_ptr<PlanStageStats> TextOrStage::getStats() {
unique_ptr<PlanStageStats> ret = make_unique<PlanStageStats>(_commonStats, STAGE_TEXT_OR);
ret->specific = make_unique<TextOrStats>(_specificStats);

for (auto& child : _children) {
ret->children.push_back(child->getStats().release());
for (auto&& child : _children) {
ret->children.emplace_back(child->getStats());
}

return ret;
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/exec/update.cpp
Expand Up @@ -1000,7 +1000,7 @@ unique_ptr<PlanStageStats> UpdateStage::getStats() {
_commonStats.isEOF = isEOF();
unique_ptr<PlanStageStats> ret = make_unique<PlanStageStats>(_commonStats, STAGE_UPDATE);
ret->specific = make_unique<UpdateStats>(_specificStats);
ret->children.push_back(child()->getStats().release());
ret->children.emplace_back(child()->getStats());
return ret;
}

Expand Down

0 comments on commit 5aefcdd

Please sign in to comment.