Skip to content

show table t next_row_id wrong result for AUTO_ID_CACHE=1 #46545

@tiancaiamao

Description

@tiancaiamao

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

tiup playground --mode tikv-slim
./bin/tidb-server -store=tikv -path=127.0.0.1:2379
mysql -h 127.0.0.1 -u root -P 4000
create table t (id int auto_increment) auto_id_cache = 1;
insert into t values (),(),()
mysql> show table t next_row_id;
+---------+------------+-------------+--------------------+----------------+
| DB_NAME | TABLE_NAME | COLUMN_NAME | NEXT_GLOBAL_ROW_ID | ID_TYPE        |
+---------+------------+-------------+--------------------+----------------+
| test    | t          | _tidb_rowid |              30001 | _TIDB_ROWID    |
| test    | t          | _tidb_rowid |                  4 | AUTO_INCREMENT |
+---------+------------+-------------+--------------------+----------------+
2 rows in set (0.00 sec)

restart tidb-server, and query again:

mysql> show table t next_row_id;
ERROR 2013 (HY000): Lost connection to MySQL server during query
No connection. Trying to reconnect...
Connection id:    2243952642
Current database: test

+---------+------------+-------------+--------------------+----------------+
| DB_NAME | TABLE_NAME | COLUMN_NAME | NEXT_GLOBAL_ROW_ID | ID_TYPE        |
+---------+------------+-------------+--------------------+----------------+
| test    | t          | _tidb_rowid |              30001 | _TIDB_ROWID    |
| test    | t          | _tidb_rowid |              30001 | AUTO_INCREMENT |
+---------+------------+-------------+--------------------+----------------+
2 rows in set (0.00 sec)

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

AUTO_INCREMENT value should 4

3. What did you see instead (Required)

It's 30001, the same value as _TIDB_ROWID

The bug disappear if some new values are inserted.

mysql> insert into t values (),(),();
Query OK, 3 rows affected (0.01 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> show table t next_row_id;
+---------+------------+-------------+--------------------+----------------+
| DB_NAME | TABLE_NAME | COLUMN_NAME | NEXT_GLOBAL_ROW_ID | ID_TYPE        |
+---------+------------+-------------+--------------------+----------------+
| test    | t          | _tidb_rowid |              60001 | _TIDB_ROWID    |
| test    | t          | _tidb_rowid |                  7 | AUTO_INCREMENT |
+---------+------------+-------------+--------------------+----------------+
2 rows in set (0.00 sec)

4. What is your TiDB version? (Required)

master

mysql>  select tidb_version();
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                       |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v7.4.0-alpha-241-g1057a3ee78
Edition: Community
Git Commit Hash: 1057a3ee78ee6e1a7f9a659dbfb020724e377bc5
Git Branch: master
UTC Build Time: 2023-08-31 03:42:39
GoVersion: go1.21.0
Race Enabled: false
Check Table Before Drop: false
Store: tikv |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions