ddl: fix a bug that creating a table with set column don't handle collation correctly (#17905)

Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
This commit is contained in:
wjHuang
2020-06-10 19:37:40 +08:00
committed by GitHub
parent f87e2b1710
commit 83632ecc6e
2 changed files with 16 additions and 3 deletions

View File

@ -760,15 +760,16 @@ func setSetDefaultValue(v types.Datum, col *table.Column) (string, error) {
return str, nil
}
ctor := collate.GetCollator(col.Collate)
valMap := make(map[string]struct{}, len(col.Elems))
dVals := strings.Split(strings.ToLower(str), ",")
dVals := strings.Split(str, ",")
for _, dv := range dVals {
valMap[dv] = struct{}{}
valMap[string(ctor.Key(dv))] = struct{}{}
}
var existCnt int
for dv := range valMap {
for i := range col.Elems {
e := strings.ToLower(col.Elems[i])
e := string(ctor.Key(col.Elems[i]))
if e == dv {
existCnt++
break

View File

@ -6619,3 +6619,15 @@ func (s *testIntegrationSuite) TestIssue17287(c *C) {
tk.MustQuery("execute stmt7 using @val1;").Check(testkit.Rows("1589873945"))
tk.MustQuery("execute stmt7 using @val2;").Check(testkit.Rows("1589873946"))
}
func (s *testIntegrationSerialSuite) TestIssue17891(c *C) {
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(id int, value set ('a','b','c') charset utf8mb4 collate utf8mb4_bin default 'a,b ');")
tk.MustExec("drop table t")
tk.MustExec("create table test(id int, value set ('a','b','c') charset utf8mb4 collate utf8mb4_general_ci default 'a,B ,C');")
}