summaryrefslogtreecommitdiff
path: root/jstests/core/optimized_match_explain.js
blob: 8e688302753a1893654c2fa82f9a40c8b7e313cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/**
 * Tests that the explain output for $match reflects any optimizations.
 */
(function() {
    "use strict";
    load("jstests/libs/analyze_plan.js");

    const coll = db.match_explain;
    coll.drop();

    assert.writeOK(coll.insert({a: 1, b: 1}));
    assert.writeOK(coll.insert({a: 2, b: 3}));
    assert.writeOK(coll.insert({a: 1, b: 2}));
    assert.writeOK(coll.insert({a: 1, b: 4}));

    // Explain output should reflect optimizations.
    // $and should not be in the explain output because it is optimized out.
    let explain = coll.explain().aggregate(
        [{$sort: {b: -1}}, {$addFields: {c: {$mod: ["$a", 4]}}}, {$match: {$and: [{c: 1}]}}]);

    assert.commandWorked(explain);
    assert.eq(getAggPlanStage(explain, "$match"), {$match: {c: {$eq: 1}}});
}());