Skip to content

Commit

Permalink
expression: fix wrong collation and coercibility (#19169) (#22602)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Jan 28, 2021
1 parent cc92147 commit f74dd5d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions expression/builtin_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions expression/collation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -178,7 +178,7 @@ func deriveCoercibilityForColumn(c *Column) Coercibility {

// DeriveCollationFromExprs derives collation information from these expressions.
func DeriveCollationFromExprs(ctx sessionctx.Context, exprs ...Expression) (dstCharset, dstCollation string) {
curCoer := CoercibilityCoercible
curCoer := CoercibilityIgnorable
curCollationPriority := -1
dstCharset, dstCollation = charset.GetDefaultCharsetAndCollate()
if ctx != nil && ctx.GetSessionVars() != nil {
Expand Down
10 changes: 10 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}

0 comments on commit f74dd5d

Please sign in to comment.