Bug #110018 MySQL crash recovery too slow when instance has too many tables
Submitted: 10 Feb 2023 7:25 Modified: 10 Feb 2023 9:35
Reporter: xiaoyu bai Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S3 (Non-critical)
Version:5.7.29 OS:Any
Assigned to: CPU Architecture:Any

[10 Feb 2023 7:25] xiaoyu bai
Description:
When MySQL instance has too many tables(663958), when mysql start from crash,it will take very long time. Below is the log from my env.
It takes about 8 minute after output binlog file position.

2023-02-10T03:10:14.318686Z 0 [Note] InnoDB: Last MySQL binlog file position 0 704652105, file name mysql-bin.004248
2023-02-10T03:18:00.657774Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2023-02-10T03:18:00.657826Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables

How to repeat:
Create about 663958 tables in mysql. crash mysql then start.

Suggested fix:
1 When i read cod, the following code show validate_to_dd executed 3 times, is it possible before execute validate_to_dd, first judge whether they point to same file, then can execute validate_to_dd 1 time.

/* Read and validate the first page of these three tablespace
    locations, if found. */
valid_tablespaces_found +=
(df_remote.validate_to_dd(id, flags, for_import)
== DB_SUCCESS) ? 1 : 0;
valid_tablespaces_found +=
(df_default.validate_to_dd(id, flags, for_import)
== DB_SUCCESS) ? 1 : 0;
valid_tablespaces_found +=
(df_dict.validate_to_dd(id, flags, for_import)
== DB_SUCCESS) ? 1 : 0;

2 Is it possible execute validate in parallel based on db level?
[10 Feb 2023 9:35] MySQL Verification Team
Hello xiaoyu bai,

Thank you for the report and feedback.
IMHO this is duplicate of Bug #84025, please see Bug #84025
Also, MySQL 5.7.29 (2020-01-13, General Availability) is very old and many bugs fixed since then and thus we recommend upgrading to 8.0.32.  MySQL 5.7 will be EOL this year (Oct 2023). 

Related - Bug #96340, Bug #103743 which are fixed in 8.0

regards,
Umesh