summaryrefslogtreecommitdiff
path: root/jstests/core/optimized_match_explain.js
blob: bf4893519bdd933289112ef3732d84662ce47bb2 (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
// @tags: [
//   does_not_support_stepdowns,
// ]

/**
 * 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.commandWorked(coll.insert({a: 1, b: 1}));
assert.commandWorked(coll.insert({a: 2, b: 3}));
assert.commandWorked(coll.insert({a: 1, b: 2}));
assert.commandWorked(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}}});
}());