Skip to content

Commit

Permalink
having and count() estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
englefly committed Aug 12, 2024
1 parent 0520b2f commit 6f649e7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,9 @@ public ColumnStatistic visitMax(Max max, Statistics context) {
@Override
public ColumnStatistic visitCount(Count count, Statistics context) {
double width = count.getDataType().width();
return new ColumnStatisticBuilder().setCount(1D).setAvgSizeByte(width).setNumNulls(0)
// for scalar agg, ndv and row count will be normalized by 1 in StatsCalculator.computeAggregate()
return new ColumnStatisticBuilder().setNdv(context.getRowCount()).setCount(context.getRowCount())
.setAvgSizeByte(width).setNumNulls(0)
.setDataSize(width).setMinValue(0).setMaxValue(context.getRowCount())
.setMaxExpr(null).setMinExpr(null).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ public Statistics visitComparisonPredicate(ComparisonPredicate cp, EstimationCon
}
return false;
};
boolean leftAgg = left.anyMatch(containsAggSlot);
boolean rightAgg = right.anyMatch(containsAggSlot);
// It means this predicate appears in HAVING clause.
if (leftAgg || rightAgg) {
double rowCount = context.statistics.getRowCount();
double newRowCount = Math.max(rowCount * DEFAULT_HAVING_COEFFICIENT,
Math.max(statsForLeft.ndv, statsForRight.ndv));
return context.statistics.withRowCount(newRowCount);
}
// boolean leftAgg = left.anyMatch(containsAggSlot);
// boolean rightAgg = right.anyMatch(containsAggSlot);
// // It means this predicate appears in HAVING clause.
// if (leftAgg || rightAgg) {
// double rowCount = context.statistics.getRowCount();
// double newRowCount = Math.max(rowCount * 0.5,
// Math.max(statsForLeft.ndv, statsForRight.ndv));
// return context.statistics.withRowCount(newRowCount);
// }
}
if (!left.isConstant() && !right.isConstant()) {
return calculateWhenBothColumn(cp, context, statsForLeft, statsForRight);
Expand Down

0 comments on commit 6f649e7

Please sign in to comment.