session: fix global variable collation_server does not take effect in new session (#23932)
This commit is contained in:
@ -2570,7 +2570,7 @@ func (s *session) loadCommonGlobalVariablesIfNeeded() error {
|
||||
vars = append(vars, variable.PluginVarNames...)
|
||||
}
|
||||
|
||||
stmt, err := s.ParseWithParams(context.TODO(), "select HIGH_PRIORITY * from mysql.global_variables where variable_name in (%?)", vars)
|
||||
stmt, err := s.ParseWithParams(context.TODO(), "select HIGH_PRIORITY * from mysql.global_variables where variable_name in (%?) order by VARIABLE_NAME", vars)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Trace(err)
|
||||
}
|
||||
@ -2588,7 +2588,9 @@ func (s *session) loadCommonGlobalVariablesIfNeeded() error {
|
||||
for _, row := range rows {
|
||||
varName := row.GetString(0)
|
||||
varVal := row.GetDatum(1, &fields[1].Column.FieldType)
|
||||
if _, ok := vars.GetSystemVar(varName); !ok {
|
||||
// `collation_server` is related to `character_set_server`, set `character_set_server` will also set `collation_server`.
|
||||
// We have to make sure we set the `collation_server` with right value.
|
||||
if _, ok := vars.GetSystemVar(varName); !ok || varName == variable.CollationServer {
|
||||
err = variable.SetSessionSystemVar(s.sessionVars, varName, varVal)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@ -4171,6 +4171,15 @@ func (s *testSessionSerialSuite) TestTiKVSystemVars(c *C) {
|
||||
|
||||
}
|
||||
|
||||
func (s *testSessionSerialSuite) TestGlobalVarCollationServer(c *C) {
|
||||
tk := testkit.NewTestKit(c, s.store)
|
||||
tk.MustExec("set @@global.collation_server=utf8mb4_general_ci")
|
||||
tk.MustQuery("show global variables like 'collation_server'").Check(testkit.Rows("collation_server utf8mb4_general_ci"))
|
||||
tk = testkit.NewTestKit(c, s.store)
|
||||
tk.MustQuery("show global variables like 'collation_server'").Check(testkit.Rows("collation_server utf8mb4_general_ci"))
|
||||
tk.MustQuery("show variables like 'collation_server'").Check(testkit.Rows("collation_server utf8mb4_general_ci"))
|
||||
}
|
||||
|
||||
func (s *testSessionSerialSuite) TestProcessInfoIssue22068(c *C) {
|
||||
tk := testkit.NewTestKit(c, s.store)
|
||||
tk.MustExec("use test")
|
||||
|
||||
Reference in New Issue
Block a user