在MySQL中声明所有主键bigint能有多大区别?
我有一些不需要 bigint 主键的小表,它们不会变得那么大,但是,所有表都以 bigint 主键作为标准。
这会影响我的性能还是 mysql 在这方面很聪明?
我不想将这些表上的 PK 更改为 int,但如果它可以减慢我的速度,我当然会的。
I have some small tables that don't need the bigint primary key, they won't get that big, but, all tables have bigint primary key as standard.
Can this affect my performance or mysql is smart on that?
I wouldn't like to change the PKs to int on those tables, but if it can slow me down, surely I will.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
DBMS 的优化规则之一是“让数据尽可能小” ” - 所以如果你不需要 bigint - 将其声明为 int (并在需要时更改类型)
One of optimization rules for DBMS is "keep your data as small as possible" - so if you don't need bigint - declare it as an int (and change type when you need it)
基于此处 使用 BIGINT 可能会使数据库大小增加一个重要因素,这会影响性能,在达到相当大的大小之前可能不会注意到。
Based on benchmarks here using an BIGINT could increase the database size by a significant factor, which would affect performance, probably not noticeable until you reached a significant size.
MySQL 不会为你做这件事,因为它(和你)永远不知道表将有多大。在较小的表上将
BIGINT
更改为INT
的性能优势可以忽略不计,尽管保留BIGINT
类型可能是一个主意,以防您的行计数超出INT
的限制 2147483647 (4294967295 未签名)。但是,建议尽可能保持数据紧凑。如果它是一个相对较小的表,那么实际上您最好使用
MEDIUMINT
。它的限制是 8388607 和 16777215(无符号)。MySQL won't do this for you, as it (and you) never know(s) how big the tables will get. The performance benefits of changing
BIGINT
toINT
on smaller tables is negligable, although it might be an idea to keep theBIGINT
type in case your row count goes aboveINT
s limits of 2147483647 (4294967295 unsigned). It is, however, advisable to keep your data in as compact a way as possible.If it's a relatively small table, you might be better off going with
MEDIUMINT
actually. It's limits are 8388607 and 16777215 (unsigned).