summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/sbe_plan_cache_key_reporting.js
diff options
context:
space:
mode:
authorAlexander Ignatyev <alexander.ignatyev@mongodb.com>2022-04-27 12:27:28 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-04-27 12:59:39 +0000
commit8aa42af0644b93e794db1b824238c4b2ab203d25 (patch)
treededbd63a932af036eba6ea8e3ba91d4c6faa150e /jstests/noPassthrough/sbe_plan_cache_key_reporting.js
parent7e8ebefc2f35671a68d7bfdb0658cb6f2d69f431 (diff)
downloadmongo-8aa42af0644b93e794db1b824238c4b2ab203d25.tar.gz
SERVER-65345 Check if CanonicalQuery has pushed down stages
Diffstat (limited to 'jstests/noPassthrough/sbe_plan_cache_key_reporting.js')
-rw-r--r--jstests/noPassthrough/sbe_plan_cache_key_reporting.js60
1 files changed, 60 insertions, 0 deletions
diff --git a/jstests/noPassthrough/sbe_plan_cache_key_reporting.js b/jstests/noPassthrough/sbe_plan_cache_key_reporting.js
index 6dd57d377a5..41e242e872b 100644
--- a/jstests/noPassthrough/sbe_plan_cache_key_reporting.js
+++ b/jstests/noPassthrough/sbe_plan_cache_key_reporting.js
@@ -165,5 +165,65 @@ function assertQueryHashAndPlanCacheKey(sbe, classic) {
assertQueryHashAndPlanCacheKey(sbe.attr, classic.attr);
})();
+// Validate that a query with pushed down $lookup stage uses classic plan cache key encoding.
+(function validateLookupQueryHashMap() {
+ const lookupColl = db.lookupColl;
+ lookupColl.drop();
+ assert.commandWorked(lookupColl.createIndex({b: 1}));
+ const [sbe, classic] =
+ runTestAgainstSbeAndClassicEngines(
+ function(engine) {
+ const pipeline = [
+ {
+ $lookup:
+ {
+ from: lookupColl.getName(),
+ localField: "a",
+ foreignField: "b",
+ as: "whatever"
+ }
+ }
+ ];
+ return coll.explain().aggregate(pipeline);
+ });
+
+ assert.neq(sbe, null);
+ assert.neq(classic, null);
+ assert.eq(sbe.explainVersion, "2", sbe);
+ assert.eq(classic.explainVersion, "1", classic);
+
+ // The query hashes and the plan cache keys ('the keys') are different now because
+ // 'internalQueryForceClassicEngine' flag is encoded into query shape, once this flag is removed
+ // from the query shape encoding the keys will be the same until SERVER-61507 is completed, then
+ // the keys will be different forever.
+ assertQueryHashAndPlanCacheKey(sbe.queryPlanner, classic.stages[0]["$cursor"].queryPlanner);
+})();
+
+// Validate that a query with pushed down $group stage uses classic plan cache key encoding.
+(function validateGroupQueryHashMap() {
+ const groupColl = db.groupColl;
+ groupColl.drop();
+ assert.commandWorked(groupColl.insertOne({b: 1}));
+ const [sbe, classic] = runTestAgainstSbeAndClassicEngines(function(engine) {
+ const pipeline = [{
+ $group: {
+ _id: "$b",
+ }
+ }];
+ return groupColl.explain().aggregate(pipeline);
+ });
+
+ assert.neq(sbe, null);
+ assert.neq(classic, null);
+ assert.eq(sbe.explainVersion, "2", sbe);
+ assert.eq(classic.explainVersion, "1", classic);
+
+ // The query hashes and the plan cache keys ('the keys') are different now because
+ // 'internalQueryForceClassicEngine' flag is encoded into query shape, once this flag is removed
+ // from the query shape encoding the keys will be the same until SERVER-61507 is completed, then
+ // the keys will be different forever.
+ assertQueryHashAndPlanCacheKey(sbe.queryPlanner, classic.stages[0]["$cursor"].queryPlanner);
+})();
+
MongoRunner.stopMongod(conn);
}());