From 7b492d6a70b78ad811cb5e81e1684f1b8e454690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 23 Aug 2021 09:13:55 +0300 Subject: [PATCH] MDEV-26458 Crash on ALTER TABLE after DISCARD TABLESPACE ha_innobase::check_if_supported_inplace_alter(): Do not invoke innobase_table_is_empty() if the tablespace has been discarded. That is, native ALTER TABLE in InnoDB will treat an empty table in the same way as a tablespace whose tablespace has been discarded. (Note: ALTER TABLE...ALGORITHM=COPY will fail if the tablespace has been discarded.) This fixes a crash that was introduced in commit c755974775a7a7f4fc24abeacd2fc9ea7bf0c247 (MDEV-19611). --- .../suite/innodb/r/innodb-alter-timestamp.result | 12 ++++++++++++ .../suite/innodb/t/innodb-alter-timestamp.test | 12 ++++++++++++ storage/innobase/handler/handler0alter.cc | 1 + 3 files changed, 25 insertions(+) diff --git a/mysql-test/suite/innodb/r/innodb-alter-timestamp.result b/mysql-test/suite/innodb/r/innodb-alter-timestamp.result index 6934484a488..280ab3ebee4 100644 --- a/mysql-test/suite/innodb/r/innodb-alter-timestamp.result +++ b/mysql-test/suite/innodb/r/innodb-alter-timestamp.result @@ -139,3 +139,15 @@ ALTER TABLE t1 ADD f3 DATE NOT NULL, ALGORITHM=INPLACE; ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY DROP TABLE t1; disconnect purge_control; +# +# MDEV-26458 SIGSEGV in innobase_table_is_empty() on ALTER TABLE +# +CREATE TABLE t(a INT PRIMARY KEY) ENGINE=InnoDB; +ALTER TABLE t DISCARD TABLESPACE; +SET sql_mode='NO_ZERO_DATE'; +ALTER TABLE t ADD c DATE NOT NULL; +Warnings: +Warning 1814 Tablespace has been discarded for table `t` +SET sql_mode=DEFAULT; +DROP TABLE t; +# End of 10.3 tests diff --git a/mysql-test/suite/innodb/t/innodb-alter-timestamp.test b/mysql-test/suite/innodb/t/innodb-alter-timestamp.test index 28b09b18e10..e1c263dc5d0 100644 --- a/mysql-test/suite/innodb/t/innodb-alter-timestamp.test +++ b/mysql-test/suite/innodb/t/innodb-alter-timestamp.test @@ -103,3 +103,15 @@ INSERT INTO t1 VALUES (1, now()); ALTER TABLE t1 ADD f3 DATE NOT NULL, ALGORITHM=INPLACE; DROP TABLE t1; disconnect purge_control; + +--echo # +--echo # MDEV-26458 SIGSEGV in innobase_table_is_empty() on ALTER TABLE +--echo # +CREATE TABLE t(a INT PRIMARY KEY) ENGINE=InnoDB; +ALTER TABLE t DISCARD TABLESPACE; +SET sql_mode='NO_ZERO_DATE'; +ALTER TABLE t ADD c DATE NOT NULL; +SET sql_mode=DEFAULT; +DROP TABLE t; + +--echo # End of 10.3 tests diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index ff7c355f2dd..8418ad7316c 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -1164,6 +1164,7 @@ ha_innobase::check_if_supported_inplace_alter( /* '0000-00-00' value isn't allowed for datetime datatype for newly added column when table is not empty */ if (ha_alter_info->error_if_not_empty + && m_prebuilt->table->space && !innobase_table_is_empty(m_prebuilt->table)) { DBUG_RETURN(HA_ALTER_INPLACE_NOT_SUPPORTED); }