summaryrefslogtreecommitdiff
path: root/jstests/core
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/core')
-rw-r--r--jstests/core/plan_cache_list_plans.js21
-rw-r--r--jstests/core/profile_find.js9
2 files changed, 23 insertions, 7 deletions
diff --git a/jstests/core/plan_cache_list_plans.js b/jstests/core/plan_cache_list_plans.js
index caa1cc9cd55..9c34205c0c4 100644
--- a/jstests/core/plan_cache_list_plans.js
+++ b/jstests/core/plan_cache_list_plans.js
@@ -13,14 +13,13 @@
let t = db.jstests_plan_cache_list_plans;
t.drop();
- // Utility function to list plans for a query.
- function getPlans(query, sort, projection) {
+ function getPlansForCacheEntry(query, sort, projection) {
let key = {query: query, sort: sort, projection: projection};
let res = t.runCommand('planCacheListPlans', key);
assert.commandWorked(res, 'planCacheListPlans(' + tojson(key, '', true) + ' failed');
assert(res.hasOwnProperty('plans'),
'plans missing from planCacheListPlans(' + tojson(key, '', true) + ') result');
- return res.plans;
+ return res;
}
// Assert that timeOfCreation exists in the cache entry. The difference between the current time
@@ -48,8 +47,8 @@
t.ensureIndex({a: 1, b: 1});
// Invalid key should be an error.
- assert.eq(0,
- getPlans({unknownfield: 1}, {}, {}),
+ assert.eq([],
+ getPlansForCacheEntry({unknownfield: 1}, {}, {}).plans,
'planCacheListPlans should return empty results on unknown query shape');
// Create a cache entry.
@@ -61,7 +60,12 @@
checkTimeOfCreation({a: 1, b: 1}, {a: -1}, {_id: 0, a: 1}, now);
// Retrieve plans for valid cache entry.
- let plans = getPlans({a: 1, b: 1}, {a: -1}, {_id: 0, a: 1});
+ let entry = getPlansForCacheEntry({a: 1, b: 1}, {a: -1}, {_id: 0, a: 1});
+ assert(entry.hasOwnProperty('works'),
+ 'works missing from planCacheListPlans() result ' + tojson(entry));
+ assert.eq(entry.isActive, false);
+
+ let plans = entry.plans;
assert.eq(2, plans.length, 'unexpected number of plans cached for query');
// Print every plan
@@ -90,7 +94,10 @@
now = (new Date()).getTime();
checkTimeOfCreation({a: 3, b: 3}, {a: -1}, {_id: 0, a: 1}, now);
- plans = getPlans({a: 3, b: 3}, {a: -1}, {_id: 0, a: 1});
+ entry = getPlansForCacheEntry({a: 3, b: 3}, {a: -1}, {_id: 0, a: 1});
+ assert(entry.hasOwnProperty('works'), 'works missing from planCacheListPlans() result');
+ assert.eq(entry.isActive, true);
+ plans = entry.plans;
// This should be obvious but feedback is available only for the first (winning) plan.
print('planCacheListPlans result (after adding indexes and completing 20 executions):');
diff --git a/jstests/core/profile_find.js b/jstests/core/profile_find.js
index a87a84c34ce..6c89781bd33 100644
--- a/jstests/core/profile_find.js
+++ b/jstests/core/profile_find.js
@@ -111,7 +111,16 @@
assert.writeOK(coll.insert({a: 5, b: i}));
assert.writeOK(coll.insert({a: i, b: 10}));
}
+
+ // Until we get the failpoint described in the above comment (regarding SERVER-23620), we must
+ // run the query twice. The first time will create an inactive cache entry. The second run will
+ // take the same number of works, and create an active cache entry.
+ assert.neq(coll.findOne({a: 5, b: 15}), null);
assert.neq(coll.findOne({a: 5, b: 15}), null);
+
+ // Run a query with the same shape, but with different parameters. The plan cached for the
+ // query above will perform poorly (since the selectivities are different) and we will be
+ // forced to replan.
assert.neq(coll.findOne({a: 15, b: 10}), null);
profileObj = getLatestProfilerEntry(testDB, profileEntryFilter);