diff --git a/ddl/ddl.go b/ddl/ddl.go index a624921baa522..c20535f4ddeb5 100644 --- a/ddl/ddl.go +++ b/ddl/ddl.go @@ -32,7 +32,6 @@ import ( "github.com/pingcap/parser/mysql" "github.com/pingcap/parser/terror" pumpcli "github.com/pingcap/tidb-tools/tidb-binlog/pump_client" - "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/ddl/util" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/kv" @@ -102,20 +101,19 @@ var ( errUnsupportedShardRowIDBits = terror.ClassDDL.New(codeUnsupportedShardRowIDBits, "unsupported shard_row_id_bits for table with primary key as row id.") errBlobKeyWithoutLength = terror.ClassDDL.New(codeBlobKeyWithoutLength, "BLOB/TEXT column '%-.192s' used in key specification without a key length") errIncorrectPrefixKey = terror.ClassDDL.New(codeIncorrectPrefixKey, "Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys") - errTooLongKey = terror.ClassDDL.New(codeTooLongKey, - fmt.Sprintf("Specified key was too long; max key length is %d bytes", config.GetGlobalConfig().MaxIndexLength)) - errKeyColumnDoesNotExits = terror.ClassDDL.New(codeKeyColumnDoesNotExits, mysql.MySQLErrName[mysql.ErrKeyColumnDoesNotExits]) - errUnknownTypeLength = terror.ClassDDL.New(codeUnknownTypeLength, "Unknown length for type tp %d") - errUnknownFractionLength = terror.ClassDDL.New(codeUnknownFractionLength, "Unknown Length for type tp %d and fraction %d") - errInvalidJobVersion = terror.ClassDDL.New(codeInvalidJobVersion, "DDL job with version %d greater than current %d") - errFileNotFound = terror.ClassDDL.New(codeFileNotFound, "Can't find file: './%s/%s.frm'") - errErrorOnRename = terror.ClassDDL.New(codeErrorOnRename, "Error on rename of './%s/%s' to './%s/%s'") - errInvalidUseOfNull = terror.ClassDDL.New(codeInvalidUseOfNull, "Invalid use of NULL value") - errTooManyFields = terror.ClassDDL.New(codeTooManyFields, "Too many columns") - errInvalidSplitRegionRanges = terror.ClassDDL.New(codeInvalidRanges, "Failed to split region ranges") - errReorgPanic = terror.ClassDDL.New(codeReorgWorkerPanic, "reorg worker panic.") - errFkColumnCannotDrop = terror.ClassDDL.New(mysql.ErrFkColumnCannotDrop, mysql.MySQLErrName[mysql.ErrFkColumnCannotDrop]) - errFKIncompatibleColumns = terror.ClassDDL.New(mysql.ErrFKIncompatibleColumns, mysql.MySQLErrName[mysql.ErrFKIncompatibleColumns]) + errTooLongKey = terror.ClassDDL.New(codeTooLongKey, mysql.MySQLErrName[mysql.ErrTooLongKey]) + errKeyColumnDoesNotExits = terror.ClassDDL.New(codeKeyColumnDoesNotExits, mysql.MySQLErrName[mysql.ErrKeyColumnDoesNotExits]) + errUnknownTypeLength = terror.ClassDDL.New(codeUnknownTypeLength, "Unknown length for type tp %d") + errUnknownFractionLength = terror.ClassDDL.New(codeUnknownFractionLength, "Unknown Length for type tp %d and fraction %d") + errInvalidJobVersion = terror.ClassDDL.New(codeInvalidJobVersion, "DDL job with version %d greater than current %d") + errFileNotFound = terror.ClassDDL.New(codeFileNotFound, "Can't find file: './%s/%s.frm'") + errErrorOnRename = terror.ClassDDL.New(codeErrorOnRename, "Error on rename of './%s/%s' to './%s/%s'") + errInvalidUseOfNull = terror.ClassDDL.New(codeInvalidUseOfNull, "Invalid use of NULL value") + errTooManyFields = terror.ClassDDL.New(codeTooManyFields, "Too many columns") + errInvalidSplitRegionRanges = terror.ClassDDL.New(codeInvalidRanges, "Failed to split region ranges") + errReorgPanic = terror.ClassDDL.New(codeReorgWorkerPanic, "reorg worker panic.") + errFkColumnCannotDrop = terror.ClassDDL.New(mysql.ErrFkColumnCannotDrop, mysql.MySQLErrName[mysql.ErrFkColumnCannotDrop]) + errFKIncompatibleColumns = terror.ClassDDL.New(mysql.ErrFKIncompatibleColumns, mysql.MySQLErrName[mysql.ErrFKIncompatibleColumns]) errOnlyOnRangeListPartition = terror.ClassDDL.New(codeOnlyOnRangeListPartition, mysql.MySQLErrName[mysql.ErrOnlyOnRangeListPartition]) // errWrongKeyColumn is for table column cannot be indexed. diff --git a/ddl/index.go b/ddl/index.go index 776cce35027ba..634c9ba79d2c8 100755 --- a/ddl/index.go +++ b/ddl/index.go @@ -78,7 +78,7 @@ func buildIndexColumns(columns []*model.ColumnInfo, idxColNames []*ast.IndexColN // The sum of all lengths must be shorter than the max length for prefix. if sumLength > config.GetGlobalConfig().MaxIndexLength { - return nil, errors.Trace(errTooLongKey) + return nil, errTooLongKey.GenWithStackByArgs(config.GetGlobalConfig().MaxIndexLength) } idxColumns = append(idxColumns, &model.IndexColumn{ @@ -123,7 +123,7 @@ func checkIndexPrefixLength(columns []*model.ColumnInfo, idxColumns []*model.Ind sumLength += indexColumnLength // The sum of all lengths must be shorter than the max length for prefix. if sumLength > config.GetGlobalConfig().MaxIndexLength { - return errors.Trace(errTooLongKey) + return errTooLongKey.GenWithStackByArgs(config.GetGlobalConfig().MaxIndexLength) } } return nil @@ -157,7 +157,7 @@ func checkIndexColumn(col *model.ColumnInfo, ic *ast.IndexColName) error { // Specified length must be shorter than the max length for prefix. if ic.Length > config.GetGlobalConfig().MaxIndexLength { - return errors.Trace(errTooLongKey) + return errTooLongKey.GenWithStackByArgs(config.GetGlobalConfig().MaxIndexLength) } return nil } diff --git a/ddl/serial_test.go b/ddl/serial_test.go index e12867a296c9c..e4c59eeb7f955 100644 --- a/ddl/serial_test.go +++ b/ddl/serial_test.go @@ -96,7 +96,8 @@ func (s *testSerialSuite) TestChangeMaxIndexLength(c *C) { tk.MustExec("create table t (c1 varchar(3073), index(c1)) charset = ascii;") tk.MustExec(fmt.Sprintf("create table t1 (c1 varchar(%d), index(c1)) charset = ascii;", config.DefMaxOfMaxIndexLength)) - tk.MustGetErrCode(fmt.Sprintf("create table t2 (c1 varchar(%d), index(c1)) charset = ascii;", config.DefMaxOfMaxIndexLength+1), mysql.ErrTooLongKey) + _, err := tk.Exec(fmt.Sprintf("create table t2 (c1 varchar(%d), index(c1)) charset = ascii;", config.DefMaxOfMaxIndexLength+1)) + c.Assert(err.Error(), Equals, "[ddl:1071]Specified key was too long; max key length is 12288 bytes") tk.MustExec("drop table t, t1") }