Description:
When exporting/importing a tablespace using DISCARD/IMPORT TABLESPACE, the operation fails with ER_TABLE_SCHEMA_MISMATCH if:
1. The source table had an index with a prefix length that was the maximum prefix length for a column.
2. The index with the maximum prefix length was dropped before exporting.
The root cause is that dict_col_t::max_prefix (the maximum prefix length of a column across all indexes) is not updated when an index with the maximum prefix is dropped. This value is persisted in the .cfg file during FLUSH TABLES ... FOR EXPORT, causing a schema mismatch during import.
How to repeat:
create database src;
create database dst;
create table src.t1 (
`name` varchar(128),
KEY `name1` (`name`(8))
);
alter table src.t1 add index name2 (name(15));
alter table src.t1 drop index name2;
create table dst.t1 like src.t1;
alter table dst.t1 discard tablespace;
flush tables src.t1 for export;
--let $MYSQLD_DATADIR=`select @@datadir`
--copy_file $MYSQLD_DATADIR/src/t1.ibd $MYSQLD_DATADIR/dst/t1.ibd
--copy_file $MYSQLD_DATADIR/src/t1.cfg $MYSQLD_DATADIR/dst/t1.cfg
unlock tables;
# --error ER_TABLE_SCHEMA_MISMATCH
alter table dst.t1 import tablespace;
drop database src;
drop database dst;
Suggested fix:
Remove the validation of max_prefix during importing?