其他分享
首页 > 其他分享> > TiDB自增ID

TiDB自增ID

作者:互联网

自增ID实现原理:

自增ID使用限制


AUTO_RANDOM用于解决聚簇表大批量写入数据时,因含有整型自增主键而产生的热点问题

 

mysql> create table t(a bigint primary key auto_random);
Query OK, 0 rows affected, 1 warning (0.28 sec)

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

mysql> select * from t;
+---------------------+
| a                   |
+---------------------+
| 1441151880758558725 |
| 1441151880758558726 |
| 4899916394579099655 |
| 4899916394579099656 |
| 6052837899185946625 |
| 6052837899185946626 |
| 6052837899185946627 |
| 6052837899185946628 |
| 6341068275337658377 |
| 6341068275337658378 |
+---------------------+
10 rows in set (0.00 sec)

当tidb_enable_clustered_index值为默认值INT_ONLY时,所见的auto_random的表为聚簇表

mysql> select @@global.tidb_enable_clustered_index;
+--------------------------------------+
| @@global.tidb_enable_clustered_index |
+--------------------------------------+
| INT_ONLY                             |
+--------------------------------------+
1 row in set (0.00 sec)
mysql> show create table t\G
*************************** 1. row ***************************
       Table: t
Create Table: CREATE TABLE `t` (
  `a` bigint(20) NOT NULL /*T![auto_rand] AUTO_RANDOM(5) */,
  PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T![auto_rand_base] AUTO_RANDOM_BASE=30001 */
1 row in set (0.00 sec)

 

AUTO_RANDOM使用限制:

标签:自增,TiDB,auto,AUTO,RANDOM,mysql,ID
来源: https://blog.csdn.net/JSWANGCHANG/article/details/122585690