From f1cd9a78da3fea2b63a3dd5c54b3927d447039af Mon Sep 17 00:00:00 2001 From: minghong Date: Mon, 4 Nov 2024 15:23:15 +0800 Subject: [PATCH] set session var once --- .../apache/doris/nereids/NereidsPlanner.java | 13 ++++---- .../analysis/EliminateLogicalSelectHint.java | 10 +++--- .../doris/nereids/stats/StatsCalculator.java | 8 ++++- .../plans/commands/CreateTableCommand.java | 3 +- .../plans/commands/info/CreateMTMVInfo.java | 2 +- .../org/apache/doris/qe/SessionVariable.java | 32 +++++++------------ .../org/apache/doris/qe/StmtExecutor.java | 2 +- 7 files changed, 34 insertions(+), 36 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/NereidsPlanner.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/NereidsPlanner.java index 6cb3414820b473a..3d058db4c659b06 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/NereidsPlanner.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/NereidsPlanner.java @@ -248,21 +248,22 @@ private void setRuntimeFilterWaitTimeByTableRowCountAndType() { .collectToList(LogicalCatalogRelation.class::isInstance); double maxRow = StatsCalculator.getMaxTableRowCount(scans, cascadesContext); boolean hasExternalTable = scans.stream().anyMatch(scan -> !(scan instanceof LogicalOlapScan)); + SessionVariable sessionVariable = ConnectContext.get().getSessionVariable(); if (hasExternalTable) { if (maxRow < 1_000_000_000L) { - ConnectContext.get().getSessionVariable().runtimeFilterWaitTimeMs = 5000; + sessionVariable.setVarOnce(SessionVariable.RUNTIME_FILTER_WAIT_TIME_MS, "5000"); } else if (maxRow < 10_000_000_000L) { - ConnectContext.get().getSessionVariable().runtimeFilterWaitTimeMs = 20000; + sessionVariable.setVarOnce(SessionVariable.RUNTIME_FILTER_WAIT_TIME_MS, "20000"); } else { - ConnectContext.get().getSessionVariable().runtimeFilterWaitTimeMs = 50000; + sessionVariable.setVarOnce(SessionVariable.RUNTIME_FILTER_WAIT_TIME_MS, "50000"); } } else { if (maxRow < 1_000_000_000L) { - ConnectContext.get().getSessionVariable().runtimeFilterWaitTimeMs = 1000; + sessionVariable.setVarOnce(SessionVariable.RUNTIME_FILTER_WAIT_TIME_MS, "1000"); } else if (maxRow < 10_000_000_000L) { - ConnectContext.get().getSessionVariable().runtimeFilterWaitTimeMs = 5000; + sessionVariable.setVarOnce(SessionVariable.RUNTIME_FILTER_WAIT_TIME_MS, "5000"); } else { - ConnectContext.get().getSessionVariable().runtimeFilterWaitTimeMs = 20000; + sessionVariable.setVarOnce(SessionVariable.RUNTIME_FILTER_WAIT_TIME_MS, "20000"); } } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/EliminateLogicalSelectHint.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/EliminateLogicalSelectHint.java index 781e418c2256e6d..61f0bb5fb691869 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/EliminateLogicalSelectHint.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/EliminateLogicalSelectHint.java @@ -17,7 +17,6 @@ package org.apache.doris.nereids.rules.analysis; -import org.apache.doris.common.DdlException; import org.apache.doris.nereids.CascadesContext; import org.apache.doris.nereids.StatementContext; import org.apache.doris.nereids.hint.Hint; @@ -36,6 +35,7 @@ import org.apache.doris.nereids.trees.plans.Plan; import org.apache.doris.nereids.trees.plans.logical.LogicalSelectHint; import org.apache.doris.qe.ConnectContext; +import org.apache.doris.qe.SessionVariable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,11 +55,9 @@ public Rule build() { if (hintName.equalsIgnoreCase("SET_VAR")) { ((SelectHintSetVar) hint).setVarOnceInSql(ctx.statementContext); } else if (hintName.equalsIgnoreCase("ORDERED")) { - try { - ctx.cascadesContext.getConnectContext().getSessionVariable() - .disableNereidsJoinReorderOnce(); - } catch (DdlException e) { - throw new RuntimeException(e); + if (!ctx.cascadesContext.getConnectContext().getSessionVariable() + .setVarOnce(SessionVariable.DISABLE_JOIN_REORDER, "true")) { + throw new RuntimeException("set DISABLE_JOIN_REORDER=true once failed"); } OrderedHint ordered = new OrderedHint("Ordered"); ordered.setStatus(Hint.HintStatus.SUCCESS); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java index b3702488b1e79fc..c57d0882d47c72b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java @@ -138,6 +138,7 @@ import org.apache.doris.nereids.types.DataType; import org.apache.doris.nereids.util.PlanUtils; import org.apache.doris.qe.ConnectContext; +import org.apache.doris.qe.SessionVariable; import org.apache.doris.statistics.AnalysisManager; import org.apache.doris.statistics.ColumnStatistic; import org.apache.doris.statistics.ColumnStatisticBuilder; @@ -248,6 +249,11 @@ public static double getMaxTableRowCount(List scans, Cas */ public static Optional disableJoinReorderIfStatsInvalid(List scans, CascadesContext context) { + try { + ConnectContext.get().getSessionVariable().setVarOnce(SessionVariable.DISABLE_JOIN_REORDER, "true"); + } catch (Exception e) { + LOG.info("disableNereidsJoinReorderOnce failed"); + } StatsCalculator calculator = new StatsCalculator(context); if (ConnectContext.get() == null) { // ut case @@ -265,7 +271,7 @@ public static Optional disableJoinReorderIfStatsInvalid(List reason = calculator.checkNdvValidation(scan, rowCount); if (reason.isPresent()) { try { - ConnectContext.get().getSessionVariable().disableNereidsJoinReorderOnce(); + ConnectContext.get().getSessionVariable().setVarOnce(SessionVariable.DISABLE_JOIN_REORDER, "true"); LOG.info("disable join reorder since col stats invalid: " + reason.get()); } catch (Exception e) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateTableCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateTableCommand.java index 92463c9f9d9dd98..281eb73513e21cd 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateTableCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateTableCommand.java @@ -54,6 +54,7 @@ import org.apache.doris.nereids.util.TypeCoercionUtils; import org.apache.doris.qe.ConnectContext; import org.apache.doris.qe.QueryState.MysqlStateType; +import org.apache.doris.qe.SessionVariable; import org.apache.doris.qe.StmtExecutor; import com.google.common.collect.ImmutableList; @@ -98,7 +99,7 @@ public void run(ConnectContext ctx, StmtExecutor executor) throws Exception { List ctasCols = createTableInfo.getCtasColumns(); NereidsPlanner planner = new NereidsPlanner(ctx.getStatementContext()); // must disable constant folding by be, because be constant folding may return wrong type - ctx.getSessionVariable().disableConstantFoldingByBEOnce(); + ctx.getSessionVariable().setVarOnce(SessionVariable.ENABLE_FOLD_CONSTANT_BY_BE, "false"); Plan plan = planner.planWithLock(new UnboundResultSink<>(query), PhysicalProperties.ANY, ExplainLevel.NONE); if (ctasCols == null) { // we should analyze the plan firstly to get the columns' name. diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateMTMVInfo.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateMTMVInfo.java index b553dccdd8d97e9..de5e188d5a65bf7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateMTMVInfo.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateMTMVInfo.java @@ -253,7 +253,7 @@ public void analyzeQuery(ConnectContext ctx, Map mvProperties) t // this is for expression column name infer when not use alias LogicalSink logicalSink = new UnboundResultSink<>(logicalQuery); // must disable constant folding by be, because be constant folding may return wrong type - ctx.getSessionVariable().disableConstantFoldingByBEOnce(); + ctx.getSessionVariable().setVarOnce(SessionVariable.ENABLE_FOLD_CONSTANT_BY_BE, "false"); Plan plan = planner.planWithLock(logicalSink, PhysicalProperties.ANY, ExplainLevel.ALL_PLAN); // can not contain VIEW or MTMV analyzeBaseTables(planner.getAnalyzedPlan()); 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 af217c2ae09aa33..312bdf781dddf47 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 @@ -4097,27 +4097,19 @@ public void setEnableStrictConsistencyDml(boolean value) { this.enableStrictConsistencyDml = value; } - public void disableStrictConsistencyDmlOnce() throws DdlException { - if (!enableStrictConsistencyDml) { - return; - } - setIsSingleSetVar(true); - VariableMgr.setVar(this, - new SetVar(SessionVariable.ENABLE_STRICT_CONSISTENCY_DML, new StringLiteral("false"))); - } - - public void disableConstantFoldingByBEOnce() throws DdlException { - if (!enableFoldConstantByBe) { - return; + /** + * + * @return true iff set success + */ + public boolean setVarOnce(String varName, String value) { + try { + setIsSingleSetVar(true); + VariableMgr.setVar(this, new SetVar(varName, new StringLiteral(value))); + return true; + } catch (DdlException e) { + LOG.warn("set onece {} = {} failed", varName, value); + return false; } - setIsSingleSetVar(true); - VariableMgr.setVar(this, - new SetVar(SessionVariable.ENABLE_FOLD_CONSTANT_BY_BE, new StringLiteral("false"))); - } - - public void disableNereidsJoinReorderOnce() throws DdlException { - setIsSingleSetVar(true); - VariableMgr.setVar(this, new SetVar(SessionVariable.DISABLE_JOIN_REORDER, new StringLiteral("true"))); } // return number of variables by given variable annotation diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java index 1726e85fb73d997..397aa7220bbc870 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java @@ -3551,7 +3551,7 @@ public HttpStreamParams generateHttpStreamPlan(TUniqueId queryId) throws Excepti try { try { // disable shuffle for http stream (only 1 sink) - sessionVariable.disableStrictConsistencyDmlOnce(); + sessionVariable.setVarOnce(SessionVariable.ENABLE_STRICT_CONSISTENCY_DML, "false"); httpStreamParams = generateHttpStreamNereidsPlan(queryId); } catch (NereidsException | ParseException e) { if (context.getMinidump() != null && context.getMinidump().toString(4) != null) {