xzj7019 commented on code in PR #29184: URL: https://github.com/apache/doris/pull/29184#discussion_r1437357621
########## fe/fe-core/src/main/java/org/apache/doris/nereids/stats/FilterEstimation.java: ########## @@ -568,10 +570,28 @@ public Statistics visitLike(Like like, EstimationContext context) { "col stats not found. slot=%s in %s", like.left().toSql(), like.toSql()); ColumnStatisticBuilder colBuilder = new ColumnStatisticBuilder(origin); - colBuilder.setNdv(origin.ndv * DEFAULT_LIKE_COMPARISON_SELECTIVITY).setNumNulls(0); + double notNullNdv = getNotNullSelectivity(origin, origin.ndv * DEFAULT_LIKE_COMPARISON_SELECTIVITY); + colBuilder.setNdv(origin.ndv * DEFAULT_LIKE_COMPARISON_SELECTIVITY) + .setCount(notNullNdv * context.statistics.getRowCount()).setNumNulls(0); statsBuilder.putColumnStatistics(like.left(), colBuilder.build()); context.addKeyIfSlot(like.left()); } return statsBuilder.build(); } + + private double getNotNullSelectivity(ColumnStatistic stats, double origSel) { + double rowCount = stats.count; + double numNulls = stats.numNulls; + double ndv = stats.ndv; + if (numNulls > rowCount - ndv) { + numNulls = rowCount - ndv > 0 ? rowCount - ndv : 0; Review Comment: current impl may lead to the inconsistent status between rowCount and ndv, so it will go into this handling logic unexpectly. I will comment it first and refine it in future. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org