Tidb: update auto_random_base in 'show create table' after insertion

Created on 27 May 2020  路  3Comments  路  Source: pingcap/tidb

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

drop table if exists t;
create table t (a bigint primary key auto_random(5), b int unique key auto_increment) auto_random_base = 100, auto_increment = 100;
insert into t values (1000);
show create table t;

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

The AUTO_RANDOM_BASE part should be updated to a larger value:

+-------+--------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                         |
+-------+--------------------------------------------------------------------------------------------------------------------------------------+
| t     | CREATE TABLE `t` (                                                                                                                   |
|       |   `a` bigint(20) NOT NULL /*T![auto_rand] AUTO_RANDOM(5) */,                                                                         |
|       |   `b` int(11) NOT NULL AUTO_INCREMENT,                                                                                               |
|       |   PRIMARY KEY (`a`),                                                                                                                 |
|       |   UNIQUE KEY `b` (`b`)                                                                                                               |
|       | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin  AUTO_INCREMENT=2000100 /*T![auto_rand_base] AUTO_RANDOM_BASE=2000100 */ |
+-------+--------------------------------------------------------------------------------------------------------------------------------------+

3. What did you see instead (Required)

AUTO_RANDOM_BASE is still 100.

+-------+---------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                    |
+-------+---------------------------------------------------------------------------------------------------------------------------------+
| t     | CREATE TABLE `t` (                                                                                                              |
|       |   `a` bigint(20) NOT NULL /*T![auto_rand] AUTO_RANDOM(5) */,                                                                    |
|       |   `b` int(11) NOT NULL AUTO_INCREMENT,                                                                                          |
|       |   PRIMARY KEY (`a`),                                                                                                            |
|       |   UNIQUE KEY `b` (`b`)                                                                                                          |
|       | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=2000100 /*T![auto_rand_base] AUTO_RANDOM_BASE=100 */ |
+-------+---------------------------------------------------------------------------------------------------------------------------------+

4. Affected version (Required)


master, v4.0.0, v3.1.0

5. Root Cause Analysis

When show create table is executed, AUTO_RANDOM_BASE part should be filled with the value pull from meta key, instead of TableInfo.AutoRandID.

difficulteasy siinfra statuhelp-wanted typbug

All 3 comments

I am working on this.

When show create table is executed, AUTO_RANDOM_BASE part should be filled with the value pull from meta key, instead of TableInfo.AutoRandID.

@tangenta I have no idea about how to pull from meta key. Is there any code I can refer to? Could you please give me some advice? Thanks!

The current allocated ID is stored in a meta key-value. You can get the value through Allocator.NextGlobalAutoID().

See:
https://github.com/pingcap/tidb/blob/7ca3d9cadccaa19b12e20c2b5d71615c7e735a5d/executor/show.go#L1016

Was this page helpful?
0 / 5 - 0 ratings