pingcap / pingcap/tidb

txn: incompatbile lock behaviour for cop and point get for update read

Open
#54,705 0 comments 0 reactions 1 assignee Claimed by @hawkingrei View on GitHub
affects-6.5 affects-7.1 affects-7.5 affects-8.1 severity/moderate sig/planner 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!

When `select for update` is executed outside explicit transactions, there would be `SelectLockExec` for coprocessor read queries but no `lock` for point get queries, the behaviours are in-consistent.

### 1. Minimal reproduce step (Required)

```
create table t(a int key);
explain select * from t for update;
explain select * from t where a = 1 for update;
```

### 2. What did you expect to see? (Required)
Both select would not have lock operations.

### 3. What did you see instead (Required)
There is `SelectLockExec` on `select * from t for update;`
```
explain select * from t for update;
+-------------------------+----------+-----------+---------------+--------------------------------+
| id | estRows | task | access object | operator info |
+-------------------------+----------+-----------+---------------+--------------------------------+
| SelectLock_5 | 10000.00 | root | | for update 0 |
| └─TableReader_7 | 10000.00 | root | | data:TableFullScan_6 |
| └─TableFullScan_6 | 10000.00 | cop[tikv] | table:t | keep order:false, stats:pseudo |
+-------------------------+----------+-----------+---------------+--------------------------------+
3 rows in set (0.001 sec)
```

While the point get query dose not have `lock` flag
```
MySQL [test]> explain select * from t where a = 1 for update;
+-------------+---------+------+---------------+---------------+
| id | estRows | task | access object | operator info |
+-------------+---------+------+---------------+---------------+
| Point_Get_1 | 1.00 | root | table:t | handle:1 |
+-------------+---------+------+---------------+---------------+
```

**Note** though the `SelectLockExec` is generated in the SQL plan, it would be skipped when building `SelectLockExec` executor at https://github.com/pingcap/tidb/blob/master/pkg/executor/builder.go#L770.

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

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.