Skip to content

Commit

Permalink
Bug#25779239 ALTER TABLE FAILS WHEN DEFAULT CHARACTER SET CHANGES TO …
Browse files Browse the repository at this point in the history
…UTF8MB4

Change-Id: Idc375b71b86f37daeff44424de635095c3d04c86
Problem: wrong calculation of column_length in prepare_key_column()
Fix: multiply charset->mbmaxlen only for relevant field types.
  • Loading branch information
Tor Didriksen committed Mar 27, 2017
1 parent 2780e2a commit 8afbe2f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
18 changes: 18 additions & 0 deletions mysql-test/r/alter_table.result
Expand Up @@ -3138,3 +3138,21 @@ FROM information_schema.triggers WHERE event_object_schema = 'test';
TRIGGER_NAME EVENT_OBJECT_SCHEMA EVENT_OBJECT_TABLE ACTION_STATEMENT
t1_bi test t4 SET @a:=0
DROP TABLE t4;

Bug#25779239 ALTER TABLE FAILS WHEN DEFAULT
CHARACTER SET CHANGES TO UTF8MB4

CREATE TABLE t1(
i INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY) charset latin1;
ALTER TABLE t1
DROP i,
ADD i INT UNSIGNED NOT NULL AUTO_INCREMENT,
AUTO_INCREMENT = 1;
DROP TABLE t1;
CREATE TABLE t1(
i INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY) charset utf8mb4;
ALTER TABLE t1
DROP i,
ADD i INT UNSIGNED NOT NULL AUTO_INCREMENT,
AUTO_INCREMENT = 1;
DROP TABLE t1;
21 changes: 21 additions & 0 deletions mysql-test/t/alter_table.test
Expand Up @@ -2587,3 +2587,24 @@ DROP TABLE t4;
--eval alter schema test default character set $testdbcs108;
--enable_query_log
########################################

--echo
--echo Bug#25779239 ALTER TABLE FAILS WHEN DEFAULT
--echo CHARACTER SET CHANGES TO UTF8MB4
--echo

CREATE TABLE t1(
i INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY) charset latin1;
ALTER TABLE t1
DROP i,
ADD i INT UNSIGNED NOT NULL AUTO_INCREMENT,
AUTO_INCREMENT = 1;
DROP TABLE t1;

CREATE TABLE t1(
i INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY) charset utf8mb4;
ALTER TABLE t1
DROP i,
ADD i INT UNSIGNED NOT NULL AUTO_INCREMENT,
AUTO_INCREMENT = 1;
DROP TABLE t1;
18 changes: 17 additions & 1 deletion sql/sql_table.cc
Expand Up @@ -5751,7 +5751,23 @@ static bool prepare_key_column(THD *thd, HA_CREATE_INFO *create_info,
}
else
{
column_length= column->length * sql_field->charset->mbmaxlen;
switch (sql_field->sql_type) {
case MYSQL_TYPE_TINY_BLOB:
case MYSQL_TYPE_MEDIUM_BLOB:
case MYSQL_TYPE_LONG_BLOB:
case MYSQL_TYPE_BLOB:
case MYSQL_TYPE_GEOMETRY:
case MYSQL_TYPE_JSON:
case MYSQL_TYPE_VAR_STRING:
case MYSQL_TYPE_STRING:
case MYSQL_TYPE_VARCHAR:
case MYSQL_TYPE_ENUM:
case MYSQL_TYPE_SET:
column_length= column->length * sql_field->charset->mbmaxlen;
break;
default:
column_length= column->length;
}

if (key->type == KEYTYPE_SPATIAL)
{
Expand Down

0 comments on commit 8afbe2f

Please sign in to comment.