[opt](nereids) set lower bound for range-selectivity(2.1) (#41061)

## Proposed changes
pick #40089
Issue Number: close #xxx

<!--Describe your changes.-->
This commit is contained in:
minghong
2024-09-22 07:32:22 +08:00
committed by GitHub
parent d1d52ae68c
commit 9dc55f90eb
5 changed files with 66 additions and 69 deletions

View File

@ -71,6 +71,9 @@ import java.util.function.Predicate;
*/
public class FilterEstimation extends ExpressionVisitor<Statistics, EstimationContext> {
public static final double DEFAULT_INEQUALITY_COEFFICIENT = 0.5;
// "Range selectivity is prone to producing outliers, so we add this threshold limit.
// The threshold estimation is calculated based on selecting one month out of fifty years."
public static final double RANGE_SELECTIVITY_THRESHOLD = 0.0016;
public static final double DEFAULT_IN_COEFFICIENT = 1.0 / 3.0;
public static final double DEFAULT_HAVING_COEFFICIENT = 0.01;
@ -627,6 +630,8 @@ public class FilterEstimation extends ExpressionVisitor<Statistics, EstimationCo
: intersectRange.getDistinctValues() / leftRange.getDistinctValues();
if (!(dataType instanceof RangeScalable) && (sel != 0.0 && sel != 1.0)) {
sel = DEFAULT_INEQUALITY_COEFFICIENT;
} else if (sel < RANGE_SELECTIVITY_THRESHOLD) {
sel = RANGE_SELECTIVITY_THRESHOLD;
}
sel = getNotNullSelectivity(leftStats, sel);
updatedStatistics = context.statistics.withSel(sel);