MySQL:bigint 与 int

发布于 2024-10-14 04:50:24 字数 280 浏览 5 评论 0 原文

我一直在使用 int(10) 并注意到 WordPress 使用 bigint(20) - 使用 bigint(20) 和 int(10) 进行 id 自动增量有什么不同?我应该使用哪一个作为 id 列?

`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

`id` int(10) unsigned NOT NULL AUTO_INCREMENT,

谢谢。

I have been using int(10) and just noticed that Wordpress uses bigint(20) - What is different to use bigint(20) and int(10) for id auto increment? Which one should I use for id column?

`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

Vs

`id` int(10) unsigned NOT NULL AUTO_INCREMENT,

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

兲鉂ぱ嘚淚 2024-10-21 04:50:24

区别纯粹在于可以存储的最大值(我相信 bigint(20) 为 18,446,744,073,709,551,615,int(10) 为 4,294,967,295),根据 MySQL 数字类型手册页。

顺便说一句,除非您使用 ZEROFILL,否则 (20) 和 (10) 的使用基本上无关紧要。 (即:它实际上并没有改变存储的数字的大小 - 这完全取决于类型。)

但是,实际上,应该注意的是,您不太可能很快就会达到这些限制,除非您是一位真正活跃的博主。

The difference is purely in the maximum value which can be stored (18,446,744,073,709,551,615 for the bigint(20) and 4,294,967,295 for the int(10), I believe), as per the details on the MySQL Numeric Types manual page.

Incidentally, the use of (20) and (10) is largely irrelevant unless you're using ZEROFILL. (i.e.: It doesn't actually change the size of the number stored - that's all down to the type.)

However, in practical terms it should be noted that you're not likely to hit either of these limits any time soon, unless you're a really active blogger.

同展鸳鸯锦 2024-10-21 04:50:24

唯一的区别是类型的范围。 INT 是 32 位长,而 BIGINT 是 64 位长,因此它可以存储更大的数字,例如 123456789123456789 (无法存储)如INT)。

以下是 MySQL 整数类型的完整列表:http://dev. mysql.com/doc/refman/5.0/en/numeric-types.html

The only difference is the range of the type. INT is a 32-bit long while BIGINT is 64-bit long, therefore it can store much larger numbers like 123456789123456789 (which cannot be stored as INT).

Here's a full list of MySQL integer types: http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html

演多会厌 2024-10-21 04:50:24

为什么有人谈论它,因为使用其中之一没有任何区别。

数据库越大,迭代所有这些数据所需的时间就越多。

想象一下,有人把你的车钥匙藏在包里。该袋子位于您面前的 20 个盒子之一中,每个盒子总共包含 8 个袋子。

这会花费很多时间,因为在最坏的情况下,您必须托运 20 个箱子中的 8 件行李,即需要托运 160 件行李。

现在,将箱子内的行李数量减半至 4 个。您肯定会节省时间,因为最多需要托运 80 个行李。

同样的做法也适用于数据库。如果您使用 bigint 而不是 int (或medium、small、tiny),您会遇到性能下降的情况。这就是为什么您应该明智地选择数据类型。

Why does anybody speak about it as it would not make any difference to use one of them.

The bigger your database get, the more time it'll take to iterate through all these data.

Imagine that someone hides your car key in a bag. The bag is in one the 20 boxes in front of you and each of them contain 8 bags in total.

This would take a lot of time since you have to check 8 bags in 20 boxes in a worst case scenario, which is 160 bags you have to check for.

Now halve the amount of bags inside the boxes to 4. You'll definitely save time since you have to check 80 bags at the maximum.

Well the same practice goes for databases. If you use bigint instead of int (or medium,small,tiny) you'll experience a performance drop down. That's why you should choose your datatypes wisely.

时光倒影 2024-10-21 04:50:24

有趣的是,大多数评论只表达了对尺寸的担忧。即使对于 Wordpress,BigInt 的使用也很重要。

目前,UUID 的使用更为普遍,因为当我们创建网站时,我们应该从大处着眼。最后,也许我不是我页面上唯一的博主。也许我的整个社区都想表达自己。对于多次访问,插入 64 位 UUID 会更安全。

It's interesting to see how most of the comments only express concern about the size. Even for Wordpress the use of BigInt is important.

Currently, the use of UUIDs is more common, because when we create sites we should think big. At the end, maybe I am not the only blogger on my page. Maybe my entire community wants to express themself. With multiple accesses it is safer to insert 64-bit UUIDs.

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