Mysql PK 和 FK char(36) 与 int(10)
我读到,如果表键是整数而不是 char(36) UUID,mysql 可以更好地处理索引和搜索。
值得转换为 int(10) 吗?
注意:我们只使用 1 台服务器,并且目前必须计划同时使用多个数据库,因此消除了使用 UUID 的重要原因之一。如果这有区别的话,我们的表也是 InnoDB。
提前致谢。
I have read that mysql can handle indexes and searches better if the tables keys are integers rather than char(36) UUID's.
Is it worth converting to int(10)?
NOTE: We only use 1 server and have currently have to plans to use multiple databases concurrently therefore removing one of the big reasons for using UUID. Our tables are also InnoDB if that makes a difference.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(3)
幽梦紫曦~2024-10-25 23:48:36
UUID 是已索引的行,但众所周知,由于索引大小,字符键比数字键慢。
但是,如果您需要 UUID 或字符连接/索引,则必须考虑到这一点:
- 与整数键相比,CHAR 键对于连接来说确实更慢
- 对于 Innodb 表来说,性能下降的范围可能是百分之几到几倍
- MyISAM 表可能会受到严重影响,如果键压缩未禁用
- 连接较短的 CHAR 键明显比长键快
- 与 UTF8 相比,Latin1(我猜任何简单的编码)的连接速度明显更快
我分享此信息并在生产环境中对其进行了测试,可以在http://forums.mysql.com/read.php?24,263462,263462
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
通常,RDBMS 可以比其他数据类型更有效地处理整数键,因为 PK 更有效。原因是它如何构建列的索引,所以是的:只要您不需要字符串(或其他类型)键,您就应该始终使用整数。
但是:CHAR(36) 和 INT(10) 远非相等,因为 INT(10) 比 CHAR(36)小得多。我不知道您是否需要这么多不同的密钥,但您应该记住这一点。
更新,完成最后一段:
INT(10)
为 32 位,CHAR(36)
为 36 - ^Byte^(= 288 位)。这不仅意味着INT
消耗更少的空间,还意味着CHAR(36)
拥有大约 4 倍的不同键。Usually RDBMS can handle Integer keys as PK more efficient, than other datatypes. The reason is how it build up the index for the column, so yes: As long as you dont require string (or other typed) keys, you should always use integers.
However: CHAR(36) and INT(10) are far away from being equal, because a INT(10) is much smaller, than CHAR(36). I dont know, if you require so many different keys, but you should keep that in mind.
Update, to complete the last paragraph:
INT(10)
is 32-Bit,CHAR(36)
is 36 - ^Byte^ (= 288-Bit). This does not only mean, thatINT
consumes less space, it also means, thatCHAR(36)
has about 4 times more different keys.