summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/or_pushdown_disable_optimization.js
blob: 58c4ea1f8d23f3775b9b85988d8829bff116c79d (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
/**
 * Test that queries eligible for OR-pushdown optimization do not crash the server when the
 * 'disableMatchExpressionOptimization' failpoint is enabled.
 *
 * Originally designed to reproduce SERVER-70597.
 */
(function() {
"use strict";

const conn = MongoRunner.runMongod();
const db = conn.getDB("test");

assert.commandWorked(
    db.adminCommand({configureFailPoint: "disableMatchExpressionOptimization", mode: "alwaysOn"}));

const coll = db.getCollection(jsTestName());
coll.drop();
assert.commandWorked(coll.createIndex({a: 1, b: 1}));

let docs = [];
for (let a = 1; a <= 3; ++a) {
    for (let b = 1; b <= 3; ++b) {
        docs.push({a, b});
    }
}
assert.commandWorked(coll.insert(docs));

// This query has a nested $and, and a one-argument contained $or. Normally we canonicalize this
// predicate by flattening the $and and unwrapping the $or. The OR-pushdown optimization assumes the
// predicate has been canonicalized, but this assumption is broken by the failpoint.
const results = coll.aggregate([
                        {$match: {$and: [{$and: [{a: 2}]}, {$or: [{b: 3}]}]}},
                        {$unset: "_id"},
                    ])
                    .toArray();
assert.eq(results, [{a: 2, b: 3}]);

MongoRunner.stopMongod(conn);
})();