diff options
author | David Storch <david.storch@10gen.com> | 2017-02-10 11:52:18 -0500 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2017-03-13 09:46:14 -0400 |
commit | 82b16740f8a66093b453a73a04b3b9bd00e5d7a0 (patch) | |
tree | 62d156fc9676526ecbea19cd03ef7a293579c4df /jstests/core/views/views_aggregation.js | |
parent | 73f9e8b8a8422becf8694fe3d82c0e647dc71189 (diff) | |
download | mongo-82b16740f8a66093b453a73a04b3b9bd00e5d7a0.tar.gz |
SERVER-19758 add support for "executionStats" and "allPlansExecution" to agg explain
Like other explainable commands, aggregate can now be
explained using the explain command, e.g.
db.runCommand({explain: {aggregate: ...}, verbosity:
"executionStats"}). The existing explain:true flag
corresponds to "queryPlanner" mode and is still supported.
However, explain:true cannot be specified when explaining
aggregate via the explain command.
Additional execution information is provided only in the
$cursor section of the aggregation explain output. Having
aggregation stages themselves track and report execution
info is further work.
Diffstat (limited to 'jstests/core/views/views_aggregation.js')
-rw-r--r-- | jstests/core/views/views_aggregation.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/jstests/core/views/views_aggregation.js b/jstests/core/views/views_aggregation.js index 4a7e141a49f..a0c5392deb4 100644 --- a/jstests/core/views/views_aggregation.js +++ b/jstests/core/views/views_aggregation.js @@ -119,6 +119,48 @@ {aggregate: "largeView", pipeline: [{$sort: {x: -1}}], cursor: {}, allowDiskUse: true}), "Expected aggregate to succeed since 'allowDiskUse' was specified"); + // Test explain modes on a view. + let explainPlan = assert.commandWorked( + viewsDB.popSortedView.explain("queryPlanner").aggregate([{$limit: 1}, {$match: {pop: 3}}])); + assert.eq(explainPlan.stages[0].$cursor.queryPlanner.namespace, "views_aggregation.coll"); + assert(!explainPlan.stages[0].$cursor.hasOwnProperty("executionStats")); + + explainPlan = assert.commandWorked(viewsDB.popSortedView.explain("executionStats") + .aggregate([{$limit: 1}, {$match: {pop: 3}}])); + assert.eq(explainPlan.stages[0].$cursor.queryPlanner.namespace, "views_aggregation.coll"); + assert(explainPlan.stages[0].$cursor.hasOwnProperty("executionStats")); + assert.eq(explainPlan.stages[0].$cursor.executionStats.nReturned, 1); + assert(!explainPlan.stages[0].$cursor.executionStats.hasOwnProperty("allPlansExecution")); + + explainPlan = assert.commandWorked(viewsDB.popSortedView.explain("allPlansExecution") + .aggregate([{$limit: 1}, {$match: {pop: 3}}])); + assert.eq(explainPlan.stages[0].$cursor.queryPlanner.namespace, "views_aggregation.coll"); + assert(explainPlan.stages[0].$cursor.hasOwnProperty("executionStats")); + assert.eq(explainPlan.stages[0].$cursor.executionStats.nReturned, 1); + assert(explainPlan.stages[0].$cursor.executionStats.hasOwnProperty("allPlansExecution")); + + // Passing a value of true for the explain option to the aggregation command, without using the + // shell explain helper, should continue to work. + explainPlan = assert.commandWorked( + viewsDB.popSortedView.aggregate([{$limit: 1}, {$match: {pop: 3}}], {explain: true})); + assert.eq(explainPlan.stages[0].$cursor.queryPlanner.namespace, "views_aggregation.coll"); + assert(!explainPlan.stages[0].$cursor.hasOwnProperty("executionStats")); + + // Test allPlansExecution explain mode on the base collection. + explainPlan = assert.commandWorked( + viewsDB.coll.explain("allPlansExecution").aggregate([{$limit: 1}, {$match: {pop: 3}}])); + assert.eq(explainPlan.stages[0].$cursor.queryPlanner.namespace, "views_aggregation.coll"); + assert(explainPlan.stages[0].$cursor.hasOwnProperty("executionStats")); + printjson(explainPlan.stages[0].$cursor.executionStats); + assert.eq(explainPlan.stages[0].$cursor.executionStats.nReturned, 5); + assert(explainPlan.stages[0].$cursor.executionStats.hasOwnProperty("allPlansExecution")); + + // The explain:true option should not work when paired with the explain shell helper. + assert.throws(function() { + viewsDB.popSortedView.explain("executionStats") + .aggregate([{$limit: 1}, {$match: {pop: 3}}], {explain: true}); + }); + // The remaining tests involve $lookup and $graphLookup. We cannot lookup into sharded // collections, so skip these tests if running in a sharded configuration. let isMasterResponse = assert.commandWorked(viewsDB.runCommand("isMaster")); |