diff --git a/mysql-test/suite/innodb/r/import_bugs.result b/mysql-test/suite/innodb/r/import_bugs.result index 82942e85301..f62c3ee4279 100644 --- a/mysql-test/suite/innodb/r/import_bugs.result +++ b/mysql-test/suite/innodb/r/import_bugs.result @@ -61,4 +61,30 @@ id 4 5 DROP TABLE t2; +# +# MDEV-34181 Instant table aborts after discard tablespace +# +CREATE TABLE t1(c3 INT, c2 INT, c1 INT KEY)ENGINE=InnoDB; +INSERT INTO t1 VALUES(1, 1, 1), (2, 2, 2); +CREATE TABLE t2 (c1 INT KEY) ENGINE=InnoDB; +INSERT INTO t2 VALUES(1); +ALTER TABLE t2 ADD c2 INT; +FLUSH TABLES t1 FOR EXPORT; +UNLOCK TABLES; +ALTER TABLE t2 DISCARD TABLESPACE; +ALTER TABLE t2 ADD c3 INT FIRST; +Warnings: +Warning 1814 Tablespace has been discarded for table `t2` +ALTER TABLE t2 IMPORT TABLESPACE; +Warnings: +Warning 1810 IO Read error: (2, No such file or directory) Error opening './test/t2.cfg', will attempt to import without schema verification +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `c3` int(11) DEFAULT NULL, + `c1` int(11) NOT NULL, + `c2` int(11) DEFAULT NULL, + PRIMARY KEY (`c1`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2, t1; # End of 10.5 tests diff --git a/mysql-test/suite/innodb/t/import_bugs.test b/mysql-test/suite/innodb/t/import_bugs.test index d9c5b6b1d89..5c9fdc602fd 100644 --- a/mysql-test/suite/innodb/t/import_bugs.test +++ b/mysql-test/suite/innodb/t/import_bugs.test @@ -78,4 +78,24 @@ INSERT INTO t2() VALUES(); SELECT * FROM t2 ORDER BY id; DROP TABLE t2; +--echo # +--echo # MDEV-34181 Instant table aborts after discard tablespace +--echo # +CREATE TABLE t1(c3 INT, c2 INT, c1 INT KEY)ENGINE=InnoDB; +INSERT INTO t1 VALUES(1, 1, 1), (2, 2, 2); +CREATE TABLE t2 (c1 INT KEY) ENGINE=InnoDB; +INSERT INTO t2 VALUES(1); +ALTER TABLE t2 ADD c2 INT; +FLUSH TABLES t1 FOR EXPORT; +let $datadir=`select @@datadir`; +--copy_file $datadir/test/t1.ibd $datadir/test/imp_t1.ibd +UNLOCK TABLES; +ALTER TABLE t2 DISCARD TABLESPACE; +ALTER TABLE t2 ADD c3 INT FIRST; +--copy_file $datadir/test/imp_t1.ibd $datadir/test/t2.ibd + +--replace_regex /opening '.*\/test\//opening '.\/test\// +ALTER TABLE t2 IMPORT TABLESPACE; +SHOW CREATE TABLE t2; +DROP TABLE t2, t1; --echo # End of 10.5 tests diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 79024177125..b5a76bfcdc2 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -374,10 +374,12 @@ found_j: } } - /* In case of discarded tablespace, InnoDB can't - read the root page. So assign the null bytes based - on nullabled fields */ - if (!oindex.table->space) { + /* Discard tablespace doesn't remove the instantness + from the table definition. if n_core_null_bytes wasn't + initialized then assign it based on nullable fields */ + if (!oindex.table->space + && oindex.n_core_null_bytes + == dict_index_t::NO_CORE_NULL_BYTES) { oindex.n_core_null_bytes = static_cast( UT_BITS_IN_BYTES(unsigned(oindex.n_nullable))); }