summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/noPassthrough')
-rw-r--r--jstests/noPassthrough/plan_cache_list_failed_plans.js37
-rw-r--r--jstests/noPassthrough/plan_cache_list_plans_new_format.js28
2 files changed, 65 insertions, 0 deletions
diff --git a/jstests/noPassthrough/plan_cache_list_failed_plans.js b/jstests/noPassthrough/plan_cache_list_failed_plans.js
new file mode 100644
index 00000000000..96eea6ab27b
--- /dev/null
+++ b/jstests/noPassthrough/plan_cache_list_failed_plans.js
@@ -0,0 +1,37 @@
+// Confirms the planCacheListPlans output format includes information about failed plans.
+(function() {
+ "use strict";
+
+ const conn = MongoRunner.runMongod();
+ assert.neq(null, conn, "mongod was unable to start up");
+ const testDB = conn.getDB("jstests_plan_cache_list_failed_plans");
+ const coll = testDB.test;
+
+ coll.drop();
+
+ // Setup the database such that it will generate a failing plan and a succeeding plan.
+ const numDocs = 32;
+ const smallNumber = 10;
+ assert.commandWorked(
+ testDB.adminCommand({setParameter: 1, internalQueryExecMaxBlockingSortBytes: smallNumber}));
+ for (let i = 0; i < numDocs * 2; ++i)
+ assert.commandWorked(coll.insert({a: ((i >= (numDocs * 2) - smallNumber) ? 1 : 0), d: i}));
+
+ // Create the indexes to create competing plans.
+ assert.commandWorked(coll.createIndex({a: 1}));
+ assert.commandWorked(coll.createIndex({d: 1}));
+
+ // Assert that the find command found documents.
+ const key = {query: {a: 1}, sort: {d: 1}, projection: {}};
+ assert.eq(smallNumber, coll.find(key.query).sort(key.sort).itcount());
+ let res = assert.commandWorked(coll.runCommand("planCacheListPlans", key));
+
+ // There should have been two plans generated.
+ assert.eq(res["plans"].length, 2);
+ // The second plan should fail.
+ assert.eq(res["plans"][1]["reason"]["failed"], true);
+
+ // The failing plan should have a score of 0.
+ assert.eq(res["plans"][1]["reason"]["score"], 0);
+ MongoRunner.stopMongod(conn);
+})();
diff --git a/jstests/noPassthrough/plan_cache_list_plans_new_format.js b/jstests/noPassthrough/plan_cache_list_plans_new_format.js
index f8f96d56cbf..cd0a7fb0320 100644
--- a/jstests/noPassthrough/plan_cache_list_plans_new_format.js
+++ b/jstests/noPassthrough/plan_cache_list_plans_new_format.js
@@ -55,5 +55,33 @@
assert.eq(cachedStage, winningExecStage, `Information about the winning plan in "cachedPlan" is
inconsistent with the first element in "creationExecStats".`);
+ // Ensures that the new format preservers information about the failed plans.
+ assert(coll.drop());
+
+ // Setup the database such that it will generate a failing plan and a succeeding plan.
+ const numDocs = 32;
+ const smallNumber = 10;
+ assert.commandWorked(
+ testDB.adminCommand({setParameter: 1, internalQueryExecMaxBlockingSortBytes: smallNumber}));
+ for (let i = 0; i < numDocs * 2; ++i)
+ assert.commandWorked(coll.insert({a: ((i >= (numDocs * 2) - smallNumber) ? 1 : 0), d: i}));
+
+ // Create the indexes to create competing plans.
+ assert.commandWorked(coll.createIndex({a: 1}));
+ assert.commandWorked(coll.createIndex({d: 1}));
+
+ // Assert that the find command found documents.
+ key = {query: {a: 1}, sort: {d: 1}, projection: {}};
+ assert.eq(smallNumber, coll.find(key.query).sort(key.sort).itcount());
+ res = assert.commandWorked(coll.runCommand('planCacheListPlans', key));
+
+ // There should have been two plans generated.
+ assert.eq(res["creationExecStats"].length, 2);
+
+ // The second plan should have failed.
+ assert(res["creationExecStats"][1].failed);
+
+ // The failing plan should have a score of 0.
+ assert.eq(res["candidatePlanScores"][1], 0);
MongoRunner.stopMongod(conn);
})();