summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/explain_index_limits.js
blob: 34be015d17ee11d54abbd9f43914f2a26ee2fea8 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Test that explain correctly outputs whether the planner hit or, and, or scan limits.

(function() {
"use strict";
load("jstests/libs/fixture_helpers.js");

const conn = MongoRunner.runMongod({});
const testDB = conn.getDB(jsTestName());
const coll = testDB.planner_index_limit;
coll.drop();

// Test scanLimit.
coll.createIndex({e: 1, s: 1});
let inList = [];
for (let i = 0; i < 250; i++) {
    inList.push(i);
}
FixtureHelpers.runCommandOnEachPrimary({
    db: testDB.getSiblingDB("admin"),
    cmdObj: {
        setParameter: 1,
        "internalQueryMaxScansToExplode": 0,
    }
});
const scanResult = coll.find({e: {$in: inList}}).sort({s: 1}).explain();
assert(scanResult.queryPlanner.maxScansToExplodeReached, tojson(scanResult));
FixtureHelpers.runCommandOnEachPrimary({
    db: testDB.getSiblingDB("admin"),
    cmdObj: {
        setParameter: 1,
        "internalQueryMaxScansToExplode": 200,
    }
});
coll.drop();

// Test orLimit.
coll.createIndex({common: 1});
coll.createIndex({one: 1});
coll.createIndex({two: 1});
FixtureHelpers.runCommandOnEachPrimary({
    db: testDB.getSiblingDB("admin"),
    cmdObj: {
        setParameter: 1,
        "internalQueryEnumerationMaxOrSolutions": 1,
    }
});
const orResult = coll.find({common: 1, $or: [{one: 0, two: 0}, {one: 1, two: 1}]}).explain();
assert(orResult.queryPlanner.maxIndexedOrSolutionsReached, tojson(orResult));
FixtureHelpers.runCommandOnEachPrimary({
    db: testDB.getSiblingDB("admin"),
    cmdObj: {
        setParameter: 1,
        "internalQueryEnumerationMaxOrSolutions": 10,
    }
});

// Test andLimit.
FixtureHelpers.runCommandOnEachPrimary({
    db: testDB.getSiblingDB("admin"),
    cmdObj: {
        setParameter: 1,
        "internalQueryEnumerationMaxIntersectPerAnd": 1,
    }
});
const andResult = coll.find({common: 1, two: 0, one: 1}).explain();
assert(andResult.queryPlanner.maxIndexedAndSolutionsReached, tojson(andResult));

// Test that andLimit and orLimit will both show in one query.
FixtureHelpers.runCommandOnEachPrimary({
    db: testDB.getSiblingDB("admin"),
    cmdObj: {
        setParameter: 1,
        "internalQueryEnumerationMaxOrSolutions": 1,
    }
});
const comboResult = coll.find({common: 1, one: 10, $or: [{one: 1}, {two: 2}]}).explain();
assert(comboResult.queryPlanner.maxIndexedAndSolutionsReached, tojson(comboResult));
assert(comboResult.queryPlanner.maxIndexedOrSolutionsReached, tojson(comboResult));

// Reset values to defaults.
FixtureHelpers.runCommandOnEachPrimary({
    db: testDB.getSiblingDB("admin"),
    cmdObj: {
        setParameter: 1,
        "internalQueryEnumerationMaxOrSolutions": 10,
    }
});
FixtureHelpers.runCommandOnEachPrimary({
    db: testDB.getSiblingDB("admin"),
    cmdObj: {
        setParameter: 1,
        "internalQueryEnumerationMaxIntersectPerAnd": 3,
    }
});
MongoRunner.stopMongod(conn);
})();