- Change PlanExplainerImpl::getWinningPlanStats to not cut off the nodes on top of the MultiPlanStage. - Adapt all functions that process a tree of PlanStage or PlanStageStats for the purpose of Explain to skip the MultiPlan node, and jump to process its best plan child. - Pass the index of the multi-plan sub-plan that should be printed to various functions that print or linearize plans.
44 lines
1.4 KiB
JavaScript
44 lines
1.4 KiB
JavaScript
// 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: [
|
|
// requires_fcv_49,
|
|
// assumes_unsharded_collection,
|
|
// assumes_against_mongod_not_mongos,
|
|
// ]
|
|
|
|
(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());
|
|
}());
|