MySQL主/外键大小?
我似乎看到很多人在 MySQL 模式中任意分配大尺寸的主/外键字段,例如 WordPress 使用的 INT(11) 甚至 BIGINT(20)。
如果我错了,请纠正我,但即使是 INT(4) 也能支持高达 40 亿以上的(无符号)值。将其更改为 INT(5),您允许的值高达四万亿,这超出了您的需要,除非您可能将地理数据存储在 NASA/Google,但我相信我们大多数人都不会。
人们使用如此大尺寸的主键是否有原因?对我来说似乎很浪费...
I seem to see a lot of people arbitrarily assigning large sizes to primary/foreign key fields in their MySQL schemas, such as INT(11) and even BIGINT(20) as WordPress uses.
Now correct me if I'm wrong, but even an INT(4) would support (unsigned) values up to over 4 billion. Change it to INT(5) and you allow for values up to a quadrillion, which is more than you would ever need, unless possibly you're storing geodata at NASA/Google, which I'm sure most of us aren't.
Is there a reason people use such large sizes for their primary keys? Seems like a waste to me...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
和
请参阅
and
See this explanation.
我认为没有任何充分的理由使用大于 32 位整数的数字来索引正常业务规模的数据库中的数据。他们中的大多数可能拥有数百万条记录(或这个数量级)。
I don't see any good reason to use a number larger than 32-bit integer for indexing data in normal business-sized databases. Most of them have maybe millions of records (or that order of magnitude).