how can affect performance when I use UUIDs as my primary keys in MySQL

帅比萌擦擦* 提交于 2019-12-04 06:44:05

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/5793203/how-can-affect-performance-when-i-use-uuids-as-my-primary-keys-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!