tidb icon indicating copy to clipboard operation
tidb copied to clipboard

DROP DATABASE is not blocked while executing transaction

Open wengsy150943 opened this issue 1 year ago • 1 comments

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

Init a database and a table.

create database test;
create table t (a int);

Then start a tranasction, insert data into t, and hang it.

begin;
insert into t values(1);

Drop database test in another session.

drop database test;

2. What did you expect to see? (Required)

DROP DATABASE is blocked until transaction is committed.

We tested DROP TABLE in TiDB and found this DDL will be blocked. And we also test DROP DATABASE in MySQL, which is also be blocked. So it seems obviously that DROP DATABASE should also be blocked.

3. What did you see instead (Required)

DROP DATABASE can be executed. And the idling transaction can also be committed without warning/error.

--- session of DROP
MySQL [wsydb1]> drop database test;
Query OK, 0 rows affected (0.24 sec)

--- session of transaction
mysql> commit;
Query OK, 0 rows affected (0.03 sec)

Maybe locking all tables while altering database can help.

4. What is your TiDB version? (Required)

mysql> SELECT tidb_version();
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()

                                               |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v7.1.0
Edition: Community
Git Commit Hash: 635a4362235e8a3c0043542e629532e3c7bb2756
Git Branch: heads/refs/tags/v7.1.0
UTC Build Time: 2023-05-30 10:58:57
GoVersion: go1.20.3
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: tikv |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)


wengsy150943 avatar Sep 13 '23 07:09 wengsy150943

current mdl table doesn't contain schema info, it requires change system table to fix it, and the scenario is quite uncommon, change priority to moderate https://github.com/pingcap/tidb/blob/20454c45dc3a8b384f36fc9c2e80597c792e67b5/pkg/session/session.go#L3144-L3148

D3Hunter avatar Apr 29 '24 11:04 D3Hunter