Skip to content

Commit

Permalink
ddl: fix the issue that the length of the index is 0. (pingcap#11045)
Browse files Browse the repository at this point in the history
  • Loading branch information
zimulala committed Jul 11, 2019
1 parent 79eba3c commit a2193af
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,25 @@ func (s *testIntegrationSuite) TestEndIncluded(c *C) {
tk.MustExec("admin check table t")
}

func (s *testIntegrationSuite) TestIndexLength(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("create table idx_len(a int(0), b timestamp(0), c datetime(0), d time(0), f float(0), g decimal(0))")
tk.MustExec("create index idx on idx_len(a)")
tk.MustExec("alter table idx_len add index idxa(a)")
tk.MustExec("create index idx1 on idx_len(b)")
tk.MustExec("alter table idx_len add index idxb(b)")
tk.MustExec("create index idx2 on idx_len(c)")
tk.MustExec("alter table idx_len add index idxc(c)")
tk.MustExec("create index idx3 on idx_len(d)")
tk.MustExec("alter table idx_len add index idxd(d)")
tk.MustExec("create index idx4 on idx_len(f)")
tk.MustExec("alter table idx_len add index idxf(f)")
tk.MustExec("create index idx5 on idx_len(g)")
tk.MustExec("alter table idx_len add index idxg(g)")
tk.MustExec("create table idx_len1(a int(0), b timestamp(0), c datetime(0), d time(0), f float(0), g decimal(0), index(a), index(b), index(c), index(d), index(f), index(g))")
}

func (s *testIntegrationSuite) TestNullGeneratedColumn(c *C) {
tk := testkit.NewTestKit(c, s.store)

Expand Down
2 changes: 1 addition & 1 deletion ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func buildIndexColumns(columns []*model.ColumnInfo, idxColNames []*ast.IndexColN
return nil, errKeyColumnDoesNotExits.GenWithStack("column does not exist: %s", ic.Column.Name)
}

if col.Flen == 0 {
if col.Flen == 0 && (types.IsTypeChar(col.FieldType.Tp) || types.IsTypeVarchar(col.FieldType.Tp)) {
return nil, errors.Trace(errWrongKeyColumn.GenWithStackByArgs(ic.Column.Name))
}

Expand Down

0 comments on commit a2193af

Please sign in to comment.