|
| 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 | +})(); |
0 commit comments