englefly commented on code in PR #18272: URL: https://github.com/apache/doris/pull/18272#discussion_r1159198394
########## fe/fe-core/src/main/java/org/apache/doris/nereids/stats/JoinEstimation.java: ########## @@ -37,30 +40,75 @@ */ public class JoinEstimation { + private static EqualTo normalizeHashJoinCondition(EqualTo equalTo, Statistics leftStats, Statistics rightStats) { + boolean changeOrder = equalTo.left().getInputSlots().stream().anyMatch( + slot -> rightStats.findColumnStatistics(slot) != null + ); + if (changeOrder) { + return new EqualTo(equalTo.right(), equalTo.left()); + } else { + return equalTo; + } + } + private static Statistics estimateInnerJoin(Statistics leftStats, Statistics rightStats, Join join) { + List<Double> unTrustEqualRatio = Lists.newArrayList(); + boolean leftBigger = leftStats.getRowCount() > rightStats.getRowCount(); + List<EqualTo> trustableConditions = join.getHashJoinConjuncts().stream() + .map(expression -> (EqualTo) expression) + .filter( + expression -> { + EqualTo equal = normalizeHashJoinCondition(expression, leftStats, rightStats); + ColumnStatistic eqLeftColStats = ExpressionEstimation.estimate(equal.left(), leftStats); + ColumnStatistic eqRightColStats = ExpressionEstimation.estimate(equal.right(), rightStats); + boolean trustable = eqRightColStats.ndv / rightStats.getRowCount() > 0.9 + || eqLeftColStats.ndv / leftStats.getRowCount() > 0.9; Review Comment: done -- 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