-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Query Optimization
-
None
-
None
-
None
-
None
-
None
-
None
-
None
PlanRanker::rankPlans eagerly does dependency analysis even if samplingCE would not be used (eg. due to there being a single plan in a query with no explain).
This slows down such queries by ~7-8% relative to MP (measured on an optimized build).
Note that MP does not go through PlanRanker::rankPlans.
Repro:
const query = Object.fromEntries( Array.from({length: 32}, (_, i) => [`f${i}`, {$gte: 0}]) ); const modes = ["multiPlanning", "mixed"]; const times = {multiPlanning: [], mixed: []}; db.a.drop(); db.a.insertOne(Object.fromEntries(Object.keys(query).map(k => [k, 1]))); for (let round = 0; round < 4; ++round) { for (const mode of modes) { db.adminCommand({setParameter: 1, internalQueryPlanRanker: mode}); for (let i = 0; i < 220; ++i) { const p = db.a.find(query).explain("plannerStats").queryPlanner; if (p.plans.length !== 1 || p.rankerChoice.chosenRanker !== "singlePlan" || p.ceSamplingMetadata) { throw new Error("Expected one candidate and no sampling"); } // Discard warm-ups. if (i >= 20) times[mode].push(p.optimizationTimeMicros); } } } const median = xs => xs.sort((a, b) => a - b)[xs.length >> 1]; const mp = median(times.multiPlanning), mixed = median(times.mixed); printjson({mp_median_us: mp, mixed_median_us: mixed, ratio: mixed / mp});
On my machine with an optimized build on a recent master commit this printed:
{
mp_median_us: 224,
mixed_median_us: 241,
ratio: 1.0758928571428572
}
Found by GPT-6.1 Sol.