Reason for testing
A development colleague made a framework in which the primary key is uuid. I suggested to him that mysql should not use uuid and use auto-incrementing primary keys. Auto-incrementing primary keys are more efficient. He said it is not necessarily high. I said innodb’s index The feature has led to the most efficient use of auto-incrementing ID as the primary key. In order to convince him, I prepared to do a detailed test.
As an Internet company, there must be a user table, and the user table UC_USER basically has millions of records. Therefore, the test is carried out based on the quasi-test data based on this table.
The approximate environment is: Centos6.5, MySQL5.6.12
UC_USER, auto-increment ID as primary key:
##CREATE TABLE `UC_USER` ( |
CREATE TABLE `UC_USER_PK_VARCHAR_1` ( |
Determine the amount of data in the two tables
Table with auto-increment id as the primary key mysql> select count(1) from UC_USER; +----------+ | count(1) | +----- -----+ | 5720112 | +----------+ 1 row in set (0.00 sec)
mysql>
# Table with uuid as primary key mysql> select count(1) from UC_USER_PK_VARCHAR_1; #+----------+ | count(1) | +----------+ | 5720112 | +----------+ 1 row in set (1.91 sec) |
Judging from the space capacity occupied, the auto-increment ID is about half smaller than the UUID.
Primary key type
|
Data file size
|
Occupied capacity
|
-rw-rw---- 1 mysql mysql 2.5G Aug 11 18:29 UC_USER.ibd | 2.5 G | |
-rw-rw---- 1 mysql mysql 5.4G Aug 15 15:11 UC_USER_PK_VARCHAR_1.ibd | 5.4 G |
2.2
Primary key type
| ##SQL statement|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
##SELECT SQL_NO_CACHE t.* FROM test.`UC_USER` t WHERE t.`MOBILE` ='14782121512'; |
##0.118 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
##UUID |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
0.117 |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
##Auto-increment ID | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
0.049 | UUID | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
0.040 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
##自increment ID | SELECT SQL_NO_CACHE t.* FROM test.`UC_USER` t WHERE t.`CREATE_DATE`='2013-11-24 10:26:36' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
0.139 |
UUID | SELECT SQL_NO_CACHE t.* FROM test.`UC_USER_PK_VARCHAR_1` t WHERE t.`CREATE_DATE`='2013-11-24 10 :26:43' ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
0.126 |
2.3 RangelikeQuery, self-incrementIDPerformance is better than UUID
|