From 766e5fa92060fae8f95f2f855829da7cdc8da049 Mon Sep 17 00:00:00 2001 From: minghong Date: Mon, 29 Jul 2024 09:57:42 +0800 Subject: [PATCH] ds72-connectivity --- .../java/org/apache/doris/nereids/cost/CostModelV1.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostModelV1.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostModelV1.java index 4ef381387555cd3..edf20e382447c40 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostModelV1.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostModelV1.java @@ -349,13 +349,14 @@ public Cost visitPhysicalHashJoin( double leftRowCount = probeStats.getRowCount(); double rightRowCount = buildStats.getRowCount(); + int leftConnectivity = computeConnectivity(physicalHashJoin.left(), context); + int rightConnectivity = computeConnectivity(physicalHashJoin.right(), context); + if ((long) leftRowCount == (long) rightRowCount) { // reorder by connectivity to be friendly to runtime filter. if (physicalHashJoin.getGroupExpression().isPresent() && physicalHashJoin.getGroupExpression().get().getOwnerGroup() != null && !physicalHashJoin.getGroupExpression().get().getOwnerGroup().isStatsReliable()) { - int leftConnectivity = computeConnectivity(physicalHashJoin.left(), context); - int rightConnectivity = computeConnectivity(physicalHashJoin.right(), context); if (rightConnectivity < leftConnectivity) { leftRowCount += 1; } @@ -371,6 +372,10 @@ public Cost visitPhysicalHashJoin( leftRowCount += 1e-3; } } + if (!physicalHashJoin.getGroupExpression().get().getOwnerGroup().isStatsReliable()) { + // if a table with higher connectivity, move it to top-join. it is good for runtime filter. + leftRowCount -= rightConnectivity * probeStats.getWidthInJoinCluster(); + } /* pattern1: L join1 (Agg1() join2 Agg2())