`tidb_shard` index on `ON UPDATE CURRENT_TIMESTAMP` column causes `ERROR 8141 (HY000): assertion failed`
- 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
Assessment
This issue has not been assessed yet.