Import Table:Error: during importing table from 8.0.19 to 8.0.34

Hi,
Recently, when I did ‘sqlsmith’ random data testing for importing table. I found there is a ‘Index corrupt’ error when try to import table from 8.0.19 to 8.0.34.

[Issue]
The table has instant_add_col, the testing case is:
source node is 8.0.19.
mysql> select @@version;
±----------+
| @@version |
±----------+
| 8.0.19-10 |
±----------+
1 row in set (0.00 sec)

##create a base table
create database test;use test;
CREATE TABLE t1 (
wtfcl int DEFAULT ‘1566498914’,
id int NOT NULL AUTO_INCREMENT,
hebcxxwva decimal(26,7) DEFAULT NULL,
cgthpdcr datetime DEFAULT NULL,
wxpxct text COLLATE utf8mb4_bin,
sourjp text COLLATE utf8mb4_bin NOT NULL,
ljynqyb varchar(65) COLLATE utf8mb4_bin DEFAULT ‘stcvhbwjfclilvbadxhalrgqdgtbftwzfmxzkepjopomtyardbugribynpatvahrs’,
rnaifijo varchar(1090) COLLATE utf8mb4_bin DEFAULT NULL,
cdnorxdzg decimal(17,6) NOT NULL DEFAULT ‘0.000000’,
sjlgrwnyk int DEFAULT NULL,
uuid varchar(253) COLLATE utf8mb4_bin DEFAULT NULL,
cczlur datetime NOT NULL DEFAULT ‘2001-12-30 05:40:31’,
qozecnqhj varchar(1508) COLLATE utf8mb4_bin DEFAULT NULL,
axaqfzhym varchar(358) COLLATE utf8mb4_bin NOT NULL DEFAULT ‘EJQFATPLZRWVIY’,
ehons int DEFAULT ‘216839066’,
ydiybwo int NOT NULL DEFAULT ‘1413713835’,
alfzkkmbq int DEFAULT ‘1670056804’,
PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

##insert record
insert into t1 values(1622753879,8,90.0681000,‘2068-08-03 21:11:19’,‘oVE^IFe%%RU-@fX{x6m’,‘r]"9&/)%0’,‘UFYQ^aVOYoFb:z"/ioKcX?1|?@uu>aHTHn1plo~^dfV&8ZF(6hF{AX=)\I~x4*','z-).d)20cY-\/uz{-:^_E*T8!3R',74.167600,700723041,'j5!p0Nb;:E*sVw=HM"lK{OeeVL32ui@I:Lc%L@|4@i^qY)SJhcOi^a)cT])@-Ltdl{LO]x’,‘2093-06-15 16:32:30’,‘Ng{Zy=$M=]\47F2k$H#0>&Y&)D[jQjsy<xWo$HKclG9\FB`M`{Q+1vM!<}YMwU!h+YLn0Z}Jlb97A[ag\cXE7’,‘ASz^,fL&bEvZ4$vtYqhED+U=:e(h=0!`LLG2XA+m;ab’,114591117,200385570,1068203744);

##instant_add col
alter table t1 add columnkkanp datetime DEFAULT NULL, ALGORITHM=INSTANT;

##flush table and get cfg
flush tables t1 for export;

dest node is 8.0.34.
mysql> select @@version;
±----------+
| @@version |
±----------+
| 8.0.34-26 |
±----------+
1 row in set (0.00 sec)

##create table on dest node and discard it, note: new table has col ‘kkanp’ which is an instant_add_col of origin table.
CREATE TABLE t1 (
wtfcl int DEFAULT ‘1566498914’,
id int NOT NULL AUTO_INCREMENT,
hebcxxwva decimal(26,7) DEFAULT NULL,
cgthpdcr datetime DEFAULT NULL,
wxpxct text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin,
sourjp text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
ljynqyb varchar(65) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT ‘stcvhbwjfclilvbadxhalrgqdgtbftwzfmxzkepjopomtyardbugribynpatvahrs’,
rnaifijo varchar(1090) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL,
cdnorxdzg decimal(17,6) NOT NULL DEFAULT ‘0.000000’,
sjlgrwnyk int DEFAULT NULL,
uuid varchar(253) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL,
cczlur datetime NOT NULL DEFAULT ‘2001-12-30 05:40:31’,
qozecnqhj varchar(1508) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL,
axaqfzhym varchar(358) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT ‘EJQFATPLZRWVIY’,
ehons int DEFAULT ‘216839066’,
ydiybwo int NOT NULL DEFAULT ‘1413713835’,
alfzkkmbq int DEFAULT ‘1670056804’,
kkanp datetime DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

alter table t1 discard tablespace;

##copy the ‘t1.ibd’ and ‘t1.cfg’ to the datadir of dest node and import table
alter table t1 import tablespace;

then, an error occurs:
mysql> alter table t1 import tablespace;
ERROR 1817 (HY000): Index corrupt: Clustered index validation failed, due to data file corruption.

[Analysis]
For debug version, I can get a coredump at:
Assertion failure: rec.h:649:n_null.
n_null of func ‘rec_init_offsets_comp_ordinary’ is given by ‘index->get_nullable_before_instant_add_drop()’. So I think this bug is related to the value of n_instant_nullable of the first index of table.

The table->first_index->n_instant_nullable will be set to cfg.m_n_instant_nullable during importing (func: row_import::set_instant_info). And cfg.m_n_instant_nullable is set only when cfg version equal or larger than ‘IB_EXPORT_CFG_VERSION_V5’. As the cfg version of 8.0.19 is IB_EXPORT_CFG_VERSION_V4, so the cfg.m_n_instant_nullable is set to 0, which cause the index corrpution error in the end.

[Possible Solution]
The solution is simple, as we can get the default_value of each instant_col during row_import_read_default_values, we can get the n_nullable_of_instant_col. And the n_nullable is the number total nullable col of new table. The correct cfg.m_n_instant_nullable should be: n_nullable of new table minus n_nullable_of_instant_col.

Hello @shawn_chen,
MySQL’s INSTANT ALTER has had troubled issues. In fact, 8.0.29 is not even downloadable due to an extreme data-loss bug with INSTANT. It is therefore not recommended, (might not even be supported) to import a tablespace which used INSTANT from before 8.0.30 (version the bug was fixed).

1 Like