From 9e672832009ca98dd657e3a8b3e3da91de6f9340 Mon Sep 17 00:00:00 2001 From: xiongjiwei Date: Thu, 13 Aug 2020 16:28:49 +0800 Subject: [PATCH 1/2] cherry pick #19169 to release-4.0 Signed-off-by: ti-srebot --- expression/builtin_math.go | 1 + expression/collation.go | 7 ++++++- expression/integration_test.go | 10 ++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/expression/builtin_math.go b/expression/builtin_math.go index 4d30548c06a4a..41d976ee3df11 100644 --- a/expression/builtin_math.go +++ b/expression/builtin_math.go @@ -1142,6 +1142,7 @@ func (c *convFunctionClass) getFunction(ctx sessionctx.Context, args []Expressio if err != nil { return nil, err } + bf.tp.Charset, bf.tp.Collate = ctx.GetSessionVars().GetCharsetInfo() bf.tp.Flen = 64 sig := &builtinConvSig{bf} sig.setPbCode(tipb.ScalarFuncSig_Conv) diff --git a/expression/collation.go b/expression/collation.go index 9c7f7345eb7c7..064f15122e166 100644 --- a/expression/collation.go +++ b/expression/collation.go @@ -151,7 +151,7 @@ func deriveCoercibilityForScarlarFunc(sf *ScalarFunction) Coercibility { if sf.RetType.EvalType() != types.ETString { return CoercibilityNumeric } - coer := CoercibilityIgnorable + coer := CoercibilityCoercible for _, arg := range sf.GetArgs() { if arg.Coercibility() < coer { coer = arg.Coercibility() @@ -178,8 +178,13 @@ func deriveCoercibilityForColumn(c *Column) Coercibility { // DeriveCollationFromExprs derives collation information from these expressions. func DeriveCollationFromExprs(ctx sessionctx.Context, exprs ...Expression) (dstCharset, dstCollation string) { +<<<<<<< HEAD curCoer := CoercibilityCoercible curCollationPriority := -1 +======= + curCoer := CoercibilityIgnorable + curCollationPriority := 0 +>>>>>>> b9e90ef61... expression: fix wrong collation and coercibility (#19169) dstCharset, dstCollation = charset.GetDefaultCharsetAndCollate() if ctx != nil && ctx.GetSessionVars() != nil { dstCharset, dstCollation = ctx.GetSessionVars().GetCharsetInfo() diff --git a/expression/integration_test.go b/expression/integration_test.go index ce8c0f58e8ecc..a55e2c2e567a1 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -7668,3 +7668,13 @@ func (s *testIntegrationSuite) TestIssue11333(c *C) { tk.MustQuery(`select 0.0000000000000000000000000000000000000000000000000000000000000000000000012;`).Check(testkit.Rows("0.000000000000000000000000000000000000000000000000000000000000000000000001")) tk.MustQuery(`select 0.000000000000000000000000000000000000000000000000000000000000000000000001;`).Check(testkit.Rows("0.000000000000000000000000000000000000000000000000000000000000000000000001")) } + +func (s *testIntegrationSerialSuite) TestIssue19116(c *C) { + collate.SetNewCollationEnabledForTest(true) + defer collate.SetNewCollationEnabledForTest(false) + + tk := testkit.NewTestKit(c, s.store) + tk.MustQuery("select collation(concat(NULL,NULL));").Check(testkit.Rows("binary")) + tk.MustQuery("select coercibility(concat(1,1));").Check(testkit.Rows("4")) + tk.MustQuery("select coercibility(1);").Check(testkit.Rows("5")) +} From b11f86350b3d6fdd7c41ea9372ba003d90df34d6 Mon Sep 17 00:00:00 2001 From: jwxiong Date: Thu, 28 Jan 2021 18:18:38 +0800 Subject: [PATCH 2/2] c-p --- expression/collation.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/expression/collation.go b/expression/collation.go index 064f15122e166..4163c670513fd 100644 --- a/expression/collation.go +++ b/expression/collation.go @@ -178,13 +178,8 @@ func deriveCoercibilityForColumn(c *Column) Coercibility { // DeriveCollationFromExprs derives collation information from these expressions. func DeriveCollationFromExprs(ctx sessionctx.Context, exprs ...Expression) (dstCharset, dstCollation string) { -<<<<<<< HEAD - curCoer := CoercibilityCoercible - curCollationPriority := -1 -======= curCoer := CoercibilityIgnorable - curCollationPriority := 0 ->>>>>>> b9e90ef61... expression: fix wrong collation and coercibility (#19169) + curCollationPriority := -1 dstCharset, dstCollation = charset.GetDefaultCharsetAndCollate() if ctx != nil && ctx.GetSessionVars() != nil { dstCharset, dstCollation = ctx.GetSessionVars().GetCharsetInfo()