Bug #100598 Hang if dropping a database where there is a table without .frm file
Submitted: 21 Aug 2020 9:37 Modified: 21 Aug 2020 10:29
Reporter: Zhang JiYang Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DDL Severity:S3 (Non-critical)
Version:5.7, 5.6, 5.7.31 OS:Any
Assigned to: CPU Architecture:Any

[21 Aug 2020 9:37] Zhang JiYang
Description:
If a .frm file was unexpectedly removed, dropping the corresponding database will hang.

How to repeat:
# create a database and a table
create database db1;
create table db1.t1 (id int);

# increment table->n_ref_count
select * from db1.t1;

# remove the .frm file
--let $datadir=`SELECT @@GLOBAL.datadir`
--remove_file $datadir/db1/t1.frm

# hang, because table->n_ref_count is not zero
drop database db1;

Suggested fix:
The key point is table->n_ref_count can't be reduced as 0. See function:

mysql_rm_db:

 --> find_db_tables_and_rm_known_files can't add the table object into **tables** because .frm file is missed.

 --> tdc_remove_table can't be called because of the empty **tables**, and also table->n_ref_count can't be reduced.

 --> row_drop_table_for_mysql fall into endless loop because table->n_ref_count can never be 0.
[21 Aug 2020 10:29] MySQL Verification Team
Hello zanye zjy,

Thank you for the report and test case.

regards,
Umesh