englefly commented on code in PR #40698: URL: https://github.com/apache/doris/pull/40698#discussion_r1756021675
########## fe/fe-core/src/main/java/org/apache/doris/nereids/stats/ExpressionEstimation.java: ########## @@ -430,7 +457,14 @@ public ColumnStatistic visitBoundFunction(BoundFunction boundFunction, Statistic @Override public ColumnStatistic visitAggregateExpression(AggregateExpression aggregateExpression, Statistics context) { - return aggregateExpression.child().accept(this, context); + ColumnStatistic columnStat = aggregateExpression.child().accept(this, context); + if (columnStat.isUnKnown) { + return ColumnStatistic.UNKNOWN; + } + return new ColumnStatisticBuilder(columnStat) + .setMinExpr(null).setMinValue(Double.NEGATIVE_INFINITY) Review Comment: keep the min/max ########## fe/fe-core/src/main/java/org/apache/doris/nereids/stats/ExpressionEstimation.java: ########## @@ -344,6 +351,8 @@ public ColumnStatistic visitMin(Min min, Statistics context) { } // if this is scalar agg, we will update count and ndv to 1 when visiting group clause return new ColumnStatisticBuilder(columnStat) + .setMinExpr(null).setMinValue(Double.NEGATIVE_INFINITY) Review Comment: min/max of Min(A) is the same as that of A. ########## fe/fe-core/src/main/java/org/apache/doris/nereids/stats/ExpressionEstimation.java: ########## @@ -356,27 +365,45 @@ public ColumnStatistic visitMax(Max max, Statistics context) { } // if this is scalar agg, we will update count and ndv to 1 when visiting group clause return new ColumnStatisticBuilder(columnStat) + .setMinExpr(null).setMinValue(Double.NEGATIVE_INFINITY) Review Comment: min/max of Max(A) is the same as that of A ########## fe/fe-core/src/main/java/org/apache/doris/nereids/stats/FilterEstimation.java: ########## @@ -332,7 +332,8 @@ private Statistics estimateEqualTo(ComparisonPredicate cp, ColumnStatistic stats } else { double val = statsForRight.maxValue; if (val > statsForLeft.maxValue || val < statsForLeft.minValue) { - selectivity = 0.0; + // do a lower bound protection to avoid using 0 directly + selectivity = RANGE_SELECTIVITY_THRESHOLD; Review Comment: 不必在这里限制。所有的比较操作,我们统一限制了。 ########## fe/fe-core/src/main/java/org/apache/doris/nereids/stats/ExpressionEstimation.java: ########## @@ -356,27 +365,45 @@ public ColumnStatistic visitMax(Max max, Statistics context) { } // if this is scalar agg, we will update count and ndv to 1 when visiting group clause return new ColumnStatisticBuilder(columnStat) + .setMinExpr(null).setMinValue(Double.NEGATIVE_INFINITY) + .setMaxExpr(null).setMaxValue(Double.POSITIVE_INFINITY) .build(); } @Override public ColumnStatistic visitCount(Count count, Statistics context) { double width = count.getDataType().width(); // for scalar agg, ndv and row count will be normalized by 1 in StatsCalculator.computeAggregate() - return new ColumnStatisticBuilder(ColumnStatistic.UNKNOWN).setCount(context.getRowCount()) - .setAvgSizeByte(width).build(); + return new ColumnStatisticBuilder(ColumnStatistic.UNKNOWN) + .setCount(context.getRowCount()) + .setAvgSizeByte(width) + .build(); } // TODO: return a proper estimated stat after supports histogram @Override public ColumnStatistic visitSum(Sum sum, Statistics context) { - return sum.child().accept(this, context); + ColumnStatistic columnStat = sum.child().accept(this, context); + if (columnStat.isUnKnown) { + return ColumnStatistic.UNKNOWN; + } + return new ColumnStatisticBuilder(columnStat) + .setMinExpr(null).setMinValue(Double.NEGATIVE_INFINITY) + .setMaxExpr(null).setMaxValue(Double.POSITIVE_INFINITY) + .build(); } // TODO: return a proper estimated stat after supports histogram @Override public ColumnStatistic visitAvg(Avg avg, Statistics context) { - return avg.child().accept(this, context); + ColumnStatistic columnStat = avg.child().accept(this, context); + if (columnStat.isUnKnown) { + return ColumnStatistic.UNKNOWN; + } + return new ColumnStatisticBuilder(columnStat) + .setMinExpr(null).setMinValue(Double.NEGATIVE_INFINITY) Review Comment: min/max of Avg(A) is the same as that of A -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org