xzj7019 commented on code in PR #27259: URL: https://github.com/apache/doris/pull/27259#discussion_r1398635327
########## fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostModelV1.java: ########## @@ -299,12 +303,41 @@ public Cost visitPhysicalHashJoin( 0 ); } - return CostV1.of(context.getSessionVariable(), leftRowCount + rightRowCount + outputRowCount, + return CostV1.of(context.getSessionVariable(), + (leftRowCount + rightRowCount + outputRowCount) + * skewPenalty(physicalHashJoin, probeStats, buildStats, totalInstanceNumber), rightRowCount, 0 ); } + private double skewPenalty(PhysicalHashJoin<? extends Plan, ? extends Plan> physicalHashJoin, + Statistics probeStats, + Statistics buildStats, + int totalInstanceNumber) { + double penalty = 1.0; + for (Expression conj : physicalHashJoin.getHashJoinConjuncts()) { + EqualTo eq = (EqualTo) JoinUtils.swapEqualToForChildrenOrder( + (EqualTo) conj, physicalHashJoin.left().getOutputSet()); + ColumnStatistic leftColStats = probeStats.findColumnStatistics(eq.left()); + if (leftColStats != null && !leftColStats.isUnKnown()) { + if (leftColStats.ndv < beNumber) { + penalty = totalInstanceNumber / Math.max(1.0, leftColStats.ndv); Review Comment: consider the most commonly used case, 3 be and leftColStats is 2 (meet < beNumber), the totalInstanceNumber is 24, then the penalty will be 12 on the original total cost for shuffle join, which seems too big changes... -- 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