Bug #105301 Specific table schema causes table to become corrupted during MySQL 8 upgrade
Submitted: 22 Oct 2021 17:24 Modified: 13 Jun 22:00
Reporter: Ralf Meyer Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Data Dictionary Severity:S2 (Serious)
Version:8.0.27 OS:Linux
Assigned to: CPU Architecture:Any
Tags: corruption, mysql8, upgrade

[22 Oct 2021 17:24] Ralf Meyer
Description:
Tested on Debian 10 with MySQL packages from the official MySQL-Repos.

If a specific table schema is used, upgrading the table to MySQL 8 fails. The table is broken / corrupted after the upgrade has finished, cannot be successfully repaired and due to the nature of the upgrade to version 8, downgrading is not possible anymore (the issue happens after the data directory has been successfully upgraded).

In my small test case, the issue did not cause the MySQL upgrade to fail completely. On a larger scale with several hundreds of databases on a server however, the upgrade failed due to this issue, still the data directory was already upgraded, so no downgrade possible. I cannot say why the upgrade is failing in some cases and not in others.

The error on a larger database server, where the upgrade completely fails due to this:

"[...]
2021-10-22T13:49:00.223101Z 5 [Note] [MY-013394] [Server] Checking 'somedb01' schema.
2021-10-22T13:49:00.223532Z 5 [Note] [MY-013394] [Server] Checking 'somedb02' schema.
2021-10-22T13:49:00.279648Z 5 [Note] [MY-013394] [Server] Checking 'somedb03' schema.
2021-10-22T13:49:00.346179Z 5 [Note] [MY-013394] [Server] Checking 'affecteddb' schema.
2021-10-22T13:49:00.526075Z 5 [Warning] [MY-013382] [Server] Table 'affecteddb.brokentable1' requires repair.
2021-10-22T13:49:00.526192Z 5 [Warning] [MY-013382] [Server] Table 'affecteddb.brokentable2' requires repair.
2021-10-22T13:49:00.526241Z 5 [Note] [MY-013394] [Server] Checking 'somedb04' schema.
2021-10-22T13:49:00.580142Z 5 [Note] [MY-013394] [Server] Checking 'somedb05' schema.
2021-10-22T13:49:00.629512Z 5 [Note] [MY-013394] [Server] Checking 'somedb06' schema.
[...] (No other errors logged) [...]
2021-10-22T13:49:23.890729Z 5 [Note] [MY-013394] [Server] Checking 'sys' schema.
2021-10-22T13:49:23.939738Z 0 [ERROR] [MY-013380] [Server] Failed to upgrade server.
2021-10-22T13:49:23.943780Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-10-22T13:49:23.973041Z 0 [Note] [MY-012330] [InnoDB] FTS optimize thread exiting.
2021-10-22T13:49:24.593534Z 0 [Note] [MY-010120] [Server] Binlog end"

On a smaller server with my test case, the upgrade finishes, but the affected table is not accessible afterwards:

"[...]
2021-10-22T16:32:03.334727Z 2 [System] [MY-011003] [Server] Finished populating Data Dictionary tables with data.
2021-10-22T16:32:03.337033Z 2 [Note] [MY-011008] [Server] Finished migrating TABLE statistics data.
2021-10-22T16:32:03.338443Z 2 [Note] [MY-011008] [Server] Finished migrating TABLE statistics data.
2021-10-22T16:32:03.473588Z 2 [Note] [MY-010006] [Server] Using data dictionary with version '80023'.
2021-10-22T16:32:03.743236Z 5 [System] [MY-013381] [Server] Server upgrade from '50700' to '80027' started.
2021-10-22T16:32:03.744893Z 5 [Note] [MY-013386] [Server] Running queries to upgrade MySQL server.
2021-10-22T16:32:05.620225Z 5 [Note] [MY-013387] [Server] Upgrading system table data.
2021-10-22T16:32:05.885157Z 5 [Note] [MY-013385] [Server] Upgrading the sys schema.
2021-10-22T16:32:06.175655Z 5 [Note] [MY-013400] [Server] Upgrade of help tables started.
2021-10-22T16:32:06.273083Z 5 [Note] [MY-013400] [Server] Upgrade of help tables completed.
2021-10-22T16:32:06.273223Z 5 [Note] [MY-013394] [Server] Checking 'mysql' schema.
2021-10-22T16:32:06.342338Z 5 [Note] [MY-013394] [Server] Checking 'sys' schema.
2021-10-22T16:32:06.356299Z 5 [Note] [MY-013394] [Server] Checking 'testdb' schema.
2021-10-22T16:32:06.357376Z 5 [Warning] [MY-013382] [Server] Table 'testdb.testTable1' requires repair.
2021-10-22T16:32:06.357601Z 5 [ERROR] [MY-013383] [Server] Table 'testdb.testTable1' repair failed.
2021-10-22T16:32:06.360602Z 5 [System] [MY-013381] [Server] Server upgrade from '50700' to '80027' completed.
[...] (Server then normally starts, table testdb.testTable1 is broken) [...]"

