summaryrefslogtreecommitdiff
path: root/jstests/core/explain_multi_plan_count.js
blob: 2ac52019cf36f0645602aa92f82ba7181ca09e95 (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
// Tests that in the case of multiple plans, the plan node above the MutliPlanStage is printed
// correctly both as part of the winning, and rejected plans.
//
// This test is not prepared to handle explain output for sharded collections or when executed
// against a mongos.
// @tags: [
//   assumes_against_mongod_not_mongos,
//   assumes_unsharded_collection,
// ]

(function() {
"use strict";

load("jstests/libs/analyze_plan.js");

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

// Create two indexes to ensure that the best plan will be picked by the multi-planner.
assert.commandWorked(coll.createIndex({a: 1}));
assert.commandWorked(coll.createIndex({a: 1, b: 1}));
assert.commandWorked(coll.createIndex({a: 1, c: 1}));
assert.commandWorked(coll.insert([{a: 0}, {a: 1}, {a: 2}, {a: 3}]));

const explain =
    coll.explain("allPlansExecution").find({a: {$in: [1, 3]}, b: {$in: [1, 3]}}).count();

// Check that all plans, both winning and rejected have a structure that excludes the MultiPlanNode
// and continues with the correct plan child below COUNT.

assertExplainCount({explainResults: explain, expectedCount: 0});
isIndexOnly(db, getWinningPlan(explain.queryPlanner));

const rejectedPlans = getRejectedPlans(explain);
for (let curRejectedPlan of rejectedPlans) {
    const rejectedPlan = getRejectedPlan(curRejectedPlan);
    assert.eq(rejectedPlan.stage, "COUNT");
    isIxscan(db, rejectedPlan);
}

assert(coll.drop());
}());