summaryrefslogtreecommitdiff
path: root/jstests/libs
diff options
context:
space:
mode:
authorNick Zolnierz <nicholas.zolnierz@mongodb.com>2018-03-09 13:24:33 -0500
committerNick Zolnierz <nicholas.zolnierz@mongodb.com>2018-03-14 20:35:15 -0400
commit0109767b6962d18b60d89a723c0087cf27d370e3 (patch)
treedbe2c92f82cc668a1b837392ebd68f2000f88956 /jstests/libs
parent11f4ea91fd3f177af96da6250f998e8bd9825b67 (diff)
downloadmongo-0109767b6962d18b60d89a723c0087cf27d370e3.tar.gz
SERVER-23202: Query planner does not trim certain bounds-generating inequality predicates from expression tree
Diffstat (limited to 'jstests/libs')
-rw-r--r--jstests/libs/analyze_plan.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/jstests/libs/analyze_plan.js b/jstests/libs/analyze_plan.js
index aed394f6b83..6a719d611f6 100644
--- a/jstests/libs/analyze_plan.js
+++ b/jstests/libs/analyze_plan.js
@@ -248,3 +248,42 @@ function getChunkSkips(root) {
return 0;
}
+
+/**
+ * Given explain output at executionStats level verbosity, confirms that the root stage is COUNT and
+ * that the result of the count is equal to 'expectedCount'.
+ */
+function assertExplainCount({explainResults, expectedCount}) {
+ const execStages = explainResults.executionStats.executionStages;
+
+ // If passed through mongos, then the root stage should be the mongos SINGLE_SHARD stage or
+ // SHARD_MERGE stages, with COUNT as the root stage on each shard. If explaining directly on the
+ // shard, then COUNT is the root stage.
+ if ("SINGLE_SHARD" == execStages.stage || "SHARD_MERGE" == execStages.stage) {
+ let totalCounted = 0;
+ for (let shardExplain of execStages.shards) {
+ const countStage = shardExplain.executionStages;
+ assert.eq(countStage.stage, "COUNT", "root stage on shard is not COUNT");
+ totalCounted += countStage.nCounted;
+ }
+ assert.eq(totalCounted, expectedCount, "wrong count result");
+ } else {
+ assert.eq(execStages.stage, "COUNT", "root stage is not COUNT");
+ assert.eq(execStages.nCounted, expectedCount, "wrong count result");
+ }
+}
+
+/**
+ * Verifies that a given query uses an index and is covered when used in a count command.
+ */
+function assertCoveredQueryAndCount({collection, query, project, count}) {
+ let explain = collection.find(query, project).explain();
+ assert(isIndexOnly(db, explain.queryPlanner.winningPlan),
+ "Winning plan was not covered: " + tojson(explain.queryPlanner.winningPlan));
+
+ // Same query as a count command should also be covered.
+ explain = collection.explain("executionStats").find(query).count();
+ assert(isIndexOnly(db, explain.queryPlanner.winningPlan),
+ "Winning plan for count was not covered: " + tojson(explain.queryPlanner.winningPlan));
+ assertExplainCount({explainResults: explain, expectedCount: count});
+}