This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.0 by this push:
new 7bfb436dbce branch-4.0: [Enhancement](variable) Adding a whitelist
allows you to ignore certain unsupported variables #58998 (#59136)
7bfb436dbce is described below
commit 7bfb436dbce2d39f8ffb7d3e409068e9d47f334e
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Fri Dec 19 14:16:28 2025 +0800
branch-4.0: [Enhancement](variable) Adding a whitelist allows you to ignore
certain unsupported variables #58998 (#59136)
Cherry-picked from #58998
Co-authored-by: lw112 <[email protected]>
---
.../main/java/org/apache/doris/common/Config.java | 10 ++
.../main/java/org/apache/doris/qe/VariableMgr.java | 31 ++++++
.../set/test_mysql_compat_var_whitelist.groovy | 114 +++++++++++++++++++++
3 files changed, 155 insertions(+)
diff --git a/fe/fe-common/src/main/java/org/apache/doris/common/Config.java
b/fe/fe-common/src/main/java/org/apache/doris/common/Config.java
index 9f7a09d680c..0ca1f271a7a 100644
--- a/fe/fe-common/src/main/java/org/apache/doris/common/Config.java
+++ b/fe/fe-common/src/main/java/org/apache/doris/common/Config.java
@@ -178,6 +178,16 @@ public class Config extends ConfigBase {
"MySQL Jdbc Catalog mysql does not support pushdown functions"})
public static String[] jdbc_mysql_unsupported_pushdown_functions =
{"date_trunc", "money_format", "negative"};
+ @ConfField(mutable = true, description = {
+ "MySQL 兼容性变量白名单。这些变量在 SET 语句中会被静默忽略,而不是抛出错误。"
+ + "主要用于兼容 MySQL 客户端工具(如 phpMyAdmin, mysqldump)。"
+ + "Doris 不需要理解这些变量的具体含义,只需要接受它们而不报错。",
+ "MySQL compatibility variable whitelist. These variables will be
silently ignored in SET statements "
+ + "instead of throwing an error. This is mainly used for
compatibility with MySQL client tools "
+ + "(such as phpMyAdmin, mysqldump). Doris does not need to
understand the specific meaning of "
+ + "these variables, it just needs to accept them without
error."})
+ public static String[] mysql_compat_var_whitelist = {};
+
@ConfField(mutable = true, masterOnly = true, description = {"强制 SQLServer
Jdbc Catalog 加密为 false",
"Force SQLServer Jdbc Catalog encrypt to false"})
public static boolean force_sqlserver_jdbc_encrypt_false = false;
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 9aa360fd07d..8aaa7d452ad 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
@@ -26,6 +26,7 @@ import org.apache.doris.analysis.VariableExpr;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.Config;
import org.apache.doris.common.DdlException;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
@@ -297,6 +298,12 @@ public class VariableMgr {
throws DdlException {
VarContext varCtx = getVarContext(setVar.getVariable());
if (varCtx == null) {
+ // Check if the variable is in the MySQL compatibility whitelist
+ if (isInMySQLCompatWhitelist(setVar.getVariable())) {
+ // Silently ignore whitelisted variables for MySQL
compatibility
+ LOG.debug("Ignoring whitelisted MySQL compatibility variable:
{}", setVar.getVariable());
+ return;
+ }
ErrorReport.reportDdlException(ErrorCode.ERR_UNKNOWN_SYSTEM_VARIABLE,
setVar.getVariable(),
findSimilarSessionVarNames(setVar.getVariable()));
}
@@ -304,6 +311,24 @@ public class VariableMgr {
setVarInternal(sessionVariable, setVar, varCtx);
}
+ /**
+ * Check if a variable name is in the MySQL compatibility whitelist.
+ * This allows MySQL client tools (like phpMyAdmin, mysqldump) to set
certain
+ * variables that Doris doesn't support without causing errors.
+ */
+ private static boolean isInMySQLCompatWhitelist(String varName) {
+ if (varName == null || Config.mysql_compat_var_whitelist == null) {
+ return false;
+ }
+ String normalizedVarName = varName.toLowerCase();
+ for (String whitelistedVar : Config.mysql_compat_var_whitelist) {
+ if (whitelistedVar != null &&
whitelistedVar.toLowerCase().equals(normalizedVarName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
public static String findSimilarSessionVarNames(String inputName) {
JaroWinklerDistance jaroWinklerDistance = new JaroWinklerDistance();
StringJoiner joiner = new StringJoiner(", ", "{", "}");
@@ -318,6 +343,12 @@ public class VariableMgr {
throws DdlException {
VarContext varCtx = getVarContext(setVar.getVariable());
if (varCtx == null) {
+ // Check if the variable is in the MySQL compatibility whitelist
+ if (isInMySQLCompatWhitelist(setVar.getVariable())) {
+ // Silently ignore whitelisted variables for MySQL
compatibility
+ LOG.debug("Ignoring whitelisted MySQL compatibility variable:
{}", setVar.getVariable());
+ return;
+ }
ErrorReport.reportDdlException(ErrorCode.ERR_UNKNOWN_SYSTEM_VARIABLE,
setVar.getVariable());
}
setVarInternal(sessionVariable, setVar, varCtx);
diff --git
a/regression-test/suites/query_p0/set/test_mysql_compat_var_whitelist.groovy
b/regression-test/suites/query_p0/set/test_mysql_compat_var_whitelist.groovy
new file mode 100644
index 00000000000..5db935eea90
--- /dev/null
+++ b/regression-test/suites/query_p0/set/test_mysql_compat_var_whitelist.groovy
@@ -0,0 +1,114 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_mysql_compat_var_whitelist", "nonConcurrent") {
+
+ // Test 1: Verify unknown variables throw errors when whitelist is empty
(default)
+ test {
+ sql "set unknown_variable_12345 = 1"
+ exception "Unknown system variable"
+ }
+
+ test {
+ sql "set @@nonexistent_var = 0"
+ exception "Unknown system variable"
+ }
+
+ test {
+ sql "set foreign_key_checks = 0"
+ exception "Unknown system variable"
+ }
+
+ // Test 2: Configure whitelist using ADMIN SET FRONTEND CONFIG
+ sql """ADMIN SET FRONTEND CONFIG ("mysql_compat_var_whitelist" =
"foreign_key_checks,unique_checks,sql_notes")"""
+
+ // Test 3: Basic SET syntax - whitelisted variables should not throw errors
+ sql "set foreign_key_checks = 0"
+ sql "set foreign_key_checks = 1"
+ sql "set unique_checks = 0"
+ sql "set unique_checks = 1"
+ sql "set sql_notes = 0"
+ sql "set sql_notes = 1"
+
+ // Test 4: @@ syntax
+ sql "set @@foreign_key_checks = 0"
+ sql "set @@unique_checks = 1"
+ sql "set @@sql_notes = 0"
+
+ // Test 5: session syntax
+ sql "set session foreign_key_checks = 0"
+ sql "set @@session.unique_checks = 1"
+ sql "set @@session.sql_notes = 0"
+
+ // Test 6: Case insensitivity
+ sql "set FOREIGN_KEY_CHECKS = 0"
+ sql "set Foreign_Key_Checks = 1"
+ sql "set UNIQUE_CHECKS = 0"
+ sql "set Unique_Checks = 1"
+
+ // Test 7: Combined SET statements (common in mysqldump)
+ sql "set foreign_key_checks = 0, unique_checks = 0"
+ sql "set @@session.foreign_key_checks = 1, @@session.unique_checks = 1"
+ sql "set foreign_key_checks = 0, unique_checks = 0, sql_notes = 0"
+
+ // Test 8: MySQL dump style with version comments
+ sql "/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS,
FOREIGN_KEY_CHECKS=0 */"
+ sql "/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */"
+ sql "/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */"
+ sql "/*!40014 SET FOREIGN_KEY_CHECKS=1 */"
+ sql "/*!40014 SET UNIQUE_CHECKS=1 */"
+ sql "/*!40111 SET SQL_NOTES=1 */"
+
+ // Test 9: Various boolean value formats
+ sql "set foreign_key_checks = ON"
+ sql "set foreign_key_checks = OFF"
+ sql "set foreign_key_checks = TRUE"
+ sql "set foreign_key_checks = FALSE"
+ sql "set unique_checks = ON"
+ sql "set unique_checks = OFF"
+
+ // Test 10: Verify non-whitelisted variables still throw errors
+ test {
+ sql "set still_unknown_variable = 1"
+ exception "Unknown system variable"
+ }
+
+ test {
+ sql "set another_nonexistent_var = true"
+ exception "Unknown system variable"
+ }
+
+ // Test 11: Verify normal Doris variables still work
+ def originalTimeout = sql "show variables where variable_name =
'query_timeout'"
+ sql "set query_timeout = 999"
+ def modifiedTimeout = sql "show variables where variable_name =
'query_timeout'"
+ assertTrue(modifiedTimeout[0][1] == "999")
+ sql "set query_timeout = ${originalTimeout[0][1]}"
+
+ // Test 12: Clear whitelist and verify variables throw errors again
+ sql """ADMIN SET FRONTEND CONFIG ("mysql_compat_var_whitelist" = "")"""
+
+ test {
+ sql "set foreign_key_checks = 0"
+ exception "Unknown system variable"
+ }
+
+ test {
+ sql "set unique_checks = 0"
+ exception "Unknown system variable"
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]