Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6524,28 +6524,28 @@ public AlterTableOp visitDropRollupClause(DorisParser.DropRollupClauseContext ct
@Override
public LogicalPlan visitShowVariables(ShowVariablesContext ctx) {
SetType statementScope = visitStatementScope(ctx.statementScope());
if (ctx.wildWhere() != null) {
if (ctx.wildWhere().LIKE() != null) {
return new ShowVariablesCommand(statementScope,
stripQuotes(ctx.wildWhere().STRING_LITERAL().getText()));
LogicalPlan plan;
if (ctx.wildWhere() == null) {
plan = new ShowVariablesCommand(statementScope, null);
} else if (ctx.wildWhere().LIKE() != null) {
plan = new ShowVariablesCommand(statementScope,
stripQuotes(ctx.wildWhere().STRING_LITERAL().getText()));
} else {
StringBuilder sb = new StringBuilder();
sb.append("SELECT `VARIABLE_NAME` AS `Variable_name`, `VARIABLE_VALUE` AS `Value` FROM ");
sb.append("`").append(InternalCatalog.INTERNAL_CATALOG_NAME).append("`");
sb.append(".");
sb.append("`").append(InfoSchemaDb.DATABASE_NAME).append("`");
sb.append(".");
if (statementScope == SetType.GLOBAL) {
sb.append("`global_variables` ");
} else {
StringBuilder sb = new StringBuilder();
sb.append("SELECT `VARIABLE_NAME` AS `Variable_name`, `VARIABLE_VALUE` AS `Value` FROM ");
sb.append("`").append(InternalCatalog.INTERNAL_CATALOG_NAME).append("`");
sb.append(".");
sb.append("`").append(InfoSchemaDb.DATABASE_NAME).append("`");
sb.append(".");
if (statementScope == SetType.GLOBAL) {
sb.append("`global_variables` ");
} else {
sb.append("`session_variables` ");
}
sb.append(getOriginSql(ctx.wildWhere()));
return new NereidsParser().parseSingle(sb.toString());
sb.append("`session_variables` ");
}
} else {
return new ShowVariablesCommand(statementScope, null);
sb.append(getOriginSql(ctx.wildWhere()));
plan = new NereidsParser().parseSingle(sb.toString());
}
return plan;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
import org.apache.doris.qe.NereidsCoordinator;
import org.apache.doris.qe.QeProcessorImpl;
import org.apache.doris.qe.QueryState;
import org.apache.doris.qe.SessionVariable;
import org.apache.doris.qe.StmtExecutor;
import org.apache.doris.qe.VariableMgr;
import org.apache.doris.service.arrowflight.FlightSqlConnectProcessor;
Expand Down Expand Up @@ -992,7 +993,19 @@ public TShowVariableResult showVariables(TShowVariableRequest params) throws TEx
if (ctx == null) {
return result;
}
vars = VariableMgr.dump(SetType.fromThrift(params.getVarType()), ctx.getSessionVariable(), null);
// SHOW VARIABLES can be evaluated through an internal schema query. Planning that
// internal query may call setVarOnce() and temporarily change the live session
// variable (for example disable_join_reorder). Cloning alone is not enough,
// because the clone would keep both the temporary value and its recorded origin.
// Revert only the clone so Changed reflects user-visible session settings,
// while the real session remains untouched.
SessionVariable sessionVariable = VariableMgr.cloneSessionVariable(ctx.getSessionVariable());
try {
VariableMgr.revertSessionValue(sessionVariable);
} catch (DdlException e) {
throw new TException(e);
}
vars = VariableMgr.dump(SetType.fromThrift(params.getVarType()), sessionVariable, null);
result.setVariables(vars);
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ license Apache License, Version 2.0
-- !cmd --
license Apache License, Version 2.0

-- !changed --
enable_profile true

-- !not_changed --

-- !global --
license Apache License, Version 2.0

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ suite("show_variables_command") {
checkNereidsExecute("""show variables like 'li_ense'""")
checkNereidsExecute("""show variables where variable_name like 'li_ense'""")
checkNereidsExecute("""show variables where variable_name = 'license'""")
checkNereidsExecute("""show variables where changed = 1""")
checkNereidsExecute("""show global variables where variable_name = 'license'""")
qt_cmd("""show variables like 'li_ense'""")
qt_cmd("""show variables where variable_name like 'li_ense'""")
qt_cmd("""show variables where variable_name = 'license'""")

sql "set enable_profile = true"
qt_changed("""show variables where changed = 1 and variable_name = 'enable_profile'""")
qt_not_changed("""show variables where changed = 1 and variable_name = 'license'""")
qt_global("""show global variables where variable_name = 'license'""")
sql "UNSET VARIABLE ALL"
}
Loading