From 18e3204edb3f102ab4e6f3d252a6ec70cc920c61 Mon Sep 17 00:00:00 2001 From: Lynn Date: Mon, 28 Oct 2019 13:07:13 +0800 Subject: [PATCH] ddl, executor: limit the length of index name --- ddl/index.go | 4 ++++ executor/ddl_test.go | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/ddl/index.go b/ddl/index.go index 92d5ae0712903..b3602277910b9 100644 --- a/ddl/index.go +++ b/ddl/index.go @@ -174,6 +174,10 @@ func getIndexColumnLength(col *model.ColumnInfo, colLen int) (int, error) { } 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 7a5860dcebb09..8505f8ce5e3e0 100644 --- a/executor/ddl_test.go +++ b/executor/ddl_test.go @@ -616,6 +616,11 @@ func (s *testSuite3) 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 *testSuite3) TestShardRowIDBits(c *C) {