diff --git a/ddl/index.go b/ddl/index.go index 833a825e24e30..07a3960eb07fc 100644 --- a/ddl/index.go +++ b/ddl/index.go @@ -101,7 +101,7 @@ func buildIndexColumns(ctx sessionctx.Context, columns []*model.ColumnInfo, inde // The multiple column index and the unique index in which the length sum exceeds the maximum size // will return an error instead produce a warning. if ctx == nil || ctx.GetSessionVars().StrictSQLMode || mysql.HasUniKeyFlag(col.GetFlag()) || len(indexPartSpecifications) > 1 { - return nil, false, dbterror.ErrTooLongKey.GenWithStackByArgs(maxIndexLength) + return nil, false, dbterror.ErrTooLongKey.GenWithStackByArgs(sumLength, maxIndexLength) } // truncate index length and produce warning message in non-restrict sql mode. colLenPerUint, err := getIndexColumnLength(col, 1) @@ -110,7 +110,7 @@ func buildIndexColumns(ctx sessionctx.Context, columns []*model.ColumnInfo, inde } indexColLen = maxIndexLength / colLenPerUint // produce warning message - ctx.GetSessionVars().StmtCtx.AppendWarning(dbterror.ErrTooLongKey.FastGenByArgs(maxIndexLength)) + ctx.GetSessionVars().StmtCtx.AppendWarning(dbterror.ErrTooLongKey.FastGenByArgs(sumLength, maxIndexLength)) } idxParts = append(idxParts, &model.IndexColumn{ @@ -149,7 +149,7 @@ func checkIndexPrefixLength(columns []*model.ColumnInfo, idxColumns []*model.Ind return err } if idxLen > config.GetGlobalConfig().MaxIndexLength { - return dbterror.ErrTooLongKey.GenWithStackByArgs(config.GetGlobalConfig().MaxIndexLength) + return dbterror.ErrTooLongKey.GenWithStackByArgs(idxLen, config.GetGlobalConfig().MaxIndexLength) } return nil } @@ -211,7 +211,7 @@ func checkIndexColumn(ctx sessionctx.Context, col *model.ColumnInfo, indexColumn maxIndexLength := config.GetGlobalConfig().MaxIndexLength if indexColumnLen > maxIndexLength && (ctx == nil || ctx.GetSessionVars().StrictSQLMode) { // return error in strict sql mode - return dbterror.ErrTooLongKey.GenWithStackByArgs(maxIndexLength) + return dbterror.ErrTooLongKey.GenWithStackByArgs(indexColumnLen, maxIndexLength) } return nil } diff --git a/ddl/serial_test.go b/ddl/serial_test.go index 668b675a0b185..4d11db2b3409c 100644 --- a/ddl/serial_test.go +++ b/ddl/serial_test.go @@ -102,7 +102,7 @@ func TestChangeMaxIndexLength(t *testing.T) { 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)) err := tk.ExecToErr(fmt.Sprintf("create table t2 (c1 varchar(%d), index(c1)) charset = ascii;", config.DefMaxOfMaxIndexLength+1)) - require.EqualError(t, err, "[ddl:1071]Specified key was too long; max key length is 12288 bytes") + require.EqualError(t, err, "[ddl:1071]Specified key was too long (12289 bytes); max key length is 12288 bytes") } func TestCreateTableWithLike(t *testing.T) { diff --git a/errno/errname.go b/errno/errname.go index 39deb486ff2fb..0f6c3db0e1645 100644 --- a/errno/errname.go +++ b/errno/errname.go @@ -92,7 +92,7 @@ var MySQLErrName = map[uint16]*mysql.ErrMessage{ ErrMultiplePriKey: mysql.Message("Multiple primary key defined", nil), ErrTooManyKeys: mysql.Message("Too many keys specified; max %d keys allowed", nil), ErrTooManyKeyParts: mysql.Message("Too many key parts specified; max %d parts allowed", nil), - ErrTooLongKey: mysql.Message("Specified key was too long; max key length is %d bytes", nil), + ErrTooLongKey: mysql.Message("Specified key was too long (%d bytes); max key length is %d bytes", nil), ErrKeyColumnDoesNotExits: mysql.Message("Key column '%-.192s' doesn't exist in table", nil), ErrBlobUsedAsKey: mysql.Message("BLOB column '%-.192s' can't be used in key specification with the used table type", nil), ErrTooBigFieldlength: mysql.Message("Column length too big for column '%-.192s' (max = %d); use BLOB or TEXT instead", nil), diff --git a/errors.toml b/errors.toml index d7808c34337a1..9b503c113a836 100644 --- a/errors.toml +++ b/errors.toml @@ -668,7 +668,7 @@ Too many keys specified; max %d keys allowed ["ddl:1071"] error = ''' -Specified key was too long; max key length is %d bytes +Specified key was too long (%d bytes); max key length is %d bytes ''' ["ddl:1072"] diff --git a/parser/mysql/errname.go b/parser/mysql/errname.go index 3066d9f6fb6b0..5b1cff580f658 100644 --- a/parser/mysql/errname.go +++ b/parser/mysql/errname.go @@ -97,7 +97,7 @@ var MySQLErrName = map[uint16]*ErrMessage{ ErrMultiplePriKey: Message("Multiple primary key defined", nil), ErrTooManyKeys: Message("Too many keys specified; max %d keys allowed", nil), ErrTooManyKeyParts: Message("Too many key parts specified; max %d parts allowed", nil), - ErrTooLongKey: Message("Specified key was too long; max key length is %d bytes", nil), + ErrTooLongKey: Message("Specified key was too long (%d bytes); max key length is %d bytes", nil), ErrKeyColumnDoesNotExits: Message("Key column '%-.192s' doesn't exist in table", nil), ErrBlobUsedAsKey: Message("BLOB column '%-.192s' can't be used in key specification with the used table type", nil), ErrTooBigFieldlength: Message("Column length too big for column '%-.192s' (max = %d); use BLOB or TEXT instead", nil),