Skip to content

Commit

Permalink
MDEV-19272: Assertion unireg_check..Field::NEXT_NUMBER failed
Browse files Browse the repository at this point in the history
ha_innobase::check_if_supported_inplace_alter(): Relax a too strict
debug assertion when changing a column from NULL to NOT NULL.
InnoDB actually allows instant removal of an AUTO_INCREMENT attribute
since commit 8dffaae (MDEV-12836).
  • Loading branch information
dr-m committed Jul 23, 2021
1 parent 0604592 commit 1fb71c7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
10 changes: 10 additions & 0 deletions mysql-test/suite/innodb/r/alter_table.result
Expand Up @@ -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
#
11 changes: 11 additions & 0 deletions mysql-test/suite/innodb/t/alter_table.test
Expand Up @@ -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 #
Expand Down
17 changes: 8 additions & 9 deletions storage/innobase/handler/handler0alter.cc
Expand Up @@ -2408,6 +2408,13 @@ ha_innobase::check_if_supported_inplace_alter(
& 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
Expand All @@ -2416,7 +2423,6 @@ ha_innobase::check_if_supported_inplace_alter(
& 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:
Expand All @@ -2436,14 +2442,7 @@ ha_innobase::check_if_supported_inplace_alter(
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;
}

Expand Down

0 comments on commit 1fb71c7

Please sign in to comment.