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.
2 Answers
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,084
- 12
- 15
-
Yes, I'm using InnoDB... some of the apps in the company I work for uses UUID as primary key, but I'm not sure if I should still using it or not. I supposed I don't need UUID keys so maybe I'll stop using them. – PachinSV Apr 27 '11 at 19:31
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.

- 5,499
- 1
- 20
- 16
-
See also a discussion on UUID() and UUID_SHORT() https://stackoverflow.com/questions/12818671/is-mysql-uuid-short-comparable-to-uuid – theking2 Aug 27 '20 at 17:02