Skip to content
This repository was archived by the owner on Oct 31, 2023. It is now read-only.

Commit 1bbdd38

Browse files
alyacbEvergreen Agent
authored andcommitted
SERVER-49726 Add test for SBE generic scan when static limit reached
1 parent 53b4d1a commit 1bbdd38

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Validate that generic index scan is used in SBE once max limit for statically generated intervals
2+
// is reached.
3+
4+
(function() {
5+
"use strict";
6+
7+
load("jstests/libs/analyze_plan.js"); // For explain helpers.
8+
9+
const isSBEEnabled = db.adminCommand({
10+
getParameter: 1,
11+
internalQueryEnableSlotBasedExecutionEngine: 1
12+
}).internalQueryEnableSlotBasedExecutionEngine;
13+
14+
if (!isSBEEnabled) {
15+
// This test is only relevant when SBE is enabled.
16+
return;
17+
}
18+
19+
const coll = db.index_bounds_static_limit;
20+
coll.drop();
21+
22+
assert.commandWorked(coll.createIndex({a: 1, b: 1, c: 1, d: 1, e: 1}));
23+
24+
// Save the old limit so it can be restored once the tests completes.
25+
const staticLimit = db.adminCommand({
26+
getParameter: 1,
27+
internalQuerySlotBasedExecutionMaxStaticIndexScanIntervals: 1
28+
}).internalQuerySlotBasedExecutionMaxStaticIndexScanIntervals;
29+
30+
const setStaticLimit = function(limit) {
31+
return db.adminCommand(
32+
{setParameter: 1, internalQuerySlotBasedExecutionMaxStaticIndexScanIntervals: limit});
33+
};
34+
35+
try {
36+
// Verify that when the number of statically generated single interval bounds is less than the
37+
// static limit, the optimized plan is used.
38+
const optimized =
39+
coll.find({a: {$in: [1, 2, 3]}, b: {$in: [10, 11, 12]}, c: {$in: [42]}, d: {$lt: 3}})
40+
.explain("executionStats")
41+
.executionStats.executionStages;
42+
assert(planHasStage(db, optimized, "ixseek"), optimized);
43+
assert(!planHasStage(db, optimized, "chkbounds"), optimized);
44+
45+
// Verify that when the number of statically generated single interval bounds is greater than
46+
// the static limit, the generic plan is used.
47+
setStaticLimit(2);
48+
const generic =
49+
coll.find({a: {$in: [1, 2, 3]}, b: {$in: [10, 11, 12]}, c: {$in: [42]}, d: {$lt: 3}})
50+
.explain("executionStats")
51+
.executionStats.executionStages;
52+
assert(planHasStage(db, generic, "chkbounds"), generic);
53+
assert(planHasStage(db, generic, "ixseek"), generic);
54+
} finally {
55+
setStaticLimit(staticLimit);
56+
}
57+
})();

jstests/libs/analyze_plan.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ function getPlanStages(root, stage) {
3030
results = results.concat(getPlanStages(root.queryPlanner.winningPlan, stage));
3131
}
3232

33+
if ("thenStage" in root) {
34+
results = results.concat(getPlanStages(root.thenStage, stage));
35+
}
36+
37+
if ("elseStage" in root) {
38+
results = results.concat(getPlanStages(root.elseStage, stage));
39+
}
40+
41+
if ("outerStage" in root) {
42+
results = results.concat(getPlanStages(root.outerStage, stage));
43+
}
44+
45+
if ("innerStage" in root) {
46+
results = results.concat(getPlanStages(root.innerStage, stage));
47+
}
48+
3349
if ("shards" in root) {
3450
if (Array.isArray(root.shards)) {
3551
results = root.shards.reduce(

0 commit comments

Comments
 (0)