sql - 对于整数类型的主键,为什么避免间隙很重要?

标签 sql mysql indexing

我正在为表生成代理键,由于我的高/低算法,每次重新启动/重新启动机器时,可能会出现间隙。

T1: current hi = 10000000 
    (sequence being dished out .. 1 to 100)
       Assume that current sequence is 10000050

T2: restart system.

T3: System gives out the next_hi as 10000100 
    (sequence being dished out now ranges from 101 to 200)

T4: Next request for a key returns 100001001

从主键或索引内部的角度来看,为什么序列中没有间隙很重要?我问这个是为了更深入地了解 mysql。

最佳答案

From a primary key or indexing internals perspective, why is it important that there be no gaps in the sequences?

这并不重要 - 是什么让您相信它是重要的?
与主键相关的所有重要事项是它对表中的所有数据都是唯一的。不管值是什么,或者之前和之后的记录是否是顺序值。

关于sql - 对于整数类型的主键,为什么避免间隙很重要?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2535483/

相关文章:

Magento URL 索引和 core_url_rewrite 表

sql - 在普通 Postgres 查询中使用 PostGIS 中的边界框

mysql - 在 MYSQL 中不使用游标进行迭代

hadoop - Hive 索引无法重建 - DAG 由于顶点故障而失败

mysql - 标志的哪种数据类型?

具有内连接的 MySql 存储过程

python - 有没有好方法在 numpy 数组上进行 "moving"计算?

mysql - 使用 MySQL 匹配仅从列的开头开始匹配

sql - 使用 bool 全文搜索按相关性排序

php - Laravel:语法错误或访问冲突导致我也像字段一样使用 'order'