From 17867e446fc4e31c653a42bcccc071558187ef53 Mon Sep 17 00:00:00 2001 From: minghong Date: Thu, 10 Nov 2022 11:25:02 +0800 Subject: [PATCH] [feature](nereids) let user define right deep tree penalty by session variable (#14040) it is hard for us to find a proper factor for all queries. default is 0.7 --- .../doris/nereids/cost/CostCalculator.java | 20 ++++++++++--------- .../org/apache/doris/qe/SessionVariable.java | 12 +++++++++++ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostCalculator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostCalculator.java index c3c78396e9..7f5412470c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostCalculator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostCalculator.java @@ -51,14 +51,7 @@ 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; + /** * The intuition behind `HEAVY_OPERATOR_PUNISH_FACTOR` is we need to avoid this form of join patterns: * Plan1: L join ( AGG1(A) join AGG2(B)) @@ -80,7 +73,16 @@ public class CostCalculator { 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); + /* + * About PENALTY: + * 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. + */ + CostWeight costWeight = new CostWeight(CPU_WEIGHT, MEMORY_WEIGHT, NETWORK_WEIGHT, + ConnectContext.get().getSessionVariable().getNereidsCboPenaltyFactor()); return costWeight.calculate(costEstimate); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java index 205779b77e..4d7c4a8a80 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java +++ b/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_CBO_PENALTY_FACTOR = "nereids_cbo_penalty_factor"; public static final String ENABLE_NEREIDS_TRACE = "enable_nereids_trace"; public static final String ENABLE_NEREIDS_REORDER_TO_ELIMINATE_CROSS_JOIN = "enable_nereids_reorder_to_eliminate_cross_join"; @@ -516,6 +518,8 @@ public class SessionVariable implements Serializable, Writable { @VariableMgr.VarAttr(name = NEREIDS_STAR_SCHEMA_SUPPORT) private boolean nereidsStarSchemaSupport = true; + @VariableMgr.VarAttr(name = NEREIDS_CBO_PENALTY_FACTOR) + private double nereidsCboPenaltyFactor = 0.7; @VariableMgr.VarAttr(name = ENABLE_NEREIDS_TRACE) private boolean enableNereidsTrace = false; @@ -1103,6 +1107,14 @@ public class SessionVariable implements Serializable, Writable { return isEnableNereidsPlanner() && nereidsStarSchemaSupport; } + public double getNereidsCboPenaltyFactor() { + return nereidsCboPenaltyFactor; + } + + public void setNereidsCboPenaltyFactor(double penaltyFactor) { + this.nereidsCboPenaltyFactor = penaltyFactor; + } + public boolean isEnableNereidsTrace() { return isEnableNereidsPlanner() && enableNereidsTrace; }