pingcap / pingcap/tidb

auto_increment insert failed, but auto_id cache was changed

Open
#62,604 0 comments 0 reactions 0 assignees View on GitHub
sig/sql-infra 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)

mysql> CREATE TABLE `t` ( `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID', `data_type` smallint(4) NOT NULL COMMENT '数据类型, 1:预估 2:实际 3:预估', PRIMARY KEY (id) NONCLUSTERED ) SHARD_ROW_ID_BITS = 5;
Query OK, 0 rows affected, 2 warnings (0.08 sec)

mysql> insert into t value(1,1);
Query OK, 1 row affected (0.01 sec)

mysql> show create table t;
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t | CREATE TABLE `t` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`data_type` smallint NOT NULL COMMENT '数据类型, 1:预估 2:实际 3:预估',
PRIMARY KEY (`id`) /*T![clustered_index] NONCLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=30002 /*T! SHARD_ROW_ID_BITS=5 */ |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> insert into t value(288230376151711743,1);
ERROR 1467 (HY000): Failed to read auto-increment value from storage engine
mysql> show create table t;
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t | CREATE TABLE `t` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`data_type` smallint NOT NULL COMMENT '数据类型, 1:预估 2:实际 3:预估',
PRIMARY KEY (`id`) /*T![clustered_index] NONCLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=**288230376151741744** /*T! SHARD_ROW_ID_BITS=5 */ |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

### 2. What did you expect to see? (Required)
When insert failed, auto_id cache should not be changed.

### 3. What did you see instead (Required)
mysql> show create table t;
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t | CREATE TABLE `t` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`data_type` smallint NOT NULL COMMENT '数据类型, 1:预估 2:实际 3:预估',
PRIMARY KEY (`id`) /*T![clustered_index] NONCLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=**288230376151741744** /*T! SHARD_ROW_ID_BITS=5 */ |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

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

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.