对于整数类型的主键,为什么避免空白很重要? [英] For a primary key of an integral type, why is it important to avoid gaps?

查看:89
本文介绍了对于整数类型的主键,为什么避免空白很重要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为表&生成代理密钥.由于我的高/低算法,每次重新启动/重新启动计算机时,都可能会出现间隙.

I am generating a surrogate key for a table & due to my hi/lo algorithm, everytime you reboot/restart the machine, gaps may appear.

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 ? I'm asking this for a deeper understanding of mysql specifically.

推荐答案

从主键或索引内部结构的角度来看,为什么序列中没有空缺很重要?

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

这并不重要-是什么让您相信它是什么?
与主键有关的所有事情是,它对于表中的所有数据都是唯一的.值是什么,或前后的记录是否为顺序值都无所谓.

It's not important - what lead you to believe it was?
All that matters with the primary key is that it is unique to all the data in the table. Doesn't matter what the value is, or if the records before and after are sequencial values.

这篇关于对于整数类型的主键,为什么避免空白很重要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