Bug #115631 Upgrading from 8.0.20 to 8.0.28 corrupts a db table with a check constraint!
Submitted: 17 Jul 2024 13:15 Modified: 17 Jul 2024 14:13
Reporter: Dmitry Zenovich Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:8.0.28 OS:Any
Assigned to: CPU Architecture:Any

[17 Jul 2024 13:15] Dmitry Zenovich
Description:
Upgrading from 8.0.20 to 8.0.28 makes tables containing a check constraint calling regexp_like() with parameters of incompatible charsets inaccessible (the table is shown by 'show tables', but it's impossible to select data from the table, repair the table, alter the table, or delete the table).

Besides fixing the bug, please let me know if there is a way to get access to the data (in my real table there is much more columns than listed in "How to repeat" scenario and real data that I would like to restore).

How to repeat:
1. On 8.0.20 create a table

CREATE TABLE `t` (
  `custom_prefix` varchar(14) NOT NULL,
  CONSTRAINT `ck_t_custom_prefix` CHECK (regexp_like(cast(`custom_prefix` as char charset binary),_utf8mb4'^[a-z0-9-]+$'))
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

2. Upgrade to 8.0.28.
3.

mysql> select * from `t`;
ERROR 3995 (HY000): Character set 'binary' cannot be used in conjunction with 'utf8mb4_0900_ai_ci' in call to regexp_like.
mysql> ALTER TABLE `t` DROP CHECK `ck_t_custom_prefix`;
ERROR 3995 (HY000): Character set 'binary' cannot be used in conjunction with 'utf8mb4_0900_ai_ci' in call to regexp_like.
mysql> show create table `t`;
ERROR 3995 (HY000): Character set 'binary' cannot be used in conjunction with 'utf8mb4_0900_ai_ci' in call to regexp_like.
mysql> drop table `t`;
ERROR 3995 (HY000): Character set 'binary' cannot be used in conjunction with 'utf8mb4_0900_ai_ci' in call to regexp_like.

Suggested fix:
Probably the MySQL server should fail on upgrading DBs with such tables keeping the DBs unchanged.
[17 Jul 2024 14:13] MySQL Verification Team
Please do not submit the same bug more than once. An existing bug report already describes this very problem. Even if you feel that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments to the original bug instead.

Thank you for your interest in MySQL.