From ec5ebfdd114b202e794a184157992441b1d0e08e Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 7 Dec 2021 18:59:58 +0800 Subject: [PATCH] expression: fix data race in the collationInfo Signed-off-by: Weizhen Wang --- expression/builtin_string_test.go | 12 ++++++------ expression/builtin_test.go | 8 ++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/expression/builtin_string_test.go b/expression/builtin_string_test.go index 6035e8b120fbf..54b98770b857c 100644 --- a/expression/builtin_string_test.go +++ b/expression/builtin_string_test.go @@ -439,7 +439,7 @@ func TestLeft(t *testing.T) { } } - _, err := funcs[ast.Left].getFunction(ctx, []Expression{varcharCon, int8Con}) + _, err := funcs[ast.Left].getFunction(ctx, []Expression{getVarcharCon(), getInt8Con()}) require.NoError(t, err) } @@ -490,7 +490,7 @@ func TestRight(t *testing.T) { } } - _, err := funcs[ast.Right].getFunction(ctx, []Expression{varcharCon, int8Con}) + _, err := funcs[ast.Right].getFunction(ctx, []Expression{getVarcharCon(), getInt8Con()}) require.NoError(t, err) } @@ -629,7 +629,7 @@ func TestLower(t *testing.T) { } } - _, err := funcs[ast.Lower].getFunction(ctx, []Expression{varcharCon}) + _, err := funcs[ast.Lower].getFunction(ctx, []Expression{getVarcharCon()}) require.NoError(t, err) // Test GBK String @@ -688,7 +688,7 @@ func TestUpper(t *testing.T) { } } - _, err := funcs[ast.Upper].getFunction(ctx, []Expression{varcharCon}) + _, err := funcs[ast.Upper].getFunction(ctx, []Expression{getVarcharCon()}) require.NoError(t, err) // Test GBK String @@ -1338,10 +1338,10 @@ func TestHexFunc(t *testing.T) { } } - _, err := funcs[ast.Hex].getFunction(ctx, []Expression{int8Con}) + _, err := funcs[ast.Hex].getFunction(ctx, []Expression{getInt8Con()}) require.NoError(t, err) - _, err = funcs[ast.Hex].getFunction(ctx, []Expression{varcharCon}) + _, err = funcs[ast.Hex].getFunction(ctx, []Expression{getVarcharCon()}) require.NoError(t, err) } diff --git a/expression/builtin_test.go b/expression/builtin_test.go index 57e39282100ab..79faddd2ffd3a 100644 --- a/expression/builtin_test.go +++ b/expression/builtin_test.go @@ -191,3 +191,11 @@ var ( // MySQL varchar. varcharCon = &Constant{RetType: &types.FieldType{Tp: mysql.TypeVarchar, Charset: charset.CharsetUTF8, Collate: charset.CollationUTF8}} ) + +func getInt8Con() Expression { + return int8Con.Clone() +} + +func getVarcharCon() Expression { + return varcharCon.Clone() +}