-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
executor, session, sessionctx/variable: add validate function for sysval sql_auto_is_null #28247
Conversation
Signed-off-by: unconsolable <chenzhipeng2012@gmail.com>
Signed-off-by: unconsolable <chenzhipeng2012@gmail.com>
Signed-off-by: unconsolable <chenzhipeng2012@gmail.com>
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
Signed-off-by: unconsolable <chenzhipeng2012@gmail.com>
/cc @morgo |
executor/set_test.go
Outdated
@@ -1408,6 +1408,34 @@ func (s *testSuite5) TestSetClusterConfigJSONData(c *C) { | |||
} | |||
} | |||
|
|||
func (s *testSuite5) TestIssue28230(c *C) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know there are other exceptions, but it's recommended to name the issue something descriptive and add a comment for the issue. i.e. TestSQLAutoIsNull()
executor/set_test.go
Outdated
tk := testkit.NewTestKit(c, s.store) | ||
|
||
err := tk.ExecToErr("set sql_auto_is_null = 1;") | ||
c.Assert(terror.ErrorEqual(err, variable.ErrFunctionsNoopImpl), IsTrue, Commentf("err %v", err)) | ||
// change tidb_enable_noop_functions to 1, it will success | ||
tk.MustExec("set tidb_enable_noop_functions = 1;") | ||
tk.MustExec("set sql_auto_is_null = 1;") | ||
tk.MustQuery("select @@tidb_enable_noop_functions;").Check(testkit.Rows("1")) | ||
// restore tidb_enable_noop_functions to 0 failed, as sql_auto_is_null is 1 | ||
err = tk.ExecToErr("set tidb_enable_noop_functions = 0;") | ||
c.Assert(terror.ErrorEqual(err, variable.ErrValueNotSupportedWhen), IsTrue, Commentf("err %v", err)) | ||
// after set sql_auto_is_null to 0, restore success | ||
tk.MustExec("set sql_auto_is_null = 0;") | ||
tk.MustExec("set tidb_enable_noop_functions = 0;") | ||
|
||
// Same to global scope | ||
err = tk.ExecToErr("set @@global.sql_auto_is_null = 1;") | ||
c.Assert(terror.ErrorEqual(err, variable.ErrFunctionsNoopImpl), IsTrue, Commentf("err %v", err)) | ||
tk.MustExec("set @@global.tidb_enable_noop_functions = 1;") | ||
tk.MustExec("set @@global.sql_auto_is_null = 1;") | ||
tk.MustQuery("select @@global.tidb_enable_noop_functions;").Check(testkit.Rows("1")) | ||
err = tk.ExecToErr("set @@global.tidb_enable_noop_functions = 0;") | ||
c.Assert(terror.ErrorEqual(err, variable.ErrValueNotSupportedWhen), IsTrue, Commentf("err %v", err)) | ||
tk.MustExec("set @@global.sql_auto_is_null = 0;") | ||
tk.MustExec("set @@global.tidb_enable_noop_functions = 0;") | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can move this test to sessionctx/variable/sysvar_test.go
and test it through the sysvar API (unit test). That will save you from having to make errValueNotSupportedWhen
public, and increase the unit test coverage of sessionctx/variable
.
sessionctx/variable/varsutil.go
Outdated
// checkSQLAutoIsNull requires TiDBEnableNoopFuncs=1 for the same scope otherwise an error will be returned. | ||
// See also https://github.com/pingcap/tidb/issues/28230 | ||
func checkSQLAutoIsNull(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) { | ||
feature := "sql_auto_is_null" | ||
if TiDBOptOn(normalizedValue) { | ||
if scope == ScopeSession { | ||
if vars.EnableNoopFuncs { | ||
return normalizedValue, nil | ||
} | ||
return Off, ErrFunctionsNoopImpl.GenWithStackByArgs(feature) | ||
} | ||
val, err := vars.GlobalVarsAccessor.GetGlobalSysVar(TiDBEnableNoopFuncs) | ||
if err != nil { | ||
return originalValue, errUnknownSystemVariable.GenWithStackByArgs(TiDBEnableNoopFuncs) | ||
} | ||
if !TiDBOptOn(val) { | ||
return Off, ErrFunctionsNoopImpl.GenWithStackByArgs(feature) | ||
} | ||
} | ||
return normalizedValue, nil | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this func
is only used in one place, you might consider inlining it to sessionctx/variable/noop.go
(up to you: it's also considerably longer than most other validation functions because it has to handle both session/global scope rules.
Signed-off-by: unconsolable <chenzhipeng2012@gmail.com>
Signed-off-by: unconsolable <chenzhipeng2012@gmail.com>
LGTM. I've added the compatibility-breaker tag. It's not a commonly used feature, but we can't cherry pick this, and it needs to be clear in docs. |
/merge |
This pull request has been accepted and is ready to merge. Commit hash: b0e125d
|
@unconsolable: Your PR was out of date, I have automatically updated it for you. At the same time I will also trigger all tests for you: /run-all-tests If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
What problem does this PR solve?
Issue Number: close #28230
What is changed and how it works?
What's Changed:
checkSQLAutoIsNull
set tidb_enable_noop_functions = 0
whilecheckSQLAutoIsNull == 1
executor/set_test.go
Check List
Tests
Side effects
Documentation
Release note