-
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
sessionctx, executor: Add correctness check when set system variables #7117
Conversation
@spongedu Thanks! Is it the same behaviour with MySQL? |
/run-all-tests |
@shenli Yes,this pr add the same type & value check as MySQL do. |
Please fix ci. |
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.
Great job~
Does all the mysql system vars has been tested in MySQL5.7?
sessionctx/variable/varsutil.go
Outdated
@@ -156,6 +165,181 @@ func ValidateGetSystemVar(name string, isGlobal bool) error { | |||
return nil | |||
} | |||
|
|||
// ValidateSetSystemVar checks if system variable satisfies specific restriction. | |||
func ValidateSetSystemVar(name string, value string) (string, error, error) { |
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.
We may not need to return warn?
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.
yes, If we take the SessionVars
as a parameter into function ValidateSetSystemVar
, we can directly append warning in this function. I'll fix this
sessionctx/variable/varsutil.go
Outdated
if val := GetSysVar(name); val != nil { | ||
return val.Value, nil, nil | ||
} | ||
return value, nil, 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.
Any case cover this line?
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.
In set_test.go
, line 93 - line 97 covers this:
tk.MustQuery(`select @@global.low_priority_updates;`).Check(testkit.Rows("0"))
tk.MustExec(`set @@global.low_priority_updates="ON";`)
tk.MustQuery(`select @@global.low_priority_updates;`).Check(testkit.Rows("1"))
tk.MustExec(`set @@global.low_priority_updates=DEFAULT;`) // It will be set to compiled-in default value.
tk.MustQuery(`select @@global.low_priority_updates;`).Check(testkit.Rows("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.
Yeah, this case covers line 172, but seems there is no case that covers line 174?
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.
It seems so. I'll add some related tests..
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.
@XuHuaiyu the condition that we fail to GetSysVar
should never happen. We'd better panic here ?
@XuHuaiyu Yes, these checks are according to https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html# |
sessionctx/variable/varsutil.go
Outdated
return val.Value, nil | ||
} | ||
// should never happen | ||
panic(fmt.Sprintf("Error happened when ValidateSetSystemVar. Invalid system variable: %s", name)) |
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.
Will it be more friendly if we return UnknownSystemVar.GenByArgs(name) here
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.
ok
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.
Addressing the comment will make a LGTM ^_^
@@ -156,6 +162,197 @@ func ValidateGetSystemVar(name string, isGlobal bool) error { | |||
return nil | |||
} | |||
|
|||
// ValidateSetSystemVar checks if system variable satisfies specific restriction. | |||
func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string, error) { | |||
if strings.EqualFold(value, "DEFAULT") { |
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.
Maybe we need to consider System
? Currently, set time_zone='System'
does not work.
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.
@zhexuany it's not a common check, I think we'd better by refine parseTimeZone
in varsutil.go
to :
func parseTimeZone(s string) (*time.Location, error) {
if strings.EqualFold(s, "SYSTEM") {
.......
}
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.
It seems that we should validate the result format in ValidateSetSystemVar
. Only modify parseTimeZone
is not enough. I'll fix here.
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.
tidb> set time_zone='System'; Query OK, 0 rows affected (0.00 sec)
tidb> select @@time_zone;
+-------------+
| @@time_zone |
+-------------+
| System |
+-------------+
1 row in set (0.00 sec)
In MySQL:
mysql> set time_zone='System'; Query OK, 0 rows affected (0.00 sec)
mysql> select @@time_zone;
+-------------+
| @@time_zone |
+-------------+
| SYSTEM |
+-------------+
1 row in set (0.01 sec)
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.
@zhexuany Done here. PTAL
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.
LGTM
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.
LGTM
What have you changed? (mandatory)
Add correctness check when set system variables
What is the type of the changes? (mandatory)
How has this PR been tested? (mandatory)
Unittest