From my test case:

Before the upgrade:

Server version: 5.7.36 MySQL Community Server (GPL)

[...]

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| testdb             |
+--------------------+
5 rows in set (0.01 sec)

mysql> SELECT * FROM testdb.testTable1;
Empty set (0.00 sec)

mysql> USE testdb;
[...]
Database changed

mysql> CHECK TABLE testTable1;
+-------------------+-------+----------+----------+
| Table             | Op    | Msg_type | Msg_text |
+-------------------+-------+----------+----------+
| testdb.testTable1 | check | status   | OK       |
+-------------------+-------+----------+----------+
1 row in set (0.00 sec)

After the upgrade:

Server version: 8.0.27 MySQL Community Server - GPL

[...]

mysql> USE testdb;
[...]
Database changed

mysql> SELECT * from testTable1;
ERROR 1034 (HY000): Incorrect key file for table 'testTable1'; try to repair it

mysql> REPAIR TABLE testTable1;
+-------------------+--------+----------+-------------------------------------------------------------+
| Table             | Op     | Msg_type | Msg_text                                                    |
+-------------------+--------+----------+-------------------------------------------------------------+
| testdb.testTable1 | repair | Error    | Incorrect key file for table 'testTable1'; try to repair it |
| testdb.testTable1 | repair | error    | Corrupt                                                     |
+-------------------+--------+----------+-------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql> REPAIR TABLE testTable1 USE_FRM;
+-------------------+--------+----------+------------------+
| Table             | Op     | Msg_type | Msg_text         |
+-------------------+--------+----------+------------------+
| testdb.testTable1 | repair | Warning  | Can't open table |
| testdb.testTable1 | repair | error    | Corrupt          |
+-------------------+--------+----------+------------------+
2 rows in set (0.00 sec)

How to repeat:
I have provided a sql dump for a test case as an attachment. I have tried this on Debian 10 going from MySQL 5.7.36 -> 8.0.27, but I assume it will also happen on other (Linux) distributions.

Import it into MySQL 5. The table is working correctly, as shown above. Then upgrade to MySQL 8. The table is now corrupted and it is not possible to repair / downgrade anymore.
[22 Oct 2021 17:25] Ralf Meyer
Test case sql dump for reproducing the issue.

Attachment: testcase.sql (application/sql, text), 733 bytes.

[25 Oct 2021 13:18] MySQL Verification Team
Hello Ralf Meyer,

Thank you for the report and feedback.
Verified as described.

regards,
Umesh
[25 Oct 2021 13:23] MySQL Verification Team
MySQL server upgrade from 5.7.36 to 8.0.27 test results

Attachment: 105301_8.0.27.results (application/octet-stream, text), 25.98 KiB.

[13 Dec 2021 7:17] Nischal Tonthanahal
Posted by developer:
 
Verified 2nd scenario where table is corrupted.
Minimal test case to reproduce the issue:

CREATE TABLE `testTable1` (
  `c1` int GENERATED ALWAYS AS (0),
  `c2` int
) ENGINE=MyISAM;
[13 Jun 22:00] Jon Stephens
Documented fix as follows in the MySQL 8.0.38, 8.4.1, and 9.0.0 changelogs:

    Attempting to upgrade a MyISAM table containing a mix of regular
    columns and generated columns from MySQL 5.7 to 8.0 or later led
    to table corruption.

Closed.