Skip to content

Commit dcc9dcc

Browse files
authored
ddl: tidb_scatter_region variable supports setting value in both upper/lower case (#57677)
close #57669
1 parent 2125737 commit dcc9dcc

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

pkg/ddl/table_split_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ func TestScatterRegion(t *testing.T) {
9797
tk.MustQuery("select @@tidb_scatter_region;").Check(testkit.Rows("table"))
9898
tk.MustExec("set @@tidb_scatter_region = 'global';")
9999
tk.MustQuery("select @@tidb_scatter_region;").Check(testkit.Rows("global"))
100+
tk.MustExec("set @@tidb_scatter_region = 'TABLE';")
101+
tk.MustQuery("select @@tidb_scatter_region;").Check(testkit.Rows("table"))
102+
tk.MustExec("set @@tidb_scatter_region = 'GLOBAL';")
103+
tk.MustQuery("select @@tidb_scatter_region;").Check(testkit.Rows("global"))
100104
tk.MustExec("set @@tidb_scatter_region = '';")
101105
tk.MustQuery("select @@tidb_scatter_region;").Check(testkit.Rows(""))
102106

@@ -111,13 +115,34 @@ func TestScatterRegion(t *testing.T) {
111115
tk.MustQuery("select @@global.tidb_scatter_region;").Check(testkit.Rows("global"))
112116
tk.MustExec("set global tidb_scatter_region = '';")
113117
tk.MustQuery("select @@global.tidb_scatter_region;").Check(testkit.Rows(""))
118+
tk2 = testkit.NewTestKit(t, store)
119+
tk2.MustQuery("select @@tidb_scatter_region;").Check(testkit.Rows(""))
120+
121+
tk.MustExec("set global tidb_scatter_region = 'TABLE';")
122+
tk.MustQuery("select @@global.tidb_scatter_region;").Check(testkit.Rows("table"))
123+
tk.MustQuery("select @@tidb_scatter_region;").Check(testkit.Rows(""))
124+
tk2 = testkit.NewTestKit(t, store)
125+
tk2.MustQuery("select @@tidb_scatter_region;").Check(testkit.Rows("table"))
126+
127+
tk.MustExec("set global tidb_scatter_region = 'GLOBAL';")
128+
tk.MustQuery("select @@global.tidb_scatter_region;").Check(testkit.Rows("global"))
129+
tk.MustExec("set global tidb_scatter_region = '';")
130+
tk.MustQuery("select @@global.tidb_scatter_region;").Check(testkit.Rows(""))
114131

115132
err := tk.ExecToErr("set @@tidb_scatter_region = 'test';")
116133
require.ErrorContains(t, err, "invalid value for 'test', it should be either '', 'table' or 'global'")
134+
err = tk.ExecToErr("set @@tidb_scatter_region = 'te st';")
135+
require.ErrorContains(t, err, "invalid value for 'te st', it should be either '', 'table' or 'global'")
117136
err = tk.ExecToErr("set @@tidb_scatter_region = '1';")
118137
require.ErrorContains(t, err, "invalid value for '1', it should be either '', 'table' or 'global'")
119138
err = tk.ExecToErr("set @@tidb_scatter_region = 0;")
120139
require.ErrorContains(t, err, "invalid value for '0', it should be either '', 'table' or 'global'")
140+
141+
tk.MustQuery("select @@tidb_scatter_region;").Check(testkit.Rows(""))
142+
tk.MustExec("set @@tidb_scatter_region = 'TaBlE';")
143+
tk.MustQuery("select @@tidb_scatter_region;").Check(testkit.Rows("table"))
144+
tk.MustExec("set @@tidb_scatter_region = 'gLoBaL';")
145+
tk.MustQuery("select @@tidb_scatter_region;").Check(testkit.Rows("global"))
121146
}
122147

123148
type kvStore interface {

pkg/sessionctx/variable/sysvar.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -818,10 +818,11 @@ var defaultSysVars = []*SysVar{
818818
return vars.ScatterRegion, nil
819819
},
820820
Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
821-
if normalizedValue != ScatterOff && normalizedValue != ScatterTable && normalizedValue != ScatterGlobal {
822-
return "", fmt.Errorf("invalid value for '%s', it should be either '%s', '%s' or '%s'", normalizedValue, ScatterOff, ScatterTable, ScatterGlobal)
821+
lowerVal := strings.ToLower(normalizedValue)
822+
if lowerVal != ScatterOff && lowerVal != ScatterTable && lowerVal != ScatterGlobal {
823+
return "", fmt.Errorf("invalid value for '%s', it should be either '%s', '%s' or '%s'", lowerVal, ScatterOff, ScatterTable, ScatterGlobal)
823824
}
824-
return normalizedValue, nil
825+
return lowerVal, nil
825826
},
826827
},
827828
{Scope: ScopeGlobal, Name: TiDBEnableStmtSummary, Value: BoolToOnOff(DefTiDBEnableStmtSummary), Type: TypeBool, AllowEmpty: true,

0 commit comments

Comments
 (0)