Skip to content

Commit

Permalink
expression: fix wrong collation and coercibility (pingcap#19169)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongjiwei authored Aug 13, 2020
1 parent 3f38fa5 commit b9e90ef
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 @@ -1139,6 +1139,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 @@ -143,7 +143,7 @@ func deriveCoercibilityForScarlarFunc(sf *ScalarFunction) Coercibility {
if !types.IsString(sf.RetType.Tp) {
return CoercibilityNumeric
}
coer := CoercibilityIgnorable
coer := CoercibilityCoercible
for _, arg := range sf.GetArgs() {
if arg.Coercibility() < coer {
coer = arg.Coercibility()
Expand All @@ -170,7 +170,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 := 0
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 @@ -6901,3 +6901,13 @@ func (s *testIntegrationSerialSuite) TestIssue19045(c *C) {
tk.MustExec(`insert into t(a) values('101'),('101');`)
tk.MustQuery(`select ( SELECT t1.a FROM t1, t2 WHERE t1.b = t2.a AND t2.b = '03' AND t1.c = a.a) invode from t a ;`).Check(testkit.Rows("a011", "a011"))
}

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 b9e90ef

Please sign in to comment.