diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/properties/RequestPropertyDeriver.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/properties/RequestPropertyDeriver.java index acc8ef7886..7d9f8f994e 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/properties/RequestPropertyDeriver.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/properties/RequestPropertyDeriver.java @@ -167,12 +167,8 @@ public class RequestPropertyDeriver extends PlanVisitor { } // for broadcast join - double memLimit = ConnectContext.get().getSessionVariable().getMaxExecMemByte(); - double rowsLimit = ConnectContext.get().getSessionVariable().getBroadcastRowCountLimit(); - double brMemlimit = ConnectContext.get().getSessionVariable().getBroadcastHashtableMemLimitPercentage(); - double datasize = hashJoin.getGroupExpression().get().child(1).getStatistics().computeSize(); - double rowCount = hashJoin.getGroupExpression().get().child(1).getStatistics().getRowCount(); - if (JoinUtils.couldBroadcast(hashJoin) && rowCount <= rowsLimit && datasize <= memLimit * brMemlimit) { + if (JoinUtils.couldBroadcast(hashJoin) + && (JoinUtils.checkBroadcastJoinStats(hashJoin) || requestPropertyToChildren.isEmpty())) { addBroadcastJoinRequestProperty(); } return null; diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/JoinUtils.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/JoinUtils.java index b9e61e256b..d1fb973dd6 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/JoinUtils.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/JoinUtils.java @@ -35,6 +35,7 @@ import org.apache.doris.nereids.trees.plans.Plan; import org.apache.doris.nereids.trees.plans.algebra.Join; import org.apache.doris.nereids.trees.plans.physical.AbstractPhysicalJoin; import org.apache.doris.nereids.trees.plans.physical.PhysicalDistribute; +import org.apache.doris.nereids.trees.plans.physical.PhysicalHashJoin; import org.apache.doris.nereids.trees.plans.physical.PhysicalPlan; import org.apache.doris.qe.ConnectContext; @@ -61,6 +62,18 @@ public class JoinUtils { return !(join.getJoinType().isRightJoin() || join.getJoinType().isFullOuterJoin()); } + /** + * check if the row count of the left child in the broadcast join is less than a threshold value. + */ + public static boolean checkBroadcastJoinStats(PhysicalHashJoin join) { + double memLimit = ConnectContext.get().getSessionVariable().getMaxExecMemByte(); + double rowsLimit = ConnectContext.get().getSessionVariable().getBroadcastRowCountLimit(); + double brMemlimit = ConnectContext.get().getSessionVariable().getBroadcastHashtableMemLimitPercentage(); + double datasize = join.getGroupExpression().get().child(1).getStatistics().computeSize(); + double rowCount = join.getGroupExpression().get().child(1).getStatistics().getRowCount(); + return rowCount <= rowsLimit && datasize <= memLimit * brMemlimit; + } + /** * for a given equation, judge if it can be used as hash join condition */