Please answer these questions before submitting your issue. Thanks!
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;
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 */ |
+-------+--------------------------------------------------------------------------------------------------------------------------------------+
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 */ |
+-------+---------------------------------------------------------------------------------------------------------------------------------+
master, v4.0.0, v3.1.0
When show create table is executed, AUTO_RANDOM_BASE part should be filled with the value pull from meta key, instead of TableInfo.AutoRandID.
I am working on this.
When
show create tableis executed,AUTO_RANDOM_BASEpart should be filled with the value pull from meta key, instead ofTableInfo.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