-
Type: Task
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
-
Query Optimization
-
Fully Compatible
-
QO 2024-12-23
Extend CE and cost estimation of CBR for projection nodes. As a starting point use the patch below. Notice that this patch fixes a problem with incorrect CE for sort nodes. This patch also uncovers a problem with popping the selectivity stack for conjunction breaker QSN nodes.
diff --git a/src/mongo/db/query/cost_based_ranker/cardinality_estimator.cpp b/src/mongo/db/query/cost_based_ranker/cardinality_estimator.cpp index d421dfdff57..97169272eaf 100644 --- a/src/mongo/db/query/cost_based_ranker/cardinality_estimator.cpp +++ b/src/mongo/db/query/cost_based_ranker/cardinality_estimator.cpp @@ -70,9 +70,13 @@ CEResult CardinalityEstimator::estimate(const QuerySolutionNode* node) { break; case STAGE_SORT_DEFAULT: case STAGE_SORT_SIMPLE: - ceRes = _inputCard; + case STAGE_PROJECTION_DEFAULT: + case STAGE_PROJECTION_COVERED: + case STAGE_PROJECTION_SIMPLE: { + ceRes = estimate(node->children[0].get()); isConjunctionBreaker = true; break; + } default: MONGO_UNIMPLEMENTED_TASSERT(9586709); } diff --git a/src/mongo/db/query/cost_based_ranker/cost_estimator.cpp b/src/mongo/db/query/cost_based_ranker/cost_estimator.cpp index 4aae1562848..4beacc02845 100644 --- a/src/mongo/db/query/cost_based_ranker/cost_estimator.cpp +++ b/src/mongo/db/query/cost_based_ranker/cost_estimator.cpp @@ -132,6 +132,12 @@ CostEstimate CostEstimator::costNode(const QuerySolutionNode* node, } break; } + case STAGE_PROJECTION_DEFAULT: + case STAGE_PROJECTION_COVERED: + case STAGE_PROJECTION_SIMPLE: { + nodeCost = projectionStartup * oneCE + projectionIncrement * ce; + break; + } default: MONGO_UNIMPLEMENTED_TASSERT(9695102); } @@ -192,4 +198,7 @@ const CostCoefficient CostEstimator::sortedMergeStartup = minCC; const CostCoefficient CostEstimator::sortedMergeIncrement = CostCoefficient{CostCoefficientType{100.0_ms}}; +const CostCoefficient CostEstimator::projectionStartup = minCC; +const CostCoefficient CostEstimator::projectionIncrement = minCC; + } // namespace mongo::cost_based_ranker diff --git a/src/mongo/db/query/cost_based_ranker/cost_estimator.h b/src/mongo/db/query/cost_based_ranker/cost_estimator.h index ac7a2c6312d..5196eedf9f0 100644 --- a/src/mongo/db/query/cost_based_ranker/cost_estimator.h +++ b/src/mongo/db/query/cost_based_ranker/cost_estimator.h @@ -84,6 +84,9 @@ private: static const CostCoefficient sortedMergeStartup; static const CostCoefficient sortedMergeIncrement; + static const CostCoefficient projectionStartup; + static const CostCoefficient projectionIncrement; + EstimateMap& _estimateMap; };
- fixes
-
SERVER-98190 Complete TODO listed in SERVER-97529
- Closed
- is related to
-
SERVER-98190 Complete TODO listed in SERVER-97529
- Closed