summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2021-07-23 16:33:14 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2021-07-23 16:33:14 +0300
commit1fb71c7831c9d8d216873e48ca106ca38a4e975b (patch)
tree4dfc329b05150af4b22f97cbf02a84a608f83630
parent0604592a855a9c1f33e99552817047271aa4aae0 (diff)
downloadmariadb-git-1fb71c7831c9d8d216873e48ca106ca38a4e975b.tar.gz
MDEV-19272: Assertion unireg_check..Field::NEXT_NUMBER failed
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 8dffaaef72feaeb06fe82c7fec9c3f6c509804fb (MDEV-12836).
-rw-r--r--mysql-test/suite/innodb/r/alter_table.result10
-rw-r--r--mysql-test/suite/innodb/t/alter_table.test11
-rw-r--r--storage/innobase/handler/handler0alter.cc17
3 files changed, 29 insertions, 9 deletions
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
@@ -110,6 +110,17 @@ 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;
}