summaryrefslogtreecommitdiff
path: root/jstests/core/plan_cache_list_plans.js
diff options
context:
space:
mode:
authorRuoxin Xu <ruoxin.xu@mongodb.com>2022-01-17 18:13:45 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-01-17 18:39:52 +0000
commita29b0a6f075bb05a1a87927508edd31656a6a15c (patch)
tree6111105c737e775d74841f7775a6abee9f483db4 /jstests/core/plan_cache_list_plans.js
parent59d341f677f355939c6f4e8e9934ea1de700c1f7 (diff)
downloadmongo-a29b0a6f075bb05a1a87927508edd31656a6a15c.tar.gz
SERVER-59682 Recover SBE plans from the new plan cache
Diffstat (limited to 'jstests/core/plan_cache_list_plans.js')
-rw-r--r--jstests/core/plan_cache_list_plans.js71
1 files changed, 36 insertions, 35 deletions
diff --git a/jstests/core/plan_cache_list_plans.js b/jstests/core/plan_cache_list_plans.js
index c098acc6ee5..69ade6c65d6 100644
--- a/jstests/core/plan_cache_list_plans.js
+++ b/jstests/core/plan_cache_list_plans.js
@@ -16,52 +16,47 @@
(function() {
"use strict";
-load("jstests/libs/sbe_util.js"); // For checkSBEEnabled.
-if (checkSBEEnabled(db, ["featureFlagSbePlanCache"])) {
- jsTest.log("Skipping test because SBE and SBE plan cache are both enabled.");
- return;
-}
+load("jstests/libs/analyze_plan.js"); // For getPlanCacheKeyFromShape.
+load("jstests/libs/sbe_util.js"); // For checkSBEEnabled.
let coll = db.jstests_plan_cache_list_plans;
coll.drop();
+const isSBEAndPlanCacheOn = checkSBEEnabled(db, ["featureFlagSbePlanCache"]);
+
function dumpPlanCacheState() {
return coll.aggregate([{$planCacheStats: {}}]).toArray();
}
function getPlansForCacheEntry(query, sort, projection) {
- const match = {
- 'createdFromQuery.query': query,
- 'createdFromQuery.sort': sort,
- 'createdFromQuery.projection': projection
- };
- const res = coll.aggregate([{$planCacheStats: {}}, {$match: match}]).toArray();
+ const keyHash = getPlanCacheKeyFromShape(
+ {query: query, projection: projection, sort: sort, collection: coll, db: db});
+
+ const res =
+ coll.aggregate([{$planCacheStats: {}}, {$match: {planCacheKey: keyHash}}]).toArray();
// We expect exactly one matching cache entry.
assert.eq(1, res.length, dumpPlanCacheState());
return res[0];
}
function assertNoCacheEntry(query, sort, projection) {
- const match = {
- 'createdFromQuery.query': query,
- 'createdFromQuery.sort': sort,
- 'createdFromQuery.projection': projection
- };
+ const keyHash = getPlanCacheKeyFromShape(
+ {query: query, projection: projection, sort: sort, collection: coll, db: db});
+
assert.eq(0,
- coll.aggregate([{$planCacheStats: {}}, {$match: match}]).itcount(),
+ coll.aggregate([{$planCacheStats: {}}, {$match: {planCacheKey: keyHash}}]).itcount(),
dumpPlanCacheState());
}
// Assert that timeOfCreation exists in the cache entry. The difference between the current time
// and the time a plan was cached should not be larger than an hour.
function checkTimeOfCreation(query, sort, projection, date) {
- const match = {
- 'createdFromQuery.query': query,
- 'createdFromQuery.sort': sort,
- 'createdFromQuery.projection': projection
- };
- const res = coll.aggregate([{$planCacheStats: {}}, {$match: match}]).toArray();
+ const keyHash = getPlanCacheKeyFromShape(
+ {query: query, projection: projection, sort: sort, collection: coll, db: db});
+
+ const res =
+ coll.aggregate([{$planCacheStats: {}}, {$match: {planCacheKey: keyHash}}]).toArray();
// We expect exactly one matching cache entry.
assert.eq(1, res.length, res);
const cacheEntry = res[0];
@@ -98,9 +93,12 @@ let entry = getPlansForCacheEntry({a: 1, b: 1}, {a: -1}, {_id: 0, a: 1});
assert(entry.hasOwnProperty('works'), entry);
assert.eq(entry.isActive, false);
-// We expect that there were two candidate plans evaluated when the cache entry was created.
-assert(entry.hasOwnProperty("creationExecStats"), entry);
-assert.eq(2, entry.creationExecStats.length, entry);
+if (!isSBEAndPlanCacheOn) {
+ // Note that SBE plan cache entry does not include "creationExecStats". We expect that there
+ // were two candidate plans evaluated when the cache entry was created.
+ assert(entry.hasOwnProperty("creationExecStats"), entry);
+ assert.eq(2, entry.creationExecStats.length, entry);
+}
// Test the queryHash and planCacheKey property by comparing entries for two different
// query shapes.
@@ -132,15 +130,18 @@ entry = getPlansForCacheEntry({a: 3, b: 3}, {a: -1}, {_id: 0, a: 1});
assert(entry.hasOwnProperty('works'), entry);
assert.eq(entry.isActive, true);
-// There should be the same number of canidate plan scores as candidate plans.
-assert.eq(entry.creationExecStats.length, entry.candidatePlanScores.length, entry);
-
-// Scores should be greater than zero and sorted descending.
-for (let i = 0; i < entry.candidatePlanScores.length; ++i) {
- const scores = entry.candidatePlanScores;
- assert.gt(scores[i], 0, entry);
- if (i > 0) {
- assert.lte(scores[i], scores[i - 1], entry);
+if (!isSBEAndPlanCacheOn) {
+ // Note that SBE plan cache entry does not include "creationExecStats". There should be the same
+ // number of candidate plan scores as candidate plans.
+ assert.eq(entry.creationExecStats.length, entry.candidatePlanScores.length, entry);
+
+ // Scores should be greater than zero and sorted descending.
+ for (let i = 0; i < entry.candidatePlanScores.length; ++i) {
+ const scores = entry.candidatePlanScores;
+ assert.gt(scores[i], 0, entry);
+ if (i > 0) {
+ assert.lte(scores[i], scores[i - 1], entry);
+ }
}
}
})();