diff options
author | Thirunarayanan Balathandayuthapani <thiru@mariadb.com> | 2020-05-04 15:27:24 +0530 |
---|---|---|
committer | Thirunarayanan Balathandayuthapani <thiru@mariadb.com> | 2020-05-04 16:23:34 +0530 |
commit | 42bba9782b36247c6c2241ea4d5996723af273fd (patch) | |
tree | 131c5e233fb4d568854d48bb8bd46f484224f33b | |
parent | ec9908b2577758ffb3cb0d1b06400f12ff47b81c (diff) | |
download | mariadb-git-42bba9782b36247c6c2241ea4d5996723af273fd.tar.gz |
MDEV-22446 InnoDB aborts while adding instant column for discarded tablespace
- Instant alter should change the metadata alone when table is
discarded. It shouldn't try to add metadata record in clustered index.
Also make the clustered index to non-instant format.
-rw-r--r-- | mysql-test/suite/innodb/r/instant_alter_bugs.result | 32 | ||||
-rw-r--r-- | mysql-test/suite/innodb/t/instant_alter_bugs.test | 34 | ||||
-rw-r--r-- | storage/innobase/handler/handler0alter.cc | 7 |
3 files changed, 73 insertions, 0 deletions
diff --git a/mysql-test/suite/innodb/r/instant_alter_bugs.result b/mysql-test/suite/innodb/r/instant_alter_bugs.result index d07067fa19f..7b658df6565 100644 --- a/mysql-test/suite/innodb/r/instant_alter_bugs.result +++ b/mysql-test/suite/innodb/r/instant_alter_bugs.result @@ -169,4 +169,36 @@ DROP FOREIGN KEY fk1, CHANGE b d INT UNSIGNED, ADD c INT; DROP TABLE t2, t1; +# +# MDEV-22446 InnoDB aborts while adding instant column +# for discarded tablespace +# +CREATE TABLE t1(c1 INT NOT NULL, c2 INT NOT NULL DEFAULT 0)ENGINE=InnoDB; +INSERT INTO t1(c1) VALUES(1); +ALTER TABLE t1 ADD COLUMN c3 INT DEFAULT 10; +FLUSH TABLES t1 FOR EXPORT; +backup: t1 +UNLOCK TABLES; +DROP TABLE t1; +CREATE TABLE t1(c1 INT NOT NULL)Engine=InnoDB; +ALTER TABLE t1 DISCARD TABLESPACE; +ALTER TABLE t1 ADD COLUMN c2 INT NOT NULL; +Warnings: +Warning 1814 Tablespace has been discarded for table `t1` +ALTER TABLE t1 ADD COLUMN c3 INT DEFAULT 10; +Warnings: +Warning 1814 Tablespace has been discarded for table `t1` +restore: t1 .ibd and .cfg files +ALTER TABLE t1 IMPORT TABLESPACE; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` int(11) NOT NULL, + `c2` int(11) NOT NULL, + `c3` int(11) DEFAULT 10 +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +SELECT * FROM t1; +c1 c2 c3 +1 0 10 +DROP TABLE t1; # End of 10.3 tests diff --git a/mysql-test/suite/innodb/t/instant_alter_bugs.test b/mysql-test/suite/innodb/t/instant_alter_bugs.test index a2626ba34a1..a7ccefb19af 100644 --- a/mysql-test/suite/innodb/t/instant_alter_bugs.test +++ b/mysql-test/suite/innodb/t/instant_alter_bugs.test @@ -170,4 +170,38 @@ ALTER TABLE t2 ADD c INT; DROP TABLE t2, t1; +--echo # +--echo # MDEV-22446 InnoDB aborts while adding instant column +--echo # for discarded tablespace +--echo # + +let MYSQLD_DATADIR =`SELECT @@datadir`; +CREATE TABLE t1(c1 INT NOT NULL, c2 INT NOT NULL DEFAULT 0)ENGINE=InnoDB; +INSERT INTO t1(c1) VALUES(1); + +ALTER TABLE t1 ADD COLUMN c3 INT DEFAULT 10; +--replace_regex /, .*\).*t1.cfg/, Bad file descriptor) t1.cfg/ +FLUSH TABLES t1 FOR EXPORT; + +perl; +do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl"; +ib_backup_tablespaces("test", "t1"); +EOF +UNLOCK TABLES; +DROP TABLE t1; + +# Restore of instant table +CREATE TABLE t1(c1 INT NOT NULL)Engine=InnoDB; +ALTER TABLE t1 DISCARD TABLESPACE; +ALTER TABLE t1 ADD COLUMN c2 INT NOT NULL; +ALTER TABLE t1 ADD COLUMN c3 INT DEFAULT 10; +# Restore files +perl; +do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl"; +ib_restore_tablespaces("test", "t1"); +EOF +ALTER TABLE t1 IMPORT TABLESPACE; +SHOW CREATE TABLE t1; +SELECT * FROM t1; +DROP TABLE t1; --echo # End of 10.3 tests diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 0686c21c711..020b3954c95 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -4441,6 +4441,13 @@ innobase_add_instant_try( return true; } + /* If the table has been discarded then change the metadata alone + and make the index to non-instant format */ + if (!user_table->space) { + index->remove_instant(); + return false; + } + unsigned i = unsigned(user_table->n_cols) - DATA_N_SYS_COLS; byte trx_id[DATA_TRX_ID_LEN], roll_ptr[DATA_ROLL_PTR_LEN]; dfield_set_data(dtuple_get_nth_field(row, i++), field_ref_zero, |