Skip to content

Commit

Permalink
cherry pick #23932 to release-5.0
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
xiongjiwei authored and ti-srebot committed Apr 20, 2021
1 parent 653b6ee commit 5030372
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -2567,7 +2567,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)
}
Expand All @@ -2585,7 +2585,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
Expand Down
9 changes: 9 additions & 0 deletions session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4169,6 +4169,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")
Expand Down

0 comments on commit 5030372

Please sign in to comment.