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.
parent ec9908b2
...@@ -169,4 +169,36 @@ DROP FOREIGN KEY fk1, ...@@ -169,4 +169,36 @@ DROP FOREIGN KEY fk1,
CHANGE b d INT UNSIGNED, CHANGE b d INT UNSIGNED,
ADD c INT; ADD c INT;
DROP TABLE t2, t1; 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 # End of 10.3 tests
...@@ -170,4 +170,38 @@ ALTER TABLE t2 ...@@ -170,4 +170,38 @@ ALTER TABLE t2
ADD c INT; ADD c INT;
DROP TABLE t2, t1; 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 --echo # End of 10.3 tests
...@@ -4441,6 +4441,13 @@ innobase_add_instant_try( ...@@ -4441,6 +4441,13 @@ innobase_add_instant_try(
return true; 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; unsigned i = unsigned(user_table->n_cols) - DATA_N_SYS_COLS;
byte trx_id[DATA_TRX_ID_LEN], roll_ptr[DATA_ROLL_PTR_LEN]; 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, dfield_set_data(dtuple_get_nth_field(row, i++), field_ref_zero,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment