当我在 MySQL 中使用 UUID 作为主键时,会如何影响性能
我想知道当我在 MySQL 中使用 UUID 作为主键时,会对服务器的性能产生怎样或多大的影响。
I would like to know how or how much can affect the performance of the server when I use UUID for my primary keys in MySQL.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想你正在使用InnoDB(无论如何你应该......)
所以请阅读《高性能MySQL 2ed》的以下章节,第117页:http:// /books.google.com.hk/books?id=BL0NNoFPuAQC&lpg=PA117&ots=COPMBsvA7V&dq=uuid%20innodb%20clustered%20index%20high%20performance%20mysql&pg=PA117#v=onepage&q&f =false
一般来说,从性能角度来看,UUID 是一个糟糕的选择(由于聚集索引),并且他们有一个基准来证明这一点。
I suppose you are using InnoDB (You should anyway....)
So read the following chapter from High performance MySQL 2ed, p.117: http://books.google.com.hk/books?id=BL0NNoFPuAQC&lpg=PA117&ots=COPMBsvA7V&dq=uuid%20innodb%20clustered%20index%20high%20performance%20mysql&pg=PA117#v=onepage&q&f=false
In general, UUID is a poor choice from the performance standpoint (due to clustered index) and they have a benchmark to prove this.
UUID 的长度为 36 个字符,即 36 个字节。 INT 为 4 字节,有 TINYINT、MEDIUMINT 和 BIGINT 等变体,均小于 36 字节。
因此,对于您插入的每条记录,您的索引将分配更多空间。
此外,与递增整数相反,UUID 需要更多时间来计算。
至于它对系统的影响有多大,很难给出实际的数字,因为有多种因素——系统的负载、硬件等等。
UUID is 36 chars long, which means 36 bytes. INT is 4 bytes with variations of TINYINT, MEDIUMINT and BIGINT, which are all below 36 bytes.
Therefore, for each record you insert, your index will allocate more space.
Also, UUID is taking more time to be computed opposing to incrementing integer.
As for how much it can affect the system, it's hard to give out the actual numbers because there are various factors - the load of the system, the hardware and so on.