summaryrefslogtreecommitdiff
path: root/jstests/core/sbe/from_plan_cache_flag.js
blob: ef910b425134506e4f73198af5c9f6a1db007ec8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// The test runs commands that are not allowed with security token: setProfilingLevel.
// @tags: [
//   not_allowed_with_security_token,
//   requires_profiling,
//   does_not_support_stepdowns,
//   # TODO SERVER-67607: Test plan cache with CQF enabled.
//   cqf_incompatible,
// ]
(function() {
"use strict";

load("jstests/libs/analyze_plan.js");
load("jstests/libs/sbe_util.js");  // For checkSBEEnabled.
load("jstests/libs/profiler.js");  // For getLatestProfilerEntry.
load("jstests/libs/sbe_util.js");  // For checkSBEEnabled.

if (!checkSBEEnabled(db, ["featureFlagSbeFull"], true /* checkAllNodes */)) {
    jsTest.log("Skip running the test because SBE is not enabled");
    return;
}
var testDB = db.getSiblingDB("from_plan_cache_flag");
assert.commandWorked(testDB.dropDatabase());
var coll = testDB.getCollection("test");
assert.commandWorked(testDB.setProfilingLevel(2));
coll.drop();
coll.getPlanCache().clear();

assert.commandWorked(coll.insert({a: 1}));
assert.commandWorked(coll.insert({a: 2}));
assert.commandWorked(coll.insert({a: 3}));
assert.commandWorked(coll.insert({a: 2}));

let pipeline = {$match: {a: 1}};
coll.aggregate([pipeline]).toArray();
let profileObj = getLatestProfilerEntry(testDB);
/* fromPlanCache can be undefined in the profiler entry. The first ! determines the
 * profileObj.fromPlanCache value's associated true/false value (important in the case where
 * undefined) and then returns the opposite of the associated true/false value. The second !
 * returns the opposite of the opposite value. In other words, the !! returns the boolean true/false
 * association of a value.  */
assert.eq(!!profileObj.fromPlanCache, false);

coll.aggregate({$match: {a: 2}}).toArray();
profileObj = getLatestProfilerEntry(testDB);
assert.eq(!!profileObj.fromPlanCache, true);

coll.aggregate({$match: {a: 3}}).toArray();
profileObj = getLatestProfilerEntry(testDB);
assert.eq(!!profileObj.fromPlanCache, true);
}());