diff --git a/mysql-test/suite/innodb/r/alter_table.result b/mysql-test/suite/innodb/r/alter_table.result index 873baa905c6..7c64511c866 100644 --- a/mysql-test/suite/innodb/r/alter_table.result +++ b/mysql-test/suite/innodb/r/alter_table.result @@ -107,5 +107,15 @@ alter table t1 engine=innodb; alter table t1 add column b int; drop table t1,t2; # +# MDEV-19272 Assertion unireg_check...Field::NEXT_NUMBER failed +# +CREATE TABLE t1 (c INT AUTO_INCREMENT NULL UNIQUE) ENGINE=InnoDB; +ALTER TABLE t1 MODIFY c INT NOT NULL, ALGORITHM=INPLACE; +DROP TABLE t1; +CREATE TABLE t1 (c TIMESTAMP AUTO_INCREMENT UNIQUE) ENGINE=InnoDB; +ERROR 42000: Incorrect column specifier for column 'c' +CREATE TABLE t1 (c DATETIME AUTO_INCREMENT UNIQUE) ENGINE=InnoDB; +ERROR 42000: Incorrect column specifier for column 'c' +# # End of 10.4 tests # diff --git a/mysql-test/suite/innodb/t/alter_table.test b/mysql-test/suite/innodb/t/alter_table.test index 2b84a37cdce..ae247e7cada 100644 --- a/mysql-test/suite/innodb/t/alter_table.test +++ b/mysql-test/suite/innodb/t/alter_table.test @@ -109,6 +109,17 @@ alter table t1 engine=innodb; alter table t1 add column b int; drop table t1,t2; +--echo # +--echo # MDEV-19272 Assertion unireg_check...Field::NEXT_NUMBER failed +--echo # +CREATE TABLE t1 (c INT AUTO_INCREMENT NULL UNIQUE) ENGINE=InnoDB; +ALTER TABLE t1 MODIFY c INT NOT NULL, ALGORITHM=INPLACE; +DROP TABLE t1; +--error ER_WRONG_FIELD_SPEC +CREATE TABLE t1 (c TIMESTAMP AUTO_INCREMENT UNIQUE) ENGINE=InnoDB; +--error ER_WRONG_FIELD_SPEC +CREATE TABLE t1 (c DATETIME AUTO_INCREMENT UNIQUE) ENGINE=InnoDB; + --echo # --echo # End of 10.4 tests --echo # diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index a330cbc5460..5ce5360e14a 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -2408,6 +2408,13 @@ innodb_instant_alter_column_allowed_reason: & ALTER_ADD_COLUMN)); if (const Field* f = cf.field) { + /* An AUTO_INCREMENT attribute can only + be added to an existing column by ALGORITHM=COPY, + but we can remove the attribute. */ + ut_ad((MTYP_TYPENR((*af)->unireg_check) + != Field::NEXT_NUMBER) + || (MTYP_TYPENR(f->unireg_check) + == Field::NEXT_NUMBER)); if (!f->real_maybe_null() || (*af)->real_maybe_null()) goto next_column; /* We are changing an existing column @@ -2416,7 +2423,6 @@ innodb_instant_alter_column_allowed_reason: & ALTER_COLUMN_NOT_NULLABLE); /* Virtual columns are never NOT NULL. */ DBUG_ASSERT(f->stored_in_db()); - switch ((*af)->type()) { case MYSQL_TYPE_TIMESTAMP: case MYSQL_TYPE_TIMESTAMP2: @@ -2436,14 +2442,7 @@ innodb_instant_alter_column_allowed_reason: break; default: /* For any other data type, NULL - values are not converted. - (An AUTO_INCREMENT attribute cannot - be introduced to a column with - ALGORITHM=INPLACE.) */ - ut_ad((MTYP_TYPENR((*af)->unireg_check) - == Field::NEXT_NUMBER) - == (MTYP_TYPENR(f->unireg_check) - == Field::NEXT_NUMBER)); + values are not converted. */ goto next_column; }