diff --git a/mysql-test/r/innodb_mysql.result b/mysql-test/r/innodb_mysql.result index f32878309b827aeeda7bd7910713bebaf7ada2fd..f44ce5b5122913c7637887f6b8a5b1c6fc4c47d9 100644 --- a/mysql-test/r/innodb_mysql.result +++ b/mysql-test/r/innodb_mysql.result @@ -418,7 +418,7 @@ DROP TABLE t1,t2; create table t1(f1 varchar(800) binary not null, key(f1)) engine = innodb character set utf8 collate utf8_general_ci; Warnings: -Warning 1071 Specified key was too long; max key length is 765 bytes +Warning 1071 Specified key was too long; max key length is 767 bytes insert into t1 values('aaa'); drop table t1; CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c FLOAT, KEY b(b)) ENGINE = INNODB; @@ -735,6 +735,17 @@ COUNT(*) 3072 set @@sort_buffer_size=default; DROP TABLE t1,t2; +create table t1(a text) engine=innodb default charset=utf8; +insert into t1 values('aaa'); +alter table t1 add index(a(1024)); +Warnings: +Warning 1071 Specified key was too long; max key length is 767 bytes +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` text, + KEY `a` (`a`(255)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 drop table if exists t1; create table t1 (a int) engine=innodb; alter table t1 alter a set default 1; diff --git a/mysql-test/t/innodb_mysql.test b/mysql-test/t/innodb_mysql.test index 0d43d13ec3a20ffab814a4a20be71a306b3da884..30b40f52901b017f8663363079ca27c88af5022c 100644 --- a/mysql-test/t/innodb_mysql.test +++ b/mysql-test/t/innodb_mysql.test @@ -754,4 +754,13 @@ create table t1 (a int) engine=innodb; alter table t1 alter a set default 1; drop table t1; +# +# Bug #28125: ERROR 2013 when adding index. +# +create table t1(a text) engine=innodb default charset=utf8; +insert into t1 values('aaa'); +alter table t1 add index(a(1024)); +show create table t1; +drop table t1; + --echo End of 5.0 tests diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 87f23097a6680f7245b5b7853cbfec837ddb0c8e..0da639f989662411f9ef94f46d57a75dd14a9b3d 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1357,6 +1357,8 @@ static int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, length); push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_TOO_LONG_KEY, warn_buff); + /* Align key length to multibyte char boundary */ + length-= length % sql_field->charset->mbmaxlen; } else { @@ -1387,8 +1389,6 @@ static int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, if (length > file->max_key_part_length() && key->type != Key::FULLTEXT) { length= file->max_key_part_length(); - /* Align key length to multibyte char boundary */ - length-= length % sql_field->charset->mbmaxlen; if (key->type == Key::MULTIPLE) { /* not a critical problem */ @@ -1397,6 +1397,8 @@ static int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, length); push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_TOO_LONG_KEY, warn_buff); + /* Align key length to multibyte char boundary */ + length-= length % sql_field->charset->mbmaxlen; } else {