Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression: fix wrong collation and coercibility #19169

Merged
merged 5 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"))
}