morrySnow commented on code in PR #14040: URL: https://github.com/apache/doris/pull/14040#discussion_r1016346168
########## fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java: ########## @@ -191,6 +191,8 @@ public class SessionVariable implements Serializable, Writable { public static final String ENABLE_NEREIDS_RUNTIME_FILTER = "enable_nereids_runtime_filter"; public static final String NEREIDS_STAR_SCHEMA_SUPPORT = "nereids_star_schema_support"; + + public static final String NEREIDS_PENALTY_FACTOR = "nereids_penalty_factor"; Review Comment: ```suggestion public static final String NEREIDS_CBO_PENALTY_FACTOR = "nereids_cbo_penalty_factor"; ``` ########## fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostCalculator.java: ########## @@ -51,14 +51,15 @@ public class CostCalculator { static final double CPU_WEIGHT = 1; static final double MEMORY_WEIGHT = 1; static final double NETWORK_WEIGHT = 1.5; - /** - * Except stats information, there are some special criteria in doris. - * For example, in hash join cluster, BE could build hash tables - * in parallel for left deep tree. And hence, we need to punish right deep tree. - * penalyWeight is the factor of punishment. - * The punishment is denoted by stats.penalty. - */ - static final double PENALTY_WEIGHT = 0.5; + + ///** + // * Except stats information, there are some special criteria in doris. + // * For example, in hash join cluster, BE could build hash tables + // * in parallel for left deep tree. And hence, we need to punish right deep tree. + // * penalyWeight is the factor of punishment. + // * The punishment is denoted by stats.penalty. + // */ + //static final double PENALTY_WEIGHT = 0.5; Review Comment: remove these code ########## fe/fe-core/src/main/java/org/apache/doris/nereids/stats/JoinEstimation.java: ########## @@ -147,16 +147,33 @@ private static JoinEstimationResult estimateInnerJoin(PhysicalHashJoin join, Equ return result; } + private static double estimateLeftSemiJoin(double leftCount, double rightCount) { + return leftCount - leftCount / Math.max(2, rightCount); + } + /** * estimate join */ public static StatsDeriveResult estimateV2(StatsDeriveResult leftStats, StatsDeriveResult rightStats, Join join) { JoinType joinType = join.getJoinType(); double rowCount = Double.MAX_VALUE; + //TODO the estimation of semi and anti join is not proper, just for tpch q21 if (joinType == JoinType.LEFT_SEMI_JOIN || joinType == JoinType.LEFT_ANTI_JOIN) { - rowCount = leftStats.getRowCount(); + double rightCount = rightStats.getRowCount(); + double leftCount = leftStats.getRowCount(); + if (join.getHashJoinConjuncts().isEmpty()) { + rowCount = joinType == JoinType.LEFT_SEMI_JOIN ? leftCount : 0; + } else { + rowCount = estimateLeftSemiJoin(leftCount, rightCount); + } } else if (joinType == JoinType.RIGHT_SEMI_JOIN || joinType == JoinType.RIGHT_ANTI_JOIN) { - rowCount = rightStats.getRowCount(); + double rightCount = rightStats.getRowCount(); + double leftCount = leftStats.getRowCount(); + if (join.getHashJoinConjuncts().isEmpty()) { + rowCount = joinType == JoinType.RIGHT_SEMI_JOIN ? rightCount : 0; + } else { + rowCount = estimateLeftSemiJoin(rightCount, leftCount); + } Review Comment: already in another PR ########## fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostCalculator.java: ########## @@ -80,7 +81,9 @@ public static double calculateCost(GroupExpression groupExpression) { CostEstimator costCalculator = new CostEstimator(); CostEstimate costEstimate = groupExpression.getPlan().accept(costCalculator, planContext); groupExpression.setCostEstimate(costEstimate); - CostWeight costWeight = new CostWeight(CPU_WEIGHT, MEMORY_WEIGHT, NETWORK_WEIGHT, PENALTY_WEIGHT); + //CostWeight costWeight = new CostWeight(CPU_WEIGHT, MEMORY_WEIGHT, NETWORK_WEIGHT, PENALTY_WEIGHT); Review Comment: remove this line -- 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