From 223d7a36ebdad1436e11a43fc2d3d9fac2feca64 Mon Sep 17 00:00:00 2001 From: minghong Date: Mon, 20 Mar 2023 13:04:29 +0800 Subject: [PATCH] adjust distribution stats derive, fix bug in join estimation (#17916) --- .../doris/nereids/cost/CostModelV1.java | 23 +++++++++---------- .../org/apache/doris/nereids/cost/CostV1.java | 5 ++-- .../doris/nereids/stats/JoinEstimation.java | 4 ++-- 3 files changed, 16 insertions(+), 16 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 e415543bfa..e36a1b2aa6 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 @@ -60,8 +60,12 @@ class CostModelV1 extends PlanVisitor { public static Cost addChildCost(Plan plan, Cost planCost, Cost childCost, int index) { Preconditions.checkArgument(childCost instanceof CostV1 && planCost instanceof CostV1); - double cost = planCost.getValue() + childCost.getValue(); - return new CostV1(cost); + CostV1 childCostV1 = (CostV1) childCost; + CostV1 planCostV1 = (CostV1) planCost; + return new CostV1(childCostV1.getCpuCost() + planCostV1.getCpuCost(), + childCostV1.getMemoryCost() + planCostV1.getMemoryCost(), + childCostV1.getNetworkCost() + planCostV1.getNetworkCost(), + childCostV1.getPenalty() + planCostV1.getPenalty()); } @Override @@ -170,22 +174,17 @@ class CostModelV1 extends PlanVisitor { || childStatistics.getRowCount() > rowsLimit) { return CostV1.of(Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE); } - /* - TODO: - srcBeNum and destBeNum are not available, assume destBeNum/srcBeNum = 1 - 1. cpu: row * destBeNum/srcBeNum - 2. network: rows send = rows/srcBeNum * destBeNum. - */ return CostV1.of( - childStatistics.getRowCount(), // TODO:should multiply by destBeNum/srcBeNum - childStatistics.getRowCount(), // only consider one BE, not the whole system. - childStatistics.getRowCount() * instanceNumber); // TODO: remove instanceNumber when BE updated + 0, + 0, + childStatistics.getRowCount()); + } // gather if (spec instanceof DistributionSpecGather) { return CostV1.of( - childStatistics.getRowCount(), + 0, 0, childStatistics.getRowCount()); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostV1.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostV1.java index 0b425d91c8..2747346390 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostV1.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostV1.java @@ -105,8 +105,9 @@ class CostV1 implements Cost { @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append((long) cpuCost).append("/").append((long) memoryCost).append("/").append((long) networkCost) - .append("/").append((long) penalty); + sb.append(cost).append("[").append((long) cpuCost).append("/") + .append((long) memoryCost).append("/").append((long) networkCost) + .append("/").append((long) penalty).append("]"); return sb.toString(); } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/JoinEstimation.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/JoinEstimation.java index e77c060bba..0e8516e00c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/JoinEstimation.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/JoinEstimation.java @@ -39,9 +39,9 @@ public class JoinEstimation { .sorted((a, b) -> { double sub = a.second - b.second; if (sub > 0) { - return -1; - } else if (sub < 0) { return 1; + } else if (sub < 0) { + return -1; } else { return 0; }