Skip to content

Commit

Permalink
set session var once
Browse files Browse the repository at this point in the history
  • Loading branch information
englefly committed Nov 4, 2024
1 parent efe8936 commit f1cd9a7
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -248,6 +249,11 @@ public static double getMaxTableRowCount(List<LogicalCatalogRelation> scans, Cas
*/
public static Optional<String> disableJoinReorderIfStatsInvalid(List<LogicalOlapScan> 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
Expand All @@ -265,7 +271,7 @@ public static Optional<String> disableJoinReorderIfStatsInvalid(List<LogicalOlap
Optional<String> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -98,7 +99,7 @@ public void run(ConnectContext ctx, StmtExecutor executor) throws Exception {
List<String> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public void analyzeQuery(ConnectContext ctx, Map<String, String> mvProperties) t
// this is for expression column name infer when not use alias
LogicalSink<Plan> 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());
Expand Down
32 changes: 12 additions & 20 deletions fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit f1cd9a7

Please sign in to comment.