summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/ce/histogram_estimation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/query/ce/histogram_estimation.cpp')
-rw-r--r--src/mongo/db/query/ce/histogram_estimation.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/mongo/db/query/ce/histogram_estimation.cpp b/src/mongo/db/query/ce/histogram_estimation.cpp
index fbd041380b4..52851e5118f 100644
--- a/src/mongo/db/query/ce/histogram_estimation.cpp
+++ b/src/mongo/db/query/ce/histogram_estimation.cpp
@@ -95,14 +95,16 @@ EstimationResult interpolateEstimateInBucket(const ScalarHistogram& h,
}
}
- resultCard += bucket._rangeFreq * ratio;
+ const double bucketFreqRatio = bucket._rangeFreq * ratio;
+ resultCard += bucketFreqRatio;
resultNDV += bucket._ndv * ratio;
if (type == EstimationType::kLess) {
// Subtract from the estimate the cardinality and ndv corresponding to the equality
- // operation.
+ // operation, if they are larger than the ratio taken from this bucket.
+ const double innerEqFreqCorrection = (bucketFreqRatio < innerEqFreq) ? 0.0 : innerEqFreq;
const double innerEqNdv = (bucket._ndv * ratio <= 1.0) ? 0.0 : 1.0;
- resultCard -= innerEqFreq;
+ resultCard -= innerEqFreqCorrection;
resultNDV -= innerEqNdv;
}
return {resultCard, resultNDV};