summaryrefslogtreecommitdiff
path: root/src/mongo/db/query
diff options
context:
space:
mode:
authorJames Wahlin <james.wahlin@10gen.com>2016-02-25 13:53:42 -0500
committerRamon Fernandez <ramon@mongodb.com>2016-02-26 11:16:04 -0500
commit0efb73015daca3cbfcdfca3a8e06087bcfed3d6a (patch)
tree4963a025ddd4a6cee3ccbe174fba26125a0031b8 /src/mongo/db/query
parent5149712212bd52eec0d511779427fd95781d7838 (diff)
downloadmongo-0efb73015daca3cbfcdfca3a8e06087bcfed3d6a.tar.gz
SERVER-22425 execStats in system.profile should only report winning plan
(cherry picked from commit e63efab6aa0d0983e99cf2e2fb193a8d481500d3)
Diffstat (limited to 'src/mongo/db/query')
-rw-r--r--src/mongo/db/query/explain.cpp17
-rw-r--r--src/mongo/db/query/explain.h11
-rw-r--r--src/mongo/db/query/explain_common.h4
-rw-r--r--src/mongo/db/query/find.cpp9
4 files changed, 33 insertions, 8 deletions
diff --git a/src/mongo/db/query/explain.cpp b/src/mongo/db/query/explain.cpp
index ead46646ced..9d8be0587d1 100644
--- a/src/mongo/db/query/explain.cpp
+++ b/src/mongo/db/query/explain.cpp
@@ -496,6 +496,23 @@ void Explain::statsToBSON(const PlanStageStats& stats,
}
// static
+BSONObj Explain::getWinningPlanStats(const PlanExecutor* exec) {
+ BSONObjBuilder bob;
+ getWinningPlanStats(exec, &bob);
+ return bob.obj();
+}
+
+// static
+void Explain::getWinningPlanStats(const PlanExecutor* exec, BSONObjBuilder* bob) {
+ MultiPlanStage* mps = getMultiPlanStage(exec->getRootStage());
+ unique_ptr<PlanStageStats> winningStats(
+ mps ? std::move(mps->getStats()->children[mps->bestPlanIdx()])
+ : std::move(exec->getRootStage()->getStats()));
+
+ statsToBSON(*winningStats, ExplainCommon::EXEC_STATS, bob, bob);
+}
+
+// static
void Explain::generatePlannerInfo(PlanExecutor* exec,
PlanStageStats* winnerStats,
const vector<unique_ptr<PlanStageStats>>& rejectedStats,
diff --git a/src/mongo/db/query/explain.h b/src/mongo/db/query/explain.h
index 069d89d7cb4..2fd6314edfd 100644
--- a/src/mongo/db/query/explain.h
+++ b/src/mongo/db/query/explain.h
@@ -101,6 +101,17 @@ public:
BSONObjBuilder* out);
/**
+ * Converts the PlanExecutor's winning plan stats tree to BSON and returns to the caller.
+ */
+ static BSONObj getWinningPlanStats(const PlanExecutor* exec);
+
+ /**
+ * Converts the PlanExecutor's winning plan stats tree to BSON and returns the result through
+ * the out-parameter 'bob'.
+ */
+ static void getWinningPlanStats(const PlanExecutor* exec, BSONObjBuilder* bob);
+
+ /**
* Converts the stats tree 'stats' into a corresponding BSON object containing
* explain information.
*
diff --git a/src/mongo/db/query/explain_common.h b/src/mongo/db/query/explain_common.h
index f76c6d348cf..750f207a2a5 100644
--- a/src/mongo/db/query/explain_common.h
+++ b/src/mongo/db/query/explain_common.h
@@ -53,8 +53,8 @@ public:
// execution tree. String alias is "execStats".
EXEC_STATS = 1,
- // At this second-highest verbosity level, we generate the execution stats for each
- // rejected plan as well as the winning plan. String alias is "allPlansExecution".
+ // At this verbosity level, we generate the execution stats for each rejected plan as
+ // well as the winning plan. String alias is "allPlansExecution".
EXEC_ALL_PLANS = 2,
};
diff --git a/src/mongo/db/query/find.cpp b/src/mongo/db/query/find.cpp
index 89c356a3fe8..2aa710611b4 100644
--- a/src/mongo/db/query/find.cpp
+++ b/src/mongo/db/query/find.cpp
@@ -176,9 +176,8 @@ void endQueryOp(OperationContext* txn,
// Set debug information for consumption by the profiler only.
if (dbProfilingLevel > 0) {
// Get BSON stats.
- unique_ptr<PlanStageStats> execStats(exec.getStats());
BSONObjBuilder statsBob;
- Explain::statsToBSON(*execStats, &statsBob);
+ Explain::getWinningPlanStats(&exec, &statsBob);
curop->debug().execStats.set(statsBob.obj());
// Replace exec stats with plan summary if stats cannot fit into CachedBSONObj.
@@ -235,8 +234,7 @@ void generateBatch(int ntoreturn,
if (PlanExecutor::DEAD == *state || PlanExecutor::FAILURE == *state) {
// Propagate this error to caller.
- const unique_ptr<PlanStageStats> stats(exec->getStats());
- error() << "getMore executor error, stats: " << Explain::statsToBSON(*stats);
+ error() << "getMore executor error, stats: " << Explain::getWinningPlanStats(exec);
uasserted(17406, "getMore executor error: " + WorkingSetCommon::toStatusString(obj));
}
}
@@ -619,9 +617,8 @@ std::string runQuery(OperationContext* txn,
// Caller expects exceptions thrown in certain cases.
if (PlanExecutor::FAILURE == state || PlanExecutor::DEAD == state) {
- const unique_ptr<PlanStageStats> stats(exec->getStats());
error() << "Plan executor error during find: " << PlanExecutor::statestr(state)
- << ", stats: " << Explain::statsToBSON(*stats);
+ << ", stats: " << Explain::getWinningPlanStats(exec.get());
uasserted(17144, "Executor error: " + WorkingSetCommon::toStatusString(obj));
}