共识? MySQL,签名 VS 未签名主/外键
我看到了一些关于每个人现在在签名与未签名键值方面所做的事情的线程。看来无符号是最佳的,因为它允许以相同的成本增加两倍的行数。签名密钥有什么好处吗?
有没有标准共识?似乎签名就是答案,因为“一直都是这样”
I have seen a couple threads about what everyone was doing now a days in regards to signed vs unsigned key values. It would seem that unsigned is optimal since it allows twice the number of rows for the same cost. Are there any benefits with signed keys?
Is there any standard consensus? Its seems like signed is the answer since "it has always been that way"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果列不能为负数,我更愿意将列设置为
无符号
。除了您提到的范围因素之外,它还使阅读表定义时更加清晰。I prefer to set my columns as
unsigned
if they cannot be negative. Besides the range factor that you mentioned, it also makes it clearer when reading the table definition.一个有符号的 32 位 int 可以代表超过 20 亿个数字,所以我怀疑这个问题对大多数人来说没有实际意义。也就是说,当我想表明一条记录是故意孤立的时,我经常使用负数。
A signed 32-bit int can represent over 2 billion numbers so I suspect the issue is moot for most people. That said, I often use negative numbers when I want to indicate that a record is purposefully orphaned.