Why the auto_increment id does not increase one by one, how to set it?(为什么auto_increment id不一一增加,怎么设置呢?)
问题描述
我有一个 MariaDB Galera 集群(3 个节点),我将 uid 设置为自动增加并作为表的主键
I have a MariaDB Galera Cluster(3 nodes), I set uid to increase automatically and be the primary key of the table as
`uid | int(11) | NO | PRI | NULL | auto_increment`.
MariaDB [hello_cluster]> select uid from table order by uid limit 10;
+-----+
| uid |
+-----+
| 3 |
| 6 |
| 9 |
| 12 |
| 15 |
| 18 |
| 21 |
| 24 |
| 27 |
| 30 |
+-----+
我试过下面的命令,还是不行
I tried the following command, and it does not work
alter table uid AUTO_INCREMENT=1
推荐答案
这是设计使然,报告在 MariaDB Galera 集群 - 已知限制:
This is by design and is reported in MariaDB Galera Cluster - Known Limitations:
不要依赖自动递增值是连续的.Galera 使用基于自增增量的机制来生成唯一的非冲突序列,因此在每个单个节点上序列都会有间隙.
Do not rely on auto-increment values to be sequential. Galera uses a mechanism based on autoincrement increment to produce unique non-conflicting sequences, so on every single node the sequence will have gaps.
使用 Multi Masters 管理自动增量中解释了原因,这也是为什么观察到的自增量与聚类数具有相同的步长.
The rational is explained in Managing Auto Increments with Multi Masters, and is also why the observed auto-increment has the same step as the number of clusters.
MySQL 有系统变量 auto_increment_increment 和 auto_increment_offset 用于管理多主环境中的自动增量序列".使用这些变量,可以设置多主复制,其中每个主节点中的自动递增序列交错,并且集群中不应发生冲突.无论哪个 master(s) 获得 INSERT.
MySQL has system variables auto_increment_increment and auto_increment_offset for managing auto increment 'sequences' in multi master environment. Using these variables, it is possible to set up a multi master replication, where auto increment sequences in each master node interleave, and no conflicts should happen in the cluster. No matter which master(s) get the INSERTs.
即使没有集群,由于事务回滚和删除记录,依靠自动递增列成为密集序列也很少是一个好"的主意.
Even without clusters, it is rarely a "good" idea to rely on auto-increment columns to be dense sequences due to transaction rollbacks and deleted records.
这篇关于为什么auto_increment id不一一增加,怎么设置呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么auto_increment id不一一增加,怎么设置呢?
基础教程推荐
- 无法解决整理冲突 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
