在MySQL中声明所有主键bigint能有多大区别?

发布于 2024-12-04 03:20:02 字数 144 浏览 4 评论 0原文

我有一些不需要 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

停滞 2024-12-11 03:20:02

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)

心舞飞扬 2024-12-11 03:20:02

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.

枕头说它不想醒 2024-12-11 03:20:02

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 to INT on smaller tables is negligable, although it might be an idea to keep the BIGINT type in case your row count goes above INTs 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文