diff --git a/ddl/index.go b/ddl/index.go index ec644a3bfcd52..4081642471930 100644 --- a/ddl/index.go +++ b/ddl/index.go @@ -139,6 +139,10 @@ func buildIndexColumns(columns []*model.ColumnInfo, idxColNames []*ast.IndexColN } func buildIndexInfo(tblInfo *model.TableInfo, indexName model.CIStr, idxColNames []*ast.IndexColName, state model.SchemaState) (*model.IndexInfo, error) { + if err := checkTooLongIndex(indexName); err != nil { + return nil, errors.Trace(err) + } + idxColumns, err := buildIndexColumns(tblInfo.Columns, idxColNames) if err != nil { return nil, errors.Trace(err) diff --git a/executor/ddl_test.go b/executor/ddl_test.go index 526a9f5f113c5..65e3b91d40ce7 100644 --- a/executor/ddl_test.go +++ b/executor/ddl_test.go @@ -449,6 +449,11 @@ func (s *testSuite) TestTooLargeIdentifierLength(c *C) { tk.MustExec(fmt.Sprintf("drop index %s on t", indexName1)) _, err = tk.Exec(fmt.Sprintf("create index %s on t(c)", indexName2)) c.Assert(err.Error(), Equals, fmt.Sprintf("[ddl:1059]Identifier name '%s' is too long", indexName2)) + + // for create table with index. + tk.MustExec("drop table t;") + _, err = tk.Exec(fmt.Sprintf("create table t(c int, index %s(c));", indexName2)) + c.Assert(err.Error(), Equals, fmt.Sprintf("[ddl:1059]Identifier name '%s' is too long", indexName2)) } func (s *testSuite) TestShardRowIDBits(c *C) {