Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[opt](nereids)stats derive for min()/max() agg function #40126

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,9 @@ public ColumnStatistic visitMin(Min min, Statistics context) {
if (columnStat.isUnKnown) {
return ColumnStatistic.UNKNOWN;
}
/*
we keep columnStat.min and columnStat.max, but set ndv=1.
if there is group-by keys, we will update count when visiting group clause
*/
double width = min.child().getDataType().width();
return new ColumnStatisticBuilder().setCount(1).setNdv(1).setAvgSizeByte(width)
.setMinValue(columnStat.minValue).setMinExpr(columnStat.minExpr)
.setMaxValue(columnStat.maxValue).setMaxExpr(columnStat.maxExpr).build();
// if this is scalar agg, we will update count and ndv to 1 when visiting group clause
englefly marked this conversation as resolved.
Show resolved Hide resolved
return new ColumnStatisticBuilder(columnStat)
.build();
}

@Override
Expand All @@ -359,14 +354,8 @@ public ColumnStatistic visitMax(Max max, Statistics context) {
if (columnStat.isUnKnown) {
return ColumnStatistic.UNKNOWN;
}
/*
we keep columnStat.min and columnStat.max, but set ndv=1.
if there is group-by keys, we will update count when visiting group clause
*/
int width = max.child().getDataType().width();
return new ColumnStatisticBuilder().setCount(1D).setNdv(1D).setAvgSizeByte(width)
.setMinValue(columnStat.minValue).setMinExpr(columnStat.minExpr)
.setMaxValue(columnStat.maxValue).setMaxExpr(columnStat.maxExpr)
// if this is scalar agg, we will update count and ndv to 1 when visiting group clause
return new ColumnStatisticBuilder(columnStat)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void test1() {
ColumnStatistic estimated = ExpressionEstimation.estimate(max, stat);
Assertions.assertEquals(0, estimated.minValue);
Assertions.assertEquals(500, estimated.maxValue);
Assertions.assertEquals(1, estimated.ndv);
Assertions.assertEquals(500, estimated.ndv);
}

// MIN(a)
Expand All @@ -95,7 +95,7 @@ public void test2() {
ColumnStatistic estimated = ExpressionEstimation.estimate(max, stat);
Assertions.assertEquals(0, estimated.minValue);
Assertions.assertEquals(1000, estimated.maxValue);
Assertions.assertEquals(1, estimated.ndv);
Assertions.assertEquals(500, estimated.ndv);
}

// a + b
Expand Down
Loading