pingcap / pingcap/tidb

`tidb_shard` index on `ON UPDATE CURRENT_TIMESTAMP` column causes `ERROR 8141 (HY000): assertion failed`

Open
#54,814 3 comments 0 reactions 1 assignee Claimed by @you06 View on GitHub
affects-6.0 affects-6.1 affects-6.2 affects-6.3 affects-6.4 affects-6.5 affects-6.6 affects-7.0 affects-7.1 affects-7.2 affects-7.3 affects-7.4 affects-7.5 affects-7.6 affects-8.0 affects-8.1 may-affects-5.4 severity/major sig/transaction type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

As the title says.

### 1. Minimal reproduce step (Required)

```sql
CREATE TABLE `item` (
`id` int NOT NULL AUTO_INCREMENT,
`status` tinyint(1) NOT NULL,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY ((tidb_shard(`updated_at`)), `updated_at`)
);
```

```bash
mysql> INSERT INTO item(status) VALUES(1);
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM item;
+----+--------+---------------------+
| id | status | updated_at |
+----+--------+---------------------+
| 1 | 1 | 2024-07-22 13:20:55 |
+----+--------+---------------------+
1 row in set (0.00 sec)

mysql> UPDATE item SET status = 2;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> SELECT * FROM item;
+----+--------+---------------------+
| id | status | updated_at |
+----+--------+---------------------+
| 1 | 2 | 2024-07-22 13:21:28 |
+----+--------+---------------------+
1 row in set (0.00 sec)

mysql> UPDATE item SET status = 3;
ERROR 8141 (HY000): assertion failed: key: 748000000000000a925f69800000000000000104000000000000008f0419b3ecd55c000000038000000000000001, assertion: Exist, start_ts: 451321398243360772, existing start ts: 0, existing commit ts: 0
```

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

no assertion failed.

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

--

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

```
tidb_version(): Release Version: v7.5.1
Edition: Community
Git Commit Hash: 7d16cc79e81bbf573124df3fd9351c26963f3e70
Git Branch: heads/refs/tags/v7.5.1
UTC Build Time: 2024-02-27 14:28:32
GoVersion: go1.21.6
Race Enabled: false
Check Table Before Drop: false
Store: tikv
```

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.