MDEV-30655 IMPORT TABLESPACE fails with column count or index count mismatch

Problem:
========
Currently import operation fails with schema mismatch when
cfg file has hidden fts document id and hidden fts document index.

Fix:
====
To fix this issue, simply add the fts doc id column,
indexes in table definition and try to import the table.
In case of success:
1) update the fts document id in sys columns.
2) update the number of columns in sys tables.
3) insert the new fts index entry in sys indexes table
and sys fields.
4) Reload the table with new table definition
parent 27b064d8
call mtr.add_suppression("InnoDB: Added system generated FTS_DOC_ID and FTS_DOC_ID_INDEX while importing the tablespace");
CREATE TABLE t1(f1 INT NOT NULL PRIMARY KEY,
f2 CHAR(2) not null, fulltext f_idx(f2),
f3 INT as (f1) VIRTUAL, INDEX(f3),
f4 INT as (f1) STORED, INDEX(f4),
f5 INT as (f1) VIRTUAL)ENGINE=InnoDB;
INSERT INTO t1(f1, f2) VALUES(1, "on");
INSERT INTO t1(f1, f2) SELECT seq, "si" FROM seq_2_to_256;
ALTER TABLE t1 ADD COLUMN f6 INT NOT NULL;
ALTER TABLE t1 DROP COLUMN f6;
ALTER TABLE t1 DROP INDEX f_idx;
connect con1,localhost,root,,;
START TRANSACTION WITH CONSISTENT SNAPSHOT;
connection default;
DELETE FROM t1 WHERE f1 > 1;
FLUSH TABLE t1 FOR EXPORT;
Warnings:
Warning 1235 This version of MariaDB doesn't yet support 'FLUSH TABLES on a table that had an FTS index, created on a hidden column, the auxiliary tables haven't been dropped as yet. FTS auxiliary tables will not be flushed.'
Warning 1235 This version of MariaDB doesn't yet support 'FLUSH TABLES on a table that had an FTS index, created on a hidden column, the auxiliary tables haven't been dropped as yet. FTS auxiliary tables will not be flushed.'
backup: t1
UNLOCK TABLES;
Warnings:
Warning 1235 This version of MariaDB doesn't yet support 'FLUSH TABLES on a table that had an FTS index, created on a hidden column, the auxiliary tables haven't been dropped as yet. FTS auxiliary tables will not be flushed.'
DROP TABLE t1;
CREATE TABLE t1(f1 INT NOT NULL PRIMARY KEY,
f2 CHAR(2) not null,
f3 INT as (f1) VIRTUAL, INDEX(f3),
f4 INT as (f1) STORED, INDEX(f4),
f5 INT as (f1) VIRTUAL)ENGINE=InnoDB;
ALTER TABLE t1 DISCARD TABLESPACE;
restore: t1 .ibd and .cfg files
ALTER TABLE t1 IMPORT TABLESPACE;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`f1` int(11) NOT NULL,
`f2` char(2) NOT NULL,
`f3` int(11) GENERATED ALWAYS AS (`f1`) VIRTUAL,
`f4` int(11) GENERATED ALWAYS AS (`f1`) STORED,
`f5` int(11) GENERATED ALWAYS AS (`f1`) VIRTUAL,
PRIMARY KEY (`f1`),
KEY `f3` (`f3`),
KEY `f4` (`f4`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
DROP TABLE t1;
CREATE TABLE t1(f1 INT NOT NULL PRIMARY KEY,
f2 CHAR(2) NOT NULL, FULLTEXT f_idx(f2),
f3 INT as (f1) VIRTUAL, INDEX(f3))ENGINE=InnoDB;
INSERT INTO t1(f1, f2) VALUES(1, "on");
ALTER TABLE t1 DROP INDEX f_idx;
FLUSH TABLE t1 FOR EXPORT;
Warnings:
Warning 1235 This version of MariaDB doesn't yet support 'FLUSH TABLES on a table that had an FTS index, created on a hidden column, the auxiliary tables haven't been dropped as yet. FTS auxiliary tables will not be flushed.'
Warning 1235 This version of MariaDB doesn't yet support 'FLUSH TABLES on a table that had an FTS index, created on a hidden column, the auxiliary tables haven't been dropped as yet. FTS auxiliary tables will not be flushed.'
backup: t1
UNLOCK TABLES;
Warnings:
Warning 1235 This version of MariaDB doesn't yet support 'FLUSH TABLES on a table that had an FTS index, created on a hidden column, the auxiliary tables haven't been dropped as yet. FTS auxiliary tables will not be flushed.'
DROP TABLE t1;
CREATE TABLE t1(f1 INT NOT NULL PRIMARY KEY,
f2 CHAR(2) NOT NULL,
f3 CHAR(2) NOT NULL,
f4 INT AS (f1) VIRTUAL, INDEX(f4))ENGINE=InnoDB;
ALTER TABLE t1 DISCARD TABLESPACE;
restore: t1 .ibd and .cfg files
ALTER TABLE t1 IMPORT TABLESPACE;
ERROR HY000: Schema mismatch (Number of indexes don't match, table has 2 indexes but the tablespace meta-data file has 3 indexes)
DROP TABLE t1;
CREATE TABLE t1(f1 INT NOT NULL PRIMARY KEY,
f2 CHAR(2) NOT NULL,
f3 INT as (f1) VIRTUAL, INDEX(f3))ENGINE=InnoDB;
ALTER TABLE t1 DISCARD TABLESPACE;
restore: t1 .ibd and .cfg files
SET DEBUG_DBUG="+d,ib_import_set_index_root_failure";
ALTER TABLE t1 IMPORT TABLESPACE;
ERROR HY000: Too many active concurrent transactions
SET DEBUG_DBUG="-d,ib_import_set_index_root_failure";
SET DEBUG_DBUG="+d,ib_import_vcol_update_fail";
ALTER TABLE t1 IMPORT TABLESPACE;
ERROR 23000: Can't write; duplicate key in table 't1'
SET DEBUG_DBUG="-d,ib_import_vcol_update_fail";
restore: t1 .ibd and .cfg files
SET DEBUG_DBUG="+d,ib_import_fts_error";
ALTER TABLE t1 IMPORT TABLESPACE;
ERROR 23000: Can't write; duplicate key in table 't1'
SET DEBUG_DBUG="-d,ib_import_fts_error";
unlink: t1.ibd
unlink: t1.cfg
SELECT NAME FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS
WHERE table_id IN (SELECT table_id FROM information_schema.innodb_sys_tables where name="test/t1");
NAME
f1
f2
f3
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`f1` int(11) NOT NULL,
`f2` char(2) NOT NULL,
`f3` int(11) GENERATED ALWAYS AS (`f1`) VIRTUAL,
PRIMARY KEY (`f1`),
KEY `f3` (`f3`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
DROP TABLE t1;
CREATE TABLE t1(f1 INT NOT NULL PRIMARY KEY,
FTS_DOC_ID BIGINT SIGNED NOT NULL,
f2 CHAR(2) NOT NULL,
FULLTEXT f_idx(f2))ENGINE=InnoDB;
INSERT INTO t1 VALUES(1, 1, "on");
ALTER TABLE t1 DROP INDEX f_idx;
FLUSH TABLE t1 FOR EXPORT;
backup: t1
UNLOCK TABLES;
DROP TABLE t1;
CREATE TABLE t1(f1 INT NOT NULL PRIMARY KEY,
f2 CHAR(2) NOT NULL)ENGINE=InnoDB;
ALTER TABLE t1 DISCARD TABLESPACE;
restore: t1 .ibd and .cfg files
ALTER TABLE t1 IMPORT TABLESPACE;
ERROR HY000: Schema mismatch (Column f2 ordinal value mismatch, it's at 1 in the table and 2 in the tablespace meta-data file)
DROP TABLE t1;
--source include/have_innodb.inc
--source include/have_sequence.inc
# Table with virtual, fulltext, instant add, instant drop column
# and purgeable rows
call mtr.add_suppression("InnoDB: Added system generated FTS_DOC_ID and FTS_DOC_ID_INDEX while importing the tablespace");
CREATE TABLE t1(f1 INT NOT NULL PRIMARY KEY,
f2 CHAR(2) not null, fulltext f_idx(f2),
f3 INT as (f1) VIRTUAL, INDEX(f3),
f4 INT as (f1) STORED, INDEX(f4),
f5 INT as (f1) VIRTUAL)ENGINE=InnoDB;
INSERT INTO t1(f1, f2) VALUES(1, "on");
INSERT INTO t1(f1, f2) SELECT seq, "si" FROM seq_2_to_256;
ALTER TABLE t1 ADD COLUMN f6 INT NOT NULL;
ALTER TABLE t1 DROP COLUMN f6;
ALTER TABLE t1 DROP INDEX f_idx;
connect(con1,localhost,root,,);
START TRANSACTION WITH CONSISTENT SNAPSHOT;
connection default;
DELETE FROM t1 WHERE f1 > 1;
FLUSH TABLE t1 FOR EXPORT;
let MYSQLD_DATADIR =`SELECT @@datadir`;
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_backup_tablespaces("test", "t1");
EOF
UNLOCK TABLES;
DROP TABLE t1;
CREATE TABLE t1(f1 INT NOT NULL PRIMARY KEY,
f2 CHAR(2) not null,
f3 INT as (f1) VIRTUAL, INDEX(f3),
f4 INT as (f1) STORED, INDEX(f4),
f5 INT as (f1) VIRTUAL)ENGINE=InnoDB;
ALTER TABLE t1 DISCARD TABLESPACE;
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_discard_tablespaces("test", "t1");
ib_restore_tablespaces("test", "t1");
EOF
--disable_warnings
ALTER TABLE t1 IMPORT TABLESPACE;
--enable_warnings
SHOW CREATE TABLE t1;
DROP TABLE t1;
--source include/have_innodb.inc
--source include/have_debug.inc
CREATE TABLE t1(f1 INT NOT NULL PRIMARY KEY,
f2 CHAR(2) NOT NULL, FULLTEXT f_idx(f2),
f3 INT as (f1) VIRTUAL, INDEX(f3))ENGINE=InnoDB;
INSERT INTO t1(f1, f2) VALUES(1, "on");
ALTER TABLE t1 DROP INDEX f_idx;
FLUSH TABLE t1 FOR EXPORT;
let MYSQLD_DATADIR =`SELECT @@datadir`;
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_backup_tablespaces("test", "t1");
EOF
UNLOCK TABLES;
DROP TABLE t1;
CREATE TABLE t1(f1 INT NOT NULL PRIMARY KEY,
f2 CHAR(2) NOT NULL,
f3 CHAR(2) NOT NULL,
f4 INT AS (f1) VIRTUAL, INDEX(f4))ENGINE=InnoDB;
ALTER TABLE t1 DISCARD TABLESPACE;
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_discard_tablespaces("test", "t1");
ib_restore_tablespaces("test", "t1");
EOF
--error ER_TABLE_SCHEMA_MISMATCH
ALTER TABLE t1 IMPORT TABLESPACE;
DROP TABLE t1;
CREATE TABLE t1(f1 INT NOT NULL PRIMARY KEY,
f2 CHAR(2) NOT NULL,
f3 INT as (f1) VIRTUAL, INDEX(f3))ENGINE=InnoDB;
ALTER TABLE t1 DISCARD TABLESPACE;
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_discard_tablespaces("test", "t1");
ib_restore_tablespaces("test", "t1");
EOF
--disable_warnings
SET DEBUG_DBUG="+d,ib_import_set_index_root_failure";
--error ER_TOO_MANY_CONCURRENT_TRXS
ALTER TABLE t1 IMPORT TABLESPACE;
SET DEBUG_DBUG="-d,ib_import_set_index_root_failure";
SET DEBUG_DBUG="+d,ib_import_vcol_update_fail";
--error ER_DUP_KEY
ALTER TABLE t1 IMPORT TABLESPACE;
SET DEBUG_DBUG="-d,ib_import_vcol_update_fail";
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_discard_tablespaces("test", "t1");
ib_restore_tablespaces("test", "t1");
EOF
SET DEBUG_DBUG="+d,ib_import_fts_error";
--error ER_DUP_KEY
ALTER TABLE t1 IMPORT TABLESPACE;
SET DEBUG_DBUG="-d,ib_import_fts_error";
--enable_warnings
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_unlink_tablespace("test", "t1");
EOF
SELECT NAME FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS
WHERE table_id IN (SELECT table_id FROM information_schema.innodb_sys_tables where name="test/t1");
SHOW CREATE TABLE t1;
DROP TABLE t1;
# Manually add the FTS_DOC_ID Column with mismatched data type
CREATE TABLE t1(f1 INT NOT NULL PRIMARY KEY,
FTS_DOC_ID BIGINT SIGNED NOT NULL,
f2 CHAR(2) NOT NULL,
FULLTEXT f_idx(f2))ENGINE=InnoDB;
INSERT INTO t1 VALUES(1, 1, "on");
ALTER TABLE t1 DROP INDEX f_idx;
FLUSH TABLE t1 FOR EXPORT;
let MYSQLD_DATADIR =`SELECT @@datadir`;
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_backup_tablespaces("test", "t1");
EOF
UNLOCK TABLES;
DROP TABLE t1;
CREATE TABLE t1(f1 INT NOT NULL PRIMARY KEY,
f2 CHAR(2) NOT NULL)ENGINE=InnoDB;
ALTER TABLE t1 DISCARD TABLESPACE;
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_discard_tablespaces("test", "t1");
ib_restore_tablespaces("test", "t1");
EOF
--error ER_TABLE_SCHEMA_MISMATCH
ALTER TABLE t1 IMPORT TABLESPACE;
DROP TABLE t1;
This diff is collapsed.
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