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 fe85004 commit 3799841
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ public Statistics visitNot(Not not, EstimationContext context) {
|| child instanceof Match,
"Not-predicate meet unexpected child: %s", child.toSql());
if (child instanceof Like) {
rowCount = context.statistics.getRowCount() - childStats.getRowCount();
colBuilder.setNdv(Math.max(1.0, originColStats.ndv - childColStats.ndv));
} else if (child instanceof InPredicate) {
colBuilder.setNdv(Math.max(1.0, originColStats.ndv - childColStats.ndv));
Expand All @@ -529,6 +530,7 @@ public Statistics visitNot(Not not, EstimationContext context) {
.setMaxValue(originColStats.maxValue)
.setMaxExpr(originColStats.maxExpr);
} else if (child instanceof Match) {
rowCount = context.statistics.getRowCount() - childStats.getRowCount();
colBuilder.setNdv(Math.max(1.0, originColStats.ndv - childColStats.ndv));
}
if (not.child().getInputSlots().size() == 1 && !(child instanceof IsNull)) {
Expand All @@ -550,8 +552,7 @@ public Statistics visitIsNull(IsNull isNull, EstimationContext context) {
double row = context.statistics.getRowCount() * DEFAULT_ISNULL_SELECTIVITY;
return new StatisticsBuilder(context.statistics).setRowCount(row).build();
}
double childOutputRowCount = context.statistics.getRowCount();
double outputRowCount = Math.min(childColStats.numNulls, childOutputRowCount);
double outputRowCount = Math.min(childColStats.numNulls, context.statistics.getRowCount());
if (!isOnBaseTable) {
// for is null on base table, use the numNulls, otherwise
// nulls will be generated such as outer join and then we do a protection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ private static Statistics estimateSemiOrAnti(Statistics leftStats, Statistics ri
rowCount = Math.min(innerJoinStats.getRowCount(), baseRowCount);
return innerJoinStats.withRowCountAndEnforceValid(rowCount);
} else {
// TODO: tuning the new semi/anti estimation method
/*double crossRowCount = Math.max(1, leftStats.getRowCount()) * Math.max(1, rightStats.getRowCount());
double selectivity = innerJoinStats.getRowCount() / crossRowCount;
selectivity = Statistics.getValidSelectivity(selectivity);
Expand Down

0 comments on commit 3799841

Please sign in to comment.