[chore](config) support select experimental session variable (#31837)

support select experimental variables:

Before change:


Before change:
select @@experimental_enable_nereids_planner;
ERROR 1193 (HY000): errCode = 2, detailMessage = Unknown system variable 'experimental_enable_nereids_planner'

show variables like 'experimental_enable_nereids_planner';
+-------------------------------------+-------+---------------+---------+
| Variable_name                       | Value | Default_Value | Changed |
+-------------------------------------+-------+---------------+---------+
| experimental_enable_nereids_planner | false | true          | 1       |
+-------------------------------------+-------+---------------+---------+

After change:
> select @@experimental_enable_nereids_planner;
+---------------------------------------+
| @@experimental_enable_nereids_planner |
+---------------------------------------+
|                                     1 |
+---------------------------------------+
This commit is contained in:
camby
2024-03-11 15:45:27 +08:00
committed by yiguolei
parent fe3988c686
commit a7a85dd330
2 changed files with 21 additions and 10 deletions

View File

@ -284,7 +284,10 @@ public class VariableMgr {
// setVar: variable information that needs to be set
public static void setVar(SessionVariable sessionVariable, SetVar setVar)
throws DdlException {
VarContext varCtx = setVarPreCheck(setVar);
VarContext varCtx = getVarContext(setVar.getVariable());
if (varCtx == null) {
ErrorReport.reportDdlException(ErrorCode.ERR_UNKNOWN_SYSTEM_VARIABLE, setVar.getVariable());
}
checkUpdate(setVar, varCtx.getFlag());
setVarInternal(sessionVariable, setVar, varCtx);
}
@ -299,7 +302,10 @@ public class VariableMgr {
// So in this case, we should just ignore this exception and return.
public static void setVarForNonMasterFE(SessionVariable sessionVariable, SetVar setVar)
throws DdlException {
VarContext varCtx = setVarPreCheck(setVar);
VarContext varCtx = getVarContext(setVar.getVariable());
if (varCtx == null) {
ErrorReport.reportDdlException(ErrorCode.ERR_UNKNOWN_SYSTEM_VARIABLE, setVar.getVariable());
}
try {
checkUpdate(setVar, varCtx.getFlag());
} catch (DdlException e) {
@ -311,9 +317,9 @@ public class VariableMgr {
setVarInternal(sessionVariable, setVar, varCtx);
}
@NotNull
private static VarContext setVarPreCheck(SetVar setVar) throws DdlException {
String varName = setVar.getVariable();
@Nullable
private static VarContext getVarContext(String name) {
String varName = name;
boolean hasExpPrefix = false;
if (varName.startsWith(VariableAnnotation.EXPERIMENTAL.getPrefix())) {
varName = varName.substring(VariableAnnotation.EXPERIMENTAL.getPrefix().length());
@ -325,13 +331,13 @@ public class VariableMgr {
}
VarContext ctx = ctxByVarName.get(varName);
if (ctx == null) {
ErrorReport.reportDdlException(ErrorCode.ERR_UNKNOWN_SYSTEM_VARIABLE, setVar.getVariable());
return null;
}
// for non-matched prefix, report an error
VariableAnnotation varType = ctx.getField().getAnnotation(VarAttr.class).varType();
if (hasExpPrefix && (!setVar.getVariable().startsWith(varType.getPrefix())
if (hasExpPrefix && (!name.startsWith(varType.getPrefix())
|| varType == VariableAnnotation.NONE)) {
ErrorReport.reportDdlException(ErrorCode.ERR_UNKNOWN_SYSTEM_VARIABLE, setVar.getVariable());
return null;
}
return ctx;
}
@ -533,7 +539,7 @@ public class VariableMgr {
// Get variable value through variable name, used to satisfy statement like `SELECT @@comment_version`
public static void fillValue(SessionVariable var, VariableExpr desc) throws AnalysisException {
VarContext ctx = ctxByVarName.get(desc.getName());
VarContext ctx = getVarContext(desc.getName());
if (ctx == null) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_UNKNOWN_SYSTEM_VARIABLE, desc.getName());
}
@ -621,7 +627,7 @@ public class VariableMgr {
// For Nereids optimizer
public static @Nullable Literal getLiteral(SessionVariable var, String name, SetType setType) {
VarContext ctx = ctxByVarName.get(name);
VarContext ctx = getVarContext(name);
if (ctx == null) {
return null;
}