pingcap / tidb

TiDB - the open-source, cloud-native, distributed SQL database designed for modern applications.
https://pingcap.com
Apache License 2.0
37.38k stars 5.85k forks source link

TiDB locks the record which is filtered by the non-index condition in point-get plan at RC isolation #37653

Open TonsnakeLin opened 2 years ago

TonsnakeLin commented 2 years ago

Bug Report

Please answer these questions before submitting your issue. Thanks! RC isolation

1. Minimal reproduce step (Required)

create table t1(id1 int, id2 int, id3 int, PRIMARY KEY(id1), UNIQUE KEY udx_id2 (id2)); INSERT INTO t1 VALUES(1,1,1); -- session1 begin; select from t1 where id1 = 1 and id2 = 2 for update; -- session2 begin select from t1 where id1 = 1 for update;

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

session2 returns the result immediately.

3. What did you see instead (Required)

session2 was blocked by the lock of the key whose values is ```

4. What is your TiDB version? (Required)

Release Version: v6.2.0 Edition: Community Git Commit Hash: daf2b17cdfe30c02ce282361009fb5bdb05f2b0e

ekexium commented 2 years ago

Why shouldn't session2 be blocked by the lock?

TonsnakeLin commented 2 years ago

because on session1, the key 1 is not filtered out by the condition 'id2 = 2', it should release the lock on key 1.

ekexium commented 2 years ago

because on session1, the key 1 is not filtered out by the condition 'id2 = 2', it should release the lock on key 1.

Emm OK I get it