Skip to content

Commit

Permalink
[opt](nereids) refine operator estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongjian.xzj authored and zhongjian.xzj committed Sep 24, 2024
1 parent e31bdd4 commit d17fe57
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ public Statistics visitCompoundPredicate(CompoundPredicate predicate, Estimation
leftStats.normalizeColumnStatistics(context.statistics.getRowCount(), true);
Statistics andStats = rightExpr.accept(this, new EstimationContext(leftStats));
if (predicate instanceof And) {
// TODO: this will cause estimation change
//andStats.normalizeColumnStatistics();
andStats.normalizeColumnStatistics(context.statistics.getRowCount(), true);
return andStats;
} else if (predicate instanceof Or) {
Statistics rightStats = rightExpr.accept(this, context);
Expand Down Expand Up @@ -309,8 +308,7 @@ private Optional<DateLiteral> tryConvertStrLiteralToDateLiteral(LiteralExpr lite
}

private Statistics estimateColumnEqualToConstant(ComparisonPredicate cp, ColumnStatistic statsForLeft,
ColumnStatistic statsForRight,
EstimationContext context) {
ColumnStatistic statsForRight, EstimationContext context) {
double selectivity;
if (statsForLeft.isUnKnown) {
selectivity = DEFAULT_INEQUALITY_COEFFICIENT;
Expand All @@ -327,8 +325,8 @@ private Statistics estimateColumnEqualToConstant(ComparisonPredicate cp, ColumnS
} else {
double val = statsForRight.maxValue;
if (val > statsForLeft.maxValue || val < statsForLeft.minValue) {
// TODO: make sure left's stats is RangeScalable whose min/max is trustable
// The equal to constant which don't rely on the range, so maybe safe here.
// TODO: make sure left's stats is RangeScalable whose min/max is trustable.
// The equal to constant doesn't rely on the range, so maybe safe here.
selectivity = 0.0;
} else if (ndv >= 1.0) {
selectivity = StatsMathUtil.minNonNaN(1.0, 1.0 / ndv);
Expand All @@ -345,8 +343,8 @@ private Statistics estimateColumnEqualToConstant(ComparisonPredicate cp, ColumnS
if (!(left instanceof SlotReference)) {
left.accept(new ColumnStatsAdjustVisitor(), equalStats);
}
// TODO: normalizeColumnStatistics() will have problem after ColumnStatsAdjustVisitor
//equalStats.normalizeColumnStatistics();
// normalize column statistics here to sync numNulls by proportion and ndv by current row count
equalStats.normalizeColumnStatistics(context.statistics.getRowCount(), true);
return equalStats;
}

Expand Down Expand Up @@ -645,7 +643,8 @@ private Statistics estimateColumnToConstantRange(Expression leftExpr, DataType d
updatedStatistics.addColumnStats(leftExpr, leftColumnStatisticBuilder.build());
context.addKeyIfSlot(leftExpr);
leftExpr.accept(new ColumnStatsAdjustVisitor(), updatedStatistics);
updatedStatistics.normalizeColumnStatistics();
// normalize column statistics here to sync numNulls by proportion and ndv by current row count
updatedStatistics.normalizeColumnStatistics(context.statistics.getRowCount(), true);

return updatedStatistics;
}
Expand Down

0 comments on commit d17fe57

Please sign in to comment.