summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/explain.h
diff options
context:
space:
mode:
authorIan Boros <ian.boros@10gen.com>2017-12-08 13:58:22 -0500
committerIan Boros <ian.boros@10gen.com>2018-01-24 10:34:21 -0500
commitfec49f5e76d3b55a191c141974fdcf1aea7cdc96 (patch)
tree6215ad8f9309f4b63cde9b8c291c2d01b70d073a /src/mongo/db/query/explain.h
parentf3b39d5c157397887ecdfbb15f3097f8e8b179e4 (diff)
downloadmongo-fec49f5e76d3b55a191c141974fdcf1aea7cdc96.tar.gz
SERVER-29421 Make agg explain use outer PlanExecutor
Diffstat (limited to 'src/mongo/db/query/explain.h')
-rw-r--r--src/mongo/db/query/explain.h92
1 files changed, 73 insertions, 19 deletions
diff --git a/src/mongo/db/query/explain.h b/src/mongo/db/query/explain.h
index 8202cbfbeec..cb177321f1c 100644
--- a/src/mongo/db/query/explain.h
+++ b/src/mongo/db/query/explain.h
@@ -59,6 +59,9 @@ public:
*
* Does not take ownership of its arguments.
*
+ * The caller should hold at least an IS lock on the collection the that the query runs on,
+ * even if 'collection' is nullptr.
+ *
* If there is an error during the execution of the query, the error message and code are
* added to the "executionStats" section of the explain.
*/
@@ -66,6 +69,37 @@ public:
const Collection* collection,
ExplainOptions::Verbosity verbosity,
BSONObjBuilder* out);
+ /**
+ * Adds "queryPlanner" and "executionStats" (if requested in verbosity) fields to 'out'. Unlike
+ * the other overload of explainStages() above, this one does not add the "serverInfo" section.
+ *
+ * - 'exec' is the stage tree for the operation being explained.
+ * - 'collection' is the relevant collection. The caller should hold at least an IS lock on the
+ * collection which the query ran on, even 'collection' is nullptr.
+ * - 'verbosity' is the verbosity level of the explain.
+ * - 'executePlanStatus' is the status returned after executing the query (Status::OK if the
+ * query wasn't executed).
+ * - 'winningPlanTrialStats' is the stats of the winning plan during the trial period. May be
+ * nullptr.
+ * - 'out' is the builder for the explain output.
+ **/
+ static void explainStages(PlanExecutor* exec,
+ const Collection* collection,
+ ExplainOptions::Verbosity verbosity,
+ Status executePlanStatus,
+ PlanStageStats* winningPlanTrialStats,
+ BSONObjBuilder* out);
+
+ /**
+ * Gets explain BSON for the document sources contained by 'exec'. Use this function if you
+ * have a PlanExecutor whose root is a PipelineProxyStage and want to turn it into a human
+ * readable explain format.
+ *
+ * The explain information is generated with the level of detail specified by 'verbosity'.
+ **/
+ static void explainPipelineExecutor(PlanExecutor* exec,
+ ExplainOptions::Verbosity verbosity,
+ BSONObjBuilder* out);
/**
* Converts the PlanExecutor's winning plan stats tree to BSON and returns to the caller.
@@ -122,8 +156,31 @@ public:
*/
static void getSummaryStats(const PlanExecutor& exec, PlanSummaryStats* statsOut);
+ /**
+ * If exec's root stage is a MultiPlanStage, returns the stats for the trial period of of the
+ * winning plan. Otherwise, returns nullptr.
+ *
+ * Must be called _before_ calling PlanExecutor::executePlan() or PlanExecutor::getNext().
+ **/
+ static std::unique_ptr<PlanStageStats> getWinningPlanTrialStats(PlanExecutor* exec);
+
private:
/**
+ * Adds the 'queryPlanner' explain section to the BSON object being built
+ * by 'out'.
+ *
+ * This is a helper for generating explain BSON. It is used by explainStages(...).
+ *
+ * - 'exec' is the stage tree for the operation being explained.
+ * - 'collection' is the collection used in the operation. The caller should hold an IS lock on
+ * the collection which the query is for, even if 'collection' is nullptr.
+ * - 'out' is a builder for the explain output.
+ */
+ static void generatePlannerInfo(PlanExecutor* exec,
+ const Collection* collection,
+ BSONObjBuilder* out);
+
+ /**
* Private helper that does the heavy-lifting for the public statsToBSON(...) functions
* declared above.
*
@@ -135,22 +192,19 @@ private:
BSONObjBuilder* topLevelBob);
/**
- * Adds the 'queryPlanner' explain section to the BSON object being built
- * by 'out'.
+ * Adds the "executionStats" field to out. Assumes PlanExecutor::executePlan() has been called
+ * and that verbosity >= kExecStats.
*
- * This is a helper for generating explain BSON. It is used by explainStages(...).
+ * If verbosity >= kExecAllPlans, it will include the "allPlansExecution" array.
*
- * @param exec -- the stage tree for the operation being explained.
- * @param collection -- the collection used in the operation.
- * @param winnerStats -- the stats tree for the winning plan.
- * @param rejectedStats -- an array of stats trees, one per rejected plan
- */
- static void generatePlannerInfo(
- PlanExecutor* exec,
- const Collection* collection,
- PlanStageStats* winnerStats,
- const std::vector<std::unique_ptr<PlanStageStats>>& rejectedStats,
- BSONObjBuilder* out);
+ * - 'execPlanStatus' is the value returned after executing the query.
+ * - 'winningPlanTrialStats' may be nullptr.
+ **/
+ static void generateExecutionInfo(PlanExecutor* exec,
+ ExplainOptions::Verbosity verbosity,
+ Status executePlanStatus,
+ PlanStageStats* winningPlanTrialStats,
+ BSONObjBuilder* out);
/**
* Generates the execution stats section for the stats tree 'stats',
@@ -163,12 +217,12 @@ private:
*
* Stats are generated at the verbosity specified by 'verbosity'.
*
- * This is a helper for generating explain BSON. It is used by explainStages(...).
+ * This is a helper for generating explain BSON. It is used by generateExecutionInfo().
*/
- static void generateExecStats(PlanStageStats* stats,
- ExplainOptions::Verbosity verbosity,
- BSONObjBuilder* out,
- boost::optional<long long> totalTimeMillis);
+ static void generateSinglePlanExecutionInfo(const PlanStageStats* stats,
+ ExplainOptions::Verbosity verbosity,
+ boost::optional<long long> totalTimeMillis,
+ BSONObjBuilder* out);
/**
* Adds the 'serverInfo' explain section to the BSON object being build