This is an automated email from the ASF dual-hosted git repository.
starocean999 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new d1060850bed [fix](show variables) Fix changed variable output in show
variables (#63734)
d1060850bed is described below
commit d1060850bed233b273c638a1d688e340c57b8c03
Author: yujun <[email protected]>
AuthorDate: Thu May 28 14:12:44 2026 +0800
[fix](show variables) Fix changed variable output in show variables (#63734)
Problem Summary: SHOW VARIABLES WHERE is evaluated through an internal
schema query. During planning of that internal query, FE may call
setVarOnce() and temporarily change session variables such as
disable_join_reorder. The schema scan then dumps those temporary values
and reports them as Changed, even though they are not user-visible
session changes. This patch dumps variables from a reverted clone so
one-shot internal values do not affect SHOW VARIABLES output, while
preserving the existing information_schema WHERE execution behavior.
---
.../doris/nereids/parser/LogicalPlanBuilder.java | 38 +++++++++++-----------
.../apache/doris/service/FrontendServiceImpl.java | 15 ++++++++-
.../ddl/show_variables/show_variables_command.out | 8 +++++
.../show_variables/show_variables_command.groovy | 8 +++++
4 files changed, 49 insertions(+), 20 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
index fbeb376e4da..0bb14eff373 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
@@ -6515,28 +6515,28 @@ public class LogicalPlanBuilder extends
DorisParserBaseVisitor<Object> {
@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
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java
b/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java
index 308b1e1e51e..411b7d4c20b 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java
@@ -120,6 +120,7 @@ import org.apache.doris.qe.MysqlConnectProcessor;
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;
@@ -1007,7 +1008,19 @@ public class FrontendServiceImpl implements
FrontendService.Iface {
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;
}
diff --git
a/regression-test/data/query_p0/ddl/show_variables/show_variables_command.out
b/regression-test/data/query_p0/ddl/show_variables/show_variables_command.out
index dc009a38e77..ef1e17cb312 100644
---
a/regression-test/data/query_p0/ddl/show_variables/show_variables_command.out
+++
b/regression-test/data/query_p0/ddl/show_variables/show_variables_command.out
@@ -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
+
diff --git
a/regression-test/suites/query_p0/ddl/show_variables/show_variables_command.groovy
b/regression-test/suites/query_p0/ddl/show_variables/show_variables_command.groovy
index 77caf22cacd..8b517b6708f 100644
---
a/regression-test/suites/query_p0/ddl/show_variables/show_variables_command.groovy
+++
b/regression-test/suites/query_p0/ddl/show_variables/show_variables_command.groovy
@@ -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"
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]