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 8d075e2 commit e4d4e91
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ private static Statistics estimateSemiOrAnti(Statistics leftStats, Statistics ri
.putColumnStatistics(rightStats.columnStatistics())
.build();
}
updateJoinConditionColumnStatistics(result, join);
result.normalizeColumnStatistics();
return result;
}
Expand All @@ -306,7 +305,6 @@ private static Statistics estimateSemiOrAnti(Statistics leftStats, Statistics ri
double baseRowCount =
join.getJoinType().isLeftSemiOrAntiJoin() ? leftStats.getRowCount() : rightStats.getRowCount();
rowCount = Math.min(innerJoinStats.getRowCount(), baseRowCount);
updateJoinConditionColumnStatistics(innerJoinStats, join);
return innerJoinStats.withRowCountAndEnforceValid(rowCount);
} else {
/*double crossRowCount = Math.max(1, leftStats.getRowCount()) * Math.max(1, rightStats.getRowCount());
Expand Down Expand Up @@ -336,7 +334,6 @@ private static Statistics estimateSemiOrAnti(Statistics leftStats, Statistics ri
}
builder.setRowCount(outputRowCount);
Statistics outputStats = builder.build();
updateJoinConditionColumnStatistics(outputStats, join);
outputStats.normalizeColumnStatistics();
return outputStats;*/
StatisticsBuilder builder;
Expand Down Expand Up @@ -366,7 +363,9 @@ public static Statistics estimate(Statistics leftStats, Statistics rightStats, J
.build();
Statistics innerJoinStats = estimateInnerJoin(leftStats, rightStats, join);
if (joinType.isSemiOrAntiJoin()) {
return estimateSemiOrAnti(leftStats, rightStats, innerJoinStats, join);
Statistics outputStats = estimateSemiOrAnti(leftStats, rightStats, innerJoinStats, join);
updateJoinConditionColumnStatistics(outputStats, join);
return outputStats;
} else if (joinType == JoinType.INNER_JOIN) {
updateJoinConditionColumnStatistics(innerJoinStats, join);
return innerJoinStats;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ public void normalizeColumnStatistics(double inputRowCount, boolean isNumNullsDe
// the following columnStatistic.isUnKnown() judgment is loop inside since current doris
// supports partial stats deriving, i.e, allowing part of tables have stats and other parts don't,
// or part of columns have stats but other parts don't, especially join and filter estimation.
if (!checkColumnStatsValid(columnStatistic, inputRowCount) && !columnStatistic.isUnKnown()) {
if (!checkColumnStatsValid(columnStatistic, rowCount) && !columnStatistic.isUnKnown()) {
ColumnStatisticBuilder columnStatisticBuilder = new ColumnStatisticBuilder(columnStatistic);
double ndv = Math.min(columnStatistic.ndv, inputRowCount);
double numNulls = Math.min(columnStatistic.numNulls * factor, inputRowCount - ndv);
double ndv = Math.min(columnStatistic.ndv, rowCount);
double numNulls = Math.min(columnStatistic.numNulls * factor, rowCount - ndv);
columnStatisticBuilder.setNumNulls(numNulls);
columnStatisticBuilder.setNdv(Math.min(ndv, rowCount - numNulls));
columnStatistic = columnStatisticBuilder.build();
Expand Down

0 comments on commit e4d4e91

Please sign in to comment.