Skip to content

Commit

Permalink
Merge branch 'master' into fix-40633
Browse files Browse the repository at this point in the history
  • Loading branch information
Defined2014 committed Feb 10, 2023
2 parents cc81857 + 278a9fe commit 24a4f34
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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{
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion ddl/serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion errno/errname.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion errors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion parser/mysql/errname.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 24a4f34

Please sign in to comment.