-
Type:
Task
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Query Optimization
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Problem
The legacy-format SBE explain omits numKeysEstimate, numDocsEstimate and indexSeekEstimate for cost-based ranker (CBR) estimates, while the classic engine's legacy explain and SBE's V3 explain both report them.
Details
- Classic (statsToBSON in src/mongo/db/query/plan_explainer_impl.cpp) calls QSNEstimate::serialize() and then additionally appends numKeysEstimate (IXSCAN) or numDocsEstimate (other stages) from inCE, and indexSeekEstimate from indexSeekCE.
- SBE V3 explain (appendCostBasedStatsV3) emits the same three fields under statistics.costBased.
- SBE legacy explain (qsnToBson in src/mongo/db/query/plan_explainer_sbe.cpp, non-V3 branch) calls only estimates.at(node)->serialize(*bob), which emits costEstimate, cardinalityEstimate and estimatesMetadata.
The estimates are computed regardless of engine (indexSeekCE is set in cardinality_estimator.cpp); they are just not serialized in the SBE legacy path.
Reproduction
Run jstests/noPassthroughWithMongod/query/cbr/cbr_stage_costing.js with {{--mongodSetParameters='
{internalQueryFrameworkControl: trySbeEngine}'}} (or featureFlagSbeFull) and the checkSbeFullyEnabled early exit removed. It fails at the indexSeekEstimate assertion in runTest: the IXSCAN stage has costEstimate, cardinalityEstimate and estimatesMetadata but no indexSeekEstimate.
Proposed fix
In the legacy branch of qsnToBson, append numKeysEstimate/numDocsEstimate and indexSeekEstimate the same way classic does, ideally via a helper shared with statsToBSON. Add coverage in plan_explainer_test.cpp and remove the SBE early exits from the CBR jstests that depend on these fields.
Related
SERVER-130179(plumbed estimates into SBE explain for the release config)- SERVER-136769 (stale TODOs referencing
SERVER-130179)