pingcap / pingcap/tidb

Issue with Bulk 'LOCK TABLE' Behavior

Open
#60,016 1 comment 0 reactions 0 assignees View on GitHub
type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

Session_1 holds a row-level lock on table_a, and when Session_2 executes LOCK TABLE table_a WRITE, table_b WRITE;, it will wait to acquire the MDL lock. However, when executing LOCK TABLE table_b, table_a;, it returns the outcome immediately.

### 1. Minimal reproduce step (Required)

```
1. Set the config variable `enable-table-lock` to true.
2. Session_1:
BEGIN;
UPDATE table_a SET id = id + 1;
-- Note: Do not commit the transaction.
3. Session_2:
LOCK TABLE table_a WRITE, table_b WRITE;
-- It waits for the MDL lock until Session_1 commits the transaction.
However, in the same prerequisite, if I execute "LOCK TABLE table_b WRITE, table_a WRITE;", it immediately returns "Query OK, 0 rows affected (0.66 sec)".

```

### 2. What did you expect to see?
When there is a row-level lock on table_a, executing either LOCK TABLE table_a WRITE, table_b WRITE; or LOCK TABLE table_b WRITE, table_a WRITE; should result in both commands waiting for the MDL lock until Session_1 commits the transaction.

### 3. What did you see instead (Required)
Executing LOCK TABLE table_b WRITE, table_a WRITE; immediately returns "Query OK, 0 rows affected (0.66 sec)", even though there is a row-level lock on table_a.

### 4. What is your TiDB version? (Required)
v8.5.1

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.