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 f8d8a1fda2..7879f5ed86 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 @@ -56,6 +56,7 @@ import org.apache.doris.analysis.ReplaceTableClause; import org.apache.doris.analysis.SelectStmt; import org.apache.doris.analysis.SetOperationStmt; import org.apache.doris.analysis.SetStmt; +import org.apache.doris.analysis.SetType; import org.apache.doris.analysis.SetVar; import org.apache.doris.analysis.SetVar.SetVarType; import org.apache.doris.analysis.ShowStmt; @@ -954,6 +955,19 @@ public class StmtExecutor { for (SetVar var : setStmt.getSetVars()) { VariableMgr.setVarForNonMasterFE(context.getSessionVariable(), var); } + } else if (parsedStmt instanceof UnsetVariableStmt) { + UnsetVariableStmt unsetStmt = (UnsetVariableStmt) parsedStmt; + if (unsetStmt.isApplyToAll()) { + VariableMgr.setAllVarsToDefaultValue(context.getSessionVariable(), SetType.SESSION); + } else { + String defaultValue = VariableMgr.getDefaultValue(unsetStmt.getVariable()); + if (defaultValue == null) { + ErrorReport.reportDdlException(ErrorCode.ERR_UNKNOWN_SYSTEM_VARIABLE, unsetStmt.getVariable()); + } + SetVar var = new SetVar(SetType.SESSION, unsetStmt.getVariable(), + new StringLiteral(defaultValue), SetVarType.SET_SESSION_VAR); + VariableMgr.setVar(context.getSessionVariable(), var); + } } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/VariableMgr.java b/fe/fe-core/src/main/java/org/apache/doris/qe/VariableMgr.java index 13fe89acbb..93c842f0bf 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/VariableMgr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/VariableMgr.java @@ -715,21 +715,15 @@ public class VariableMgr { throws DdlException { for (Map.Entry entry : ctxByDisplayVarName.entrySet()) { VarContext varCtx = entry.getValue(); - - SetType newSetType = null; - // some variables are GLOBAL only or SESSION only - if ((varCtx.getFlag() & GLOBAL) != 0) { - newSetType = SetType.GLOBAL; - } else if ((varCtx.getFlag() & SESSION_ONLY) != 0) { - newSetType = SetType.SESSION; - } - - SetVar setVar = new SetVar(newSetType != null ? newSetType : setType, entry.getKey(), + SetVar setVar = new SetVar(setType, entry.getKey(), new StringLiteral(varCtx.defaultValue), SetVarType.SET_SESSION_VAR); - //skip read only variables - if ((varCtx.getFlag() & READ_ONLY) == 0) { - setVar(sessionVariable, setVar); + try { + checkUpdate(setVar, varCtx.getFlag()); + } catch (DdlException e) { + LOG.debug("no need to set var for non master fe: {}", setVar.getVariable(), e); + continue; } + setVarInternal(sessionVariable, setVar, varCtx); } }