Interval evaluation trees and parameterized plan caching
Parent: SORT_MERGE and $in sort expansion · Published reference · snapshot 2026-10-23 · skill mongodb-cohort-46673b83291a
↓ Facts as markdown↓ Portable .llms packagent context libraries
Source-anchored research for Interval evaluation trees and parameterized plan caching. 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.
Structure and components
- Without an eligible sort, this SBE $in-length key component is omitted. With a sort, changing eligible $in values while preserving their unique count can retain the key; changing a below-cap count changes that component. Other cache-key properties must still match. (high confidence) [source 1] [source 2]
How it works
- At revision 35647d07bc4bc11966c90fe7100eb1db0b0ac1d9, the SBE encoder includes the number of unique $in equalities when the expression is parameterized and the query has a sort. It encodes min(maxScansToExplode + 1, equalityCount), separating potentially different branch counts while allowing larger non-explodable lists to share that discriminator. This extra count is omitted without a sort. (high confidence) [source 1] [source 2]
- The Sydney researchers vary predicate selectivity (with two-range-predicate queries of controlled selectivity) to study which plan MongoDB chooses. Percona says that if data distribution changes without being bad enough to trigger replanning, MongoDB keeps using the cached plan, which may no longer be the best one, and that unstable data distribution or low-selectivity indexes can cause re-planning loops with degraded performance. Sources: https://15799.courses.cs.cmu.edu/spring2025/papers/23-mongodb/tao-adc2024.pdf ; https://www.percona.com/blog/mongodb-query-plan-cache-explained-performance-pitfalls-and-re-planning/ [source 1] [source 2]
- SERVER-97685, last updated December 6, 2024, says IETs were then unused because the SBE plan cache was disabled and flags large-IET construction/cloning problems for a future re-enable. This scopes the architecture description: source-code support does not establish that a given deployed version enables that path. (low confidence) (verified as of 2024-12-06) [source]
Problems, failure modes and limitations
- Validate parameterized cache reuse with ordinary query executions and $planCacheStats inspection. The MongoDB regression test executes queries to create/activate entries and checks results and cache entries; explain() alone cannot prove reuse because the manual says it ignores existing entries and creates no new entry. (high confidence) Sources: https://raw.githubusercontent.com/mongodb/mongo/35647d07bc4bc11966c90fe7100eb1db0b0ac1d9/jstests/core/query/plan_cache/in_expression_plan_cache.js ; https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md [source 1] [source 2] [source 3]
- SERVER-66459 documented a correctness failure: explode-for-sort discarded the IETs attached to the original IndexScanNode, so downstream code embedded fixed KeyString bounds and cached reuse with different constants could give incorrect or missing results. SERVER-67576 states that SERVER-66459 planned a quick fix of prohibiting explode-for-sort query solutions from being cached, and that SERVER-67576's own work was to re-enable the SBE plan cache in combination with explode for sort. These are historical defects, not evidence that every current sorted $in query is wrong. Sources: https://jira.mongodb.org/browse/SERVER-66459 ; https://jira.mongodb.org/browse/SERVER-67576 [source 1] [source 2]
Comparisons and alternatives
- With SBE auto-parameterization, auto-parameterized plans read constants from the RuntimeEnvironment instead of inlined constants. When an auto-parameterized predicate becomes index bounds, the IndexBoundsBuilder records it in an IntervalEvaluationTree (IET), which allows the index bounds to be recomputed when the plan is bound to new parameter values. Sources: https://jira.mongodb.org/browse/SERVER-66459 ; https://jira.mongodb.org/browse/SERVER-73589 [source 1] [source 2] [source 3]
- SERVER-90415 records a change for 8.0 and master release builds to use the classic plan cache instead of the SBE cache, while retaining the SBE cache under the SBE-full feature flag. Its fix versions include 8.0.0-rc7 and 8.1.0-rc0. Therefore SBE execution alone does not establish that IET-based SBE cache reuse occurred. (low confidence) (verified as of 2026-09-21) [source]
- Inspect actual cache entries with getPlanCache().list() or $planCacheStats when investigating reuse across different $in values or cardinalities. Inspect planCacheKey and cache state alongside the query, rather than assuming parameterization from similar query text. (high confidence) Sources: https://www.mongodb.com/docs/manual/reference/method/PlanCache.list.md ; https://www.mongodb.com/docs/manual/reference/operator/aggregation/planCacheStats.md ; https://raw.githubusercontent.com/mongodb/mongo/35647d07bc4bc11966c90fe7100eb1db0b0ac1d9/jstests/core/query/plan_cache/in_expression_plan_cache.js ; https://jira.mongodb.org/browse/SERVER-89436 [source 1] [source 2] [source 3] [source 4] [source 5] [source 6]
Facts and statements
- At revision 35647d07bc4bc11966c90fe7100eb1db0b0ac1d9, isOilExplodable requires a nonempty union of point intervals. If an IET is present, it accepts only ConstNode or an EvalNode for EQ/MATCH_IN; union/intersection IETs can change interval counts after rebinding and are rejected. This protects the cached sort-merge branch count. (high confidence) [source 1] [source 2] [source 3]
- In the inspected planner revision, exploded scans wrap appropriate source IETs in ExplodeNode with an explosion identity and interval position. Unexploded suffix IETs are copied into each child. This associates a reused child scan with its intended regenerated point interval. (low confidence) [source]
- Classic and SBE plan-cache reuse have different structural constraints: the classic cache maps a generously parameterized query shape to a description of which index(es) to use and, on a hit, a new query execution tree is built for the incoming query, whereas the SBE cache maps a more conservatively parameterized shape to an actual SBE plan that can be cloned and run. The $in regression test explains that classic applies explode-for-sort after retrieving from the plan cache. Sources: https://jira.mongodb.org/browse/SERVER-89436 ; https://raw.githubusercontent.com/mongodb/mongo/35647d07bc4bc11966c90fe7100eb1db0b0ac1d9/jstests/core/query/plan_cache/in_expression_plan_cache.js [source 1] [source 2] [source 3]
- The 2024 First Past the Post paper explicitly disables query-plan caching in its experiments. Its optimizer results provide selectivity context, not experimental validation of IET correctness or parameterized cache-hit behavior. (low confidence) [source]
- Plan caching avoids repeated planning for compatible query shapes. Literal changes can reuse a plan, but eligibility and cache-key discrimination still matter; sharing a broad query shape does not guarantee the same cache entry. (high confidence) Sources: https://jira.mongodb.org/browse/SERVER-89436 ; https://raw.githubusercontent.com/mongodb/mongo/35647d07bc4bc11966c90fe7100eb1db0b0ac1d9/jstests/core/query/plan_cache/in_expression_plan_cache.js ; https://www.mongodb.com/docs/manual/reference/method/PlanCache.list.md [source 1] [source 2] [source 3] [source 4] [source 5] [source 6]
- The SBE plan cache maps a conservatively parameterized query shape to an actual SBE plan which can be cloned and then run, and auto-parameterized plans read constants from the RuntimeEnvironment. The classic cache maps a generously parameterized version of the query to a description of which index(es) to use to answer the query; on a hit a new query execution tree is built. Sources: https://jira.mongodb.org/browse/SERVER-89436 ; https://jira.mongodb.org/browse/SERVER-73589 [source 1] [source 2]
- SERVER-67576 records the caching improvement as fixed in 7.0.0-rc0 and resolved on March 22, 2023. Its description proposes runtime branch creation as one possible approach; that proposal alone does not establish the implemented strategy. (low confidence) (verified as of 2023-10-29) [source]
Children
- No children recorded.