-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Query Optimization
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Overview
Estimates served from persisted NDV statistics (analyze mode "ndv", SERVER-131760) currently report EstimationSource::Sampling, which keeps downstream ranking behavior identical to the sample-based estimate but misstates the provenance. Introduce a dedicated source value.
Background
Raised in review of SERVER-131760. Metadata was considered and rejected: it is absorbed by Sampling in the source-merge table, but clampZeroEstimate() treats the two differently (Sampling zeros are bumped to kMinCE, Metadata zeros are not), and join selectivity is 1 / NDV. Provenance is meanwhile visible in explain via
queryPlanner.fieldStatsMetadata (SERVER-131761), so nothing is lost today.
Scope of work
- Add the new value to EstimationSource (estimates.h) and extend the source-merge state table in estimates.cpp (its switches end in MONGO_UNREACHABLE_TASSERT defaults). Decide deliberately how it merges with Sampling: merging to Mixed would flip most join estimates to Mixed, since persisted NDVs combine with sample-derived cardinalities.
- Extend clampZeroEstimate() in cardinality_estimator.cpp.
- Extend the query stats ceMethods mapping in get_executor_helpers.cpp and its IDL counterpart.
- Switch the read path (SamplingEstimatorImpl::tryEstimateNDVFromPersistentStats) to the new source and update affected explain/unit tests.
- is related to
-
SERVER-131761 Add explain metadata for persisted NDV statistics
-
- In Code Review
-
-
SERVER-131760 Consult persisted NDV statistics in estimateNDV()
-
- Closed
-