pingcap / pingcap/tidb

Duplicated entry in DATA_LOCK_WAITS table

Open
#37,771 1 comment 0 reactions 0 assignees View on GitHub
affects-6.5 affects-7.1 affects-7.5 affects-8.1 affects-8.5 report/customer severity/minor sig/transaction type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)

Make some lock waiting of pessimistic transactions and then query `INFORMATION_SCHEMA.DATA_LOCK_WAITS` table for the lock waiting information:

```sql
/* init */ drop table if exists t;
/* init */ create table t (id int primary key, v int);
/* init */ insert into t values (1, 1), (2, 2);

/* t1 */ begin;
/* t1 */ update t set v = 2 where id = 1;
/* t2 */ begin;
/* t2 */ update t set v = 3 where id = 1; -- blocked

/* t3 */ select * from information_schema.data_lock_waits;
```

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

A single lock-waiting entry is shown in the table like following:

```sql
-- t3 >> +----------------------------------------+----------------------------------------------------------------------------------------------------+--------------------+------------------------+------------------------------------------------------------------+-----------------------------------------+
-- t3 | KEY | KEY_INFO | TRX_ID | CURRENT_HOLDING_TRX_ID | SQL_DIGEST | SQL_DIGEST_TEXT |
-- t3 +----------------------------------------+----------------------------------------------------------------------------------------------------+--------------------+------------------------+------------------------------------------------------------------+-----------------------------------------+
-- t3 | 74800000000000004D5F728000000000000001 | {"db_name":"test","table_name":"t","handle_type":"int","handle_value":"1","db_id":2,"table_id":77} | 435955806052810758 | 435955806052810757 | 22230766411edb40f27a68dadefc63c6c6970d5827f1e5e22fc97be2c4d8350d | update `t` set `v` = ? where `id` = ? ; |
-- t3 +----------------------------------------+----------------------------------------------------------------------------------------------------+--------------------+------------------------+------------------------------------------------------------------+-----------------------------------------+
```

### 3. What did you see instead (Required)

Two duplicated rows showing the same lock waiting, one of which doesn't have the SQL_DIGEST information:

```sql
-- t3 >> +----------------------------------------+----------------------------------------------------------------------------------------------------+--------------------+------------------------+------------------------------------------------------------------+-----------------------------------------+
-- t3 | KEY | KEY_INFO | TRX_ID | CURRENT_HOLDING_TRX_ID | SQL_DIGEST | SQL_DIGEST_TEXT |
-- t3 +----------------------------------------+----------------------------------------------------------------------------------------------------+--------------------+------------------------+------------------------------------------------------------------+-----------------------------------------+
-- t3 | 74800000000000004D5F728000000000000001 | {"db_name":"test","table_name":"t","handle_type":"int","handle_value":"1","db_id":2,"table_id":77} | 435955806052810758 | 435955806052810757 | 22230766411edb40f27a68dadefc63c6c6970d5827f1e5e22fc97be2c4d8350d | update `t` set `v` = ? where `id` = ? ; |
-- t3 | 74800000000000004D5F728000000000000001 | {"db_name":"test","table_name":"t","handle_type":"int","handle_value":"1","db_id":2,"table_id":77} | 435955806052810758 | 435955806052810757 | NULL | NULL |
-- t3 +----------------------------------------+----------------------------------------------------------------------------------------------------+--------------------+------------------------+------------------------------------------------------------------+-----------------------------------------+
```

This strange behavior is also noticed in https://github.com/pingcap/automated-tests/pull/1114#issuecomment-1182746279

It's suspected to be introduced when supporting getting lock waiting state from resolving-lock info (which is useful for providing lock-waiting information about optimistic transactions), without deduping with the entries of pessimistic lock-waiting.

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

Current master (12ae85f32b11ba4ed5ed9ec111cb6777d860e3ac)

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.