Skip to content

Duplicate entry when using BR to restore a NONCLUSTERED AUTO_ID_CACHE=1 table #46093

@kennytm

Description

@kennytm

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

  1. prepare
use test;
create table t (a int primary key nonclustered auto_increment, b int) auto_id_cache = 1;
insert into t (b) values (1), (2), (3);
show table t next_row_id;
-- _TIDB_ROWID = 30001, AUTO_INCREMENT = 4
  1. backup & restore
backup table t to 'local:///tmp/br';
drop table t;
restore table t from 'local:///tmp/br';

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

(explained below)

3. What did you see instead (Required)

  1. the next_row_id are wrong
show table t next_row_id;
-- _TIDB_ROWID = 1, AUTO_INCREMENT = 4001
  1. try insert more rows, result in duplicate keys of _tidb_rowid
insert into t (b) values (4), (5), (6);
-- ERROR 1062 (23000): Duplicate entry '1' for key 't.PRIMARY'
  1. after _tidb_rowid increases to the available zone, we see the primary key's auto-inc values have a gap
insert into t (b) values (7), (8), (9);
select * from t;
+------+------+
| a    | b    |
+------+------+
|    1 |    1 |
|    2 |    2 |
|    3 |    3 |
| 4004 |    7 |
| 4005 |    8 |
| 4006 |    9 |
+------+------+

4. What is your TiDB version? (Required)

Release Version: v7.1.1
Edition: Community
Git Commit Hash: cf441574864be63938524e7dfcf7cc659edc3dd8
Git Branch: heads/refs/tags/v7.1.1
UTC Build Time: 2023-07-19 10:20:53
GoVersion: go1.20.6
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: tikv

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions