englefly commented on code in PR #22000:
URL: https://github.com/apache/doris/pull/22000#discussion_r1271456350
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java:
##########
@@ -687,37 +687,32 @@ private Statistics computeLimit(Limit limit) {
private double estimateGroupByRowCount(List<Expression>
groupByExpressions, Statistics childStats) {
double rowCount = 1;
- Map<Expression, ColumnStatistic> groupByColStats = new HashMap<>();
- for (Expression groupByExpr : groupByExpressions) {
- ColumnStatistic colStats =
childStats.findColumnStatistics(groupByExpr);
- if (colStats == null) {
- colStats = ExpressionEstimation.estimate(groupByExpr,
childStats);
- }
- groupByColStats.put(groupByExpr, colStats);
+ List<Double> groupByNdvs = groupByExpressions.stream()
+ .map(groupByExpr -> {
+ ColumnStatistic colStats =
childStats.findColumnStatistics(groupByExpr);
+ if (colStats == null) {
+ colStats = ExpressionEstimation.estimate(groupByExpr,
childStats);
+ }
+ return colStats.isUnKnown() ? -1 : colStats.ndv;
+ })
+ .sorted(Comparator.reverseOrder())
+ .collect(Collectors.toList());
+ if (groupByExpressions.isEmpty()) {
+ return 1;
}
- int groupByCount = groupByExpressions.size();
- if
(groupByColStats.values().stream().anyMatch(ColumnStatistic::isUnKnown)) {
+ if (groupByNdvs.stream().anyMatch(ndv -> ndv == -1)) {
Review Comment:
isUnknown is not equal to "ndv==-1".
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java:
##########
@@ -687,37 +687,32 @@ private Statistics computeLimit(Limit limit) {
private double estimateGroupByRowCount(List<Expression>
groupByExpressions, Statistics childStats) {
double rowCount = 1;
- Map<Expression, ColumnStatistic> groupByColStats = new HashMap<>();
- for (Expression groupByExpr : groupByExpressions) {
- ColumnStatistic colStats =
childStats.findColumnStatistics(groupByExpr);
- if (colStats == null) {
- colStats = ExpressionEstimation.estimate(groupByExpr,
childStats);
- }
- groupByColStats.put(groupByExpr, colStats);
+ List<Double> groupByNdvs = groupByExpressions.stream()
+ .map(groupByExpr -> {
+ ColumnStatistic colStats =
childStats.findColumnStatistics(groupByExpr);
+ if (colStats == null) {
+ colStats = ExpressionEstimation.estimate(groupByExpr,
childStats);
+ }
+ return colStats.isUnKnown() ? -1 : colStats.ndv;
Review Comment:
never set ndv to -1
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]