Skip to content
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

session, sessionctx/variable: ensure sysvars are always in lower case #35659

Merged
merged 5 commits into from
Jul 6, 2022
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
2 changes: 1 addition & 1 deletion session/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2055,7 +2055,7 @@ func doDMLWorks(s Session) {
case variable.TiDBEnablePaging:
vVal = variable.BoolToOnOff(variable.DefTiDBEnablePaging)
}
value := fmt.Sprintf(`("%s", "%s")`, strings.ToLower(k), vVal)
value := fmt.Sprintf(`("%s", "%s")`, k, vVal)
values = append(values, value)
}
sql := fmt.Sprintf("INSERT HIGH_PRIORITY INTO %s.%s VALUES %s;", mysql.SystemDB, mysql.GlobalVariablesTable,
Expand Down
8 changes: 8 additions & 0 deletions sessionctx/variable/sysvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,14 @@ func TestDefaultValuesAreSettable(t *testing.T) {
}
}

// TestSysVarNameIsLowerCase tests that no new sysvars are added with uppercase characters.
// In MySQL variables are always lowercase, and can be set in a case-insensitive way.
func TestSysVarNameIsLowerCase(t *testing.T) {
for _, sv := range GetSysVars() {
require.Equal(t, strings.ToLower(sv.Name), sv.Name, "sysvar name contains uppercase characters")
}
}

// TestSettersandGetters tests that sysvars are logically correct with getter and setter functions.
// i.e. it doesn't make sense to have a SetSession function on a variable that is only globally scoped.
func TestSettersandGetters(t *testing.T) {
Expand Down