SBE plan cache pinned entries and the classic runtime planner for SBE
Parent: Replanning loops and replanReason · Published reference · snapshot 2026-10-23 · skill mongodb-cohort-71089ad6ce1a-pending
↓ Facts as markdownall context files
Source-anchored research for SBE plan cache pinned entries and the classic runtime planner for SBE. Run status: COMPLETED.
These notes link each claim to its source. Some citations identify archived research reports that are no longer hosted on this site. A published reference means the content is available; it does not certify independent review or accuracy.Read the editorial policy and follow the sources before relying on a claim.
How it works
- The SBE $planCacheStats representation includes an isPinned field, so operators can distinguish pinned entries when inspecting plan-cache statistics. (high confidence) (verified as of 2026-10-22) [source]
- [redacted] documents a historical race where one reader inserted a pinned SBE entry because it saw only one plan while another reader with a different index view finished multiplanning and collided with that entry; the issue lists fixes in 6.0.0-rc2 and 6.1.0-rc0. (low confidence) (verified as of 2023-10-29) [source]
- The classic_runtime_planner_for_sbe implementation supports both cache sources: it lowers a classic-cache QuerySolution into an SBE plan tree, while the SBE-cache path recovers a stored SBE tree. The planner name describes its planning mechanism, not one cache format. (high confidence) (verified as of 2026-10-20) [source]
- Do not identify every no-works/no-reads entry as pinned. MongoDB's Jira distinguishes a special rooted $or branch entry for SBE subplanning, which also stores neither metric because rooted-$or replanning is unsupported. The current executor source still has a TODO to investigate removing that restriction. (medium confidence) (verified as of 2026-10-20) [source]
- JusDB's December 8, 2025 article reports an SBE plan-cache eviction defect for MongoDB 7.0 but does not attribute that growth to pinned entries. The article therefore does not establish that pinning itself causes unbounded cache growth. (low confidence) (verified as of 2025-12-08) [source]
Problems, failure modes and limitations
- Percona's April 2026 plan-cache explainer presents classic works-based trial and replanning behavior; its example slow-query record identifies queryFramework as classic. Treat it as outside context for classic behavior, not direct evidence for pinned SBE read-budget semantics. (low confidence) [source]
Comparisons and alternatives
- For a nonpinned SBE-cache entry with `decisionReads`, `attemptToUsePlan` runs an SBE trial with a read budget of `internalQueryCacheEvictionRatio` times `decisionReads`; SERVER-85238 defines the cached read count as total keys examined plus total documents examined. Entries without `decisionReads` bypass this trial. The SBE-cache path can replan a cached foreign `$lookup` hash join before the trial if that join is no longer eligible. This differs from the classic-engine works feedback described by Percona. (medium confidence) (verified as of 2026-10-20) [source]
Facts and statements
- MongoDB's plan-cache README says the classic cache is per collection, the SBE cache is one cache per `mongod`, and each SBE entry wraps a complete `sbe::PlanStage` execution tree. In the pinned `get_executor.cpp` source, a class-hierarchy comment names both classic-cache and SBE-cache helper variants; the file defines the classic-cache helper and mentions the SBE-cache variant only in that comment. (high confidence) (verified as of 2026-10-20) [source]
- In classic_runtime_planner_for_sbe, attemptToUsePlan treats a missing decisionReads value as a pinned-entry signal and returns SingleSolutionPassthroughPlanner before building the normal TrialRunTracker read-budget trial. MongoDB's README names single-solution and rooted $or queries as pinned examples and says standard cache eviction can still remove pinned plans. (high confidence) (verified as of 2026-10-20) [source]
- For a nonpinned SBE cache hit with decisionReads, the SBE classic runtime planner sets the trial read budget to internalQueryCacheEvictionRatio multiplied by decisionReads; it deactivates the entry and replans if TrialRunTracker exhausts that budget. SERVER-85238 defines the cached decision read count as totalKeysExamined plus totalDocsExamined. (high confidence) (verified as of 2026-10-20) [source]
- The pinned-entry passthrough does not cover every forced-replan path: PlannerGeneratorFromSbeCacheEntry checks whether a cached foreign $lookup hash-join remains eligible before it calls attemptToUsePlan, and calls replan if that eligibility check fails. (high confidence) (verified as of 2026-10-20) [source]
- The supplied canonical_query_encoder.cpp commit uses separate legacy key tags for classic plans, SBE-compatible non-subplanner plans, and SBE $or subplanner entries. The distinct subplanner tag means that an entry without ordinary reads or works should not automatically be classified as a pinned entry. (high confidence) [source]
- JusDB's December 8, 2025 article reports a MongoDB 7.0 SBE plan-cache eviction defect and says the fix starts in 7.0.4 or 7.1; this is historical cache-size and eviction context, not evidence about pinned-entry trial behavior. (low confidence) (verified as of 2025-12-08) [source]
- The plan-cache README identifies single-solution and rooted `$or` plans as pinned examples in the SBE cache. Pinned entries lack ordinary `works` or `reads` feedback and bypass the normal read-budget trial, although standard cache eviction can still remove them. The pinned `cached_planner.cpp` path checks whether a cached foreign `$lookup` hash join remains eligible before `attemptToUsePlan` checks `decisionReads` for the pinned-entry bypass; if that join is no longer eligible, the planner replans immediately. The sources therefore support skipping threshold-based cached-plan validation for pinned entries, but not a guarantee that every replan path is bypassed. (high confidence) (verified as of 2026-10-20) [source]
Children
- No children recorded.