summaryrefslogtreecommitdiff
path: root/jstests/libs/analyze_plan.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/libs/analyze_plan.js')
-rw-r--r--jstests/libs/analyze_plan.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/jstests/libs/analyze_plan.js b/jstests/libs/analyze_plan.js
index 29244576ab4..8104cf1f8c9 100644
--- a/jstests/libs/analyze_plan.js
+++ b/jstests/libs/analyze_plan.js
@@ -58,6 +58,22 @@ function getPlanStage(root, stage) {
}
/**
+ * Returns the set of rejected plans from the given replset or sharded explain output.
+ */
+function getRejectedPlans(root) {
+ if (root.queryPlanner.winningPlan.hasOwnProperty("shards")) {
+ const rejectedPlans = [];
+ for (let shard of root.queryPlanner.winningPlan.shards) {
+ for (let rejectedPlan of shard.rejectedPlans) {
+ rejectedPlans.push(Object.assign({shardName: shard.shardName}, rejectedPlan));
+ }
+ }
+ return rejectedPlans;
+ }
+ return root.queryPlanner.rejectedPlans;
+}
+
+/**
* Given the root stage of explain's JSON representation of a query plan ('root'), returns true if
* the query planner reports at least one rejected alternative plan, and false otherwise.
*/
@@ -100,6 +116,22 @@ function hasRejectedPlans(root) {
}
/**
+ * Returns an array of execution stages from the given replset or sharded explain output.
+ */
+function getExecutionStages(root) {
+ if (root.executionStats.executionStages.hasOwnProperty("shards")) {
+ const executionStages = [];
+ for (let shard of root.executionStats.executionStages.shards) {
+ executionStages.push(Object.assign(
+ {shardName: shard.shardName, executionSuccess: shard.executionSuccess},
+ shard.executionStages));
+ }
+ return executionStages;
+ }
+ return [root.executionStats.executionStages];
+}
+
+/**
* Given the root stage of agg explain's JSON representation of a query plan ('root'), returns all
* subdocuments whose stage is 'stage'. This can either be an agg stage name like "$cursor" or
* "$sort", or a query stage name like "IXSCAN" or "SORT".