From 12c8658c85ecef9b1b4a3bdaead1d2df62c46185 Mon Sep 17 00:00:00 2001 From: Chao Wang Date: Thu, 26 Sep 2024 05:39:24 +0800 Subject: [PATCH] make test stable --- pkg/expression/exprstatic/evalctx.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/pkg/expression/exprstatic/evalctx.go b/pkg/expression/exprstatic/evalctx.go index 06cf461f0fa7a..5086143497a1c 100644 --- a/pkg/expression/exprstatic/evalctx.go +++ b/pkg/expression/exprstatic/evalctx.go @@ -496,11 +496,35 @@ func (ctx *EvalContext) currentTimeFuncFromStringVal(val string) func() (time.Ti func newSessionVarsWithSystemVariables(vars map[string]string) (*variable.SessionVars, error) { sessionVars := variable.NewSessionVars(nil) + var cs, col []string for name, val := range vars { - if err := sessionVars.SetSystemVar(name, val); err != nil { + switch strings.ToLower(name) { + // `charset_connection` and `collation_connection` will overwrite each other. + // To make the result more determinate, just set them at last step in order: + // `charset_connection` first, then `collation_connection`. + case variable.CharacterSetConnection: + cs = []string{name, val} + case variable.CollationConnection: + col = []string{name, val} + default: + if err := sessionVars.SetSystemVar(name, val); err != nil { + return nil, err + } + } + } + + if cs != nil { + if err := sessionVars.SetSystemVar(cs[0], cs[1]); err != nil { return nil, err } } + + if col != nil { + if err := sessionVars.SetSystemVar(col[0], col[1]); err != nil { + return nil, err + } + } + return sessionVars, nil }