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) #22602

Merged
merged 2 commits into from
Jan 28, 2021
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 @@ -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"))
}