当前位置:网站首页>Stop using UUID indiscriminately. Have you tested the performance gap between self incrementing ID and UUID?
Stop using UUID indiscriminately. Have you tested the performance gap between self incrementing ID and UUID?
2022-07-24 19:39:00 【Java confidant_】
Click on the official account , Practical technical articles Know in time 
Catalog
One 、 Preparation form & data
Two 、500w Level data test
2.1 entry 500W data , Self increasing ID Save half the disk space
2.2 Single data is indexed , Self increasing id and uuid Little difference
2.3 Range like Inquire about , Self increasing ID Better performance than the UUID
2.4 Write test , Self increasing ID yes UUID Of 4 times
2.5、 Backup and recovery , Self increasing ID Better performance than the UUID
500W summary
1000W summary
Self increasing ID Primary key + step , Suitable for medium-sized distributed scenarios
UUID, Suitable for small-scale distributed environment
One 、 Preparation form & data
UC_USER, Self increasing ID Primary key , The table structure is similar to the following :
CREATE TABLE `UC_USER` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT COMMENT ' Primary key ',
`USER_NAME` varchar(100) DEFAULT NULL COMMENT ' user name ',
`USER_PWD` varchar(200) DEFAULT NULL COMMENT ' password ',
`BIRTHDAY` datetime DEFAULT NULL COMMENT ' Birthday ',
`NAME` varchar(200) DEFAULT NULL COMMENT ' full name ',
`USER_ICON` varchar(500) DEFAULT NULL COMMENT ' Head picture ',
`SEX` char(1) DEFAULT NULL COMMENT ' Gender , 1: male ,2: Woman ,3: A secret ',
`NICKNAME` varchar(200) DEFAULT NULL COMMENT ' nickname ',
`STAT` varchar(10) DEFAULT NULL COMMENT ' User state ,01: normal ,02: frozen ',
`USER_MALL` bigint(20) DEFAULT NULL COMMENT ' Current owner MALL',
`LAST_LOGIN_DATE` datetime DEFAULT NULL COMMENT ' Last login time ',
`LAST_LOGIN_IP` varchar(100) DEFAULT NULL COMMENT ' Finally log in IP',
`SRC_OPEN_USER_ID` bigint(20) DEFAULT NULL COMMENT ' Federated login of source ',
`EMAIL` varchar(200) DEFAULT NULL COMMENT ' mailbox ',
`MOBILE` varchar(50) DEFAULT NULL COMMENT ' mobile phone ',
`IS_DEL` char(1) DEFAULT '0' COMMENT ' Whether or not to delete ',
`IS_EMAIL_CONFIRMED` char(1) DEFAULT '0' COMMENT ' Whether to bind the mailbox ',
`IS_PHONE_CONFIRMED` char(1) DEFAULT '0' COMMENT ' Whether to bind the mobile phone ',
`CREATER` bigint(20) DEFAULT NULL COMMENT ' founder ',
`CREATE_DATE` datetime DEFAULT CURRENT_TIMESTAMP COMMENT ' Registration time ',
`UPDATE_DATE` datetime DEFAULT CURRENT_TIMESTAMP COMMENT ' modification date ',
`PWD_INTENSITY` char(1) DEFAULT NULL COMMENT ' Password strength ',
`MOBILE_TGC` char(64) DEFAULT NULL COMMENT ' Mobile login ID ',
`MAC` char(64) DEFAULT NULL COMMENT 'mac Address ',
`SOURCE` char(1) DEFAULT '0' COMMENT '1:WEB,2:IOS,3:ANDROID,4:WIFI,5: Management system , 0: Unknown ',
`ACTIVATE` char(1) DEFAULT '1' COMMENT ' Activate ,1: Activate ,0: not active ',
`ACTIVATE_TYPE` char(1) DEFAULT '0' COMMENT ' Activation type ,0: Automatically ,1: Manual ',
PRIMARY KEY (`ID`),
UNIQUE KEY `USER_NAME` (`USER_NAME`),
KEY `MOBILE` (`MOBILE`),
KEY `IDX_MOBILE_TGC` (`MOBILE_TGC`,`ID`),
KEY `IDX_EMAIL` (`EMAIL`,`ID`),
KEY `IDX_CREATE_DATE` (`CREATE_DATE`,`ID`),
KEY `IDX_UPDATE_DATE` (`UPDATE_DATE`)
) ENGINE=InnoDB AUTO_INCREMENT=7122681 DEFAULT CHARSET=utf8 COMMENT=' User table 'UC_USER_PK_VARCHAR surface , character string ID Primary key , use uuid:
CREATE TABLE `UC_USER_PK_VARCHAR_1` (
`ID` varchar(36) CHARACTER SET utf8mb4 NOT NULL DEFAULT '0' COMMENT ' Primary key ',
`USER_NAME` varchar(100) DEFAULT NULL COMMENT ' user name ',
`USER_PWD` varchar(200) DEFAULT NULL COMMENT ' password ',
`BIRTHDAY` datetime DEFAULT NULL COMMENT ' Birthday ',
`NAME` varchar(200) DEFAULT NULL COMMENT ' full name ',
`USER_ICON` varchar(500) DEFAULT NULL COMMENT ' Head picture ',
`SEX` char(1) DEFAULT NULL COMMENT ' Gender , 1: male ,2: Woman ,3: A secret ',
`NICKNAME` varchar(200) DEFAULT NULL COMMENT ' nickname ',
`STAT` varchar(10) DEFAULT NULL COMMENT ' User state ,01: normal ,02: frozen ',
`USER_MALL` bigint(20) DEFAULT NULL COMMENT ' Current owner MALL',
`LAST_LOGIN_DATE` datetime DEFAULT NULL COMMENT ' Last login time ',
`LAST_LOGIN_IP` varchar(100) DEFAULT NULL COMMENT ' Finally log in IP',
`SRC_OPEN_USER_ID` bigint(20) DEFAULT NULL COMMENT ' Federated login of source ',
`EMAIL` varchar(200) DEFAULT NULL COMMENT ' mailbox ',
`MOBILE` varchar(50) DEFAULT NULL COMMENT ' mobile phone ',
`IS_DEL` char(1) DEFAULT '0' COMMENT ' Whether or not to delete ',
`IS_EMAIL_CONFIRMED` char(1) DEFAULT '0' COMMENT ' Whether to bind the mailbox ',
`IS_PHONE_CONFIRMED` char(1) DEFAULT '0' COMMENT ' Whether to bind the mobile phone ',
`CREATER` bigint(20) DEFAULT NULL COMMENT ' founder ',
`CREATE_DATE` datetime DEFAULT CURRENT_TIMESTAMP COMMENT ' Registration time ',
`UPDATE_DATE` datetime DEFAULT CURRENT_TIMESTAMP COMMENT ' modification date ',
`PWD_INTENSITY` char(1) DEFAULT NULL COMMENT ' Password strength ',
`MOBILE_TGC` char(64) DEFAULT NULL COMMENT ' Mobile login ID ',
`MAC` char(64) DEFAULT NULL COMMENT 'mac Address ',
`SOURCE` char(1) DEFAULT '0' COMMENT '1:WEB,2:IOS,3:ANDROID,4:WIFI,5: Management system , 0: Unknown ',
`ACTIVATE` char(1) DEFAULT '1' COMMENT ' Activate ,1: Activate ,0: not active ',
`ACTIVATE_TYPE` char(1) DEFAULT '0' COMMENT ' Activation type ,0: Automatically ,1: Manual ',
PRIMARY KEY (`ID`),
UNIQUE KEY `USER_NAME` (`USER_NAME`),
KEY `MOBILE` (`MOBILE`),
KEY `IDX_MOBILE_TGC` (`MOBILE_TGC`,`ID`),
KEY `IDX_EMAIL` (`EMAIL`,`ID`),
KEY `IDX_CREATE_DATE` (`CREATE_DATE`,`ID`),
KEY `IDX_UPDATE_DATE` (`UPDATE_DATE`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=' User table ';Two 、500w Level data test
# Self increasing id Table for primary key
mysql> select count(1) from UC_USER;
+----------+
| count(1) |
+----------+
| 5720112 |
+----------+
1 row in set (0.00 sec)
# uuid Table for primary key
mysql> select count(1) from UC_USER_PK_VARCHAR_1;
+----------+
| count(1) |
+----------+
| 5720112 |
+----------+
1 row in set (1.91 sec)2.1 entry 500W data , Self increasing ID Save half the disk space
In terms of the space capacity occupied , Self increasing ID Than UUID Less than half .

2.2 Single data is indexed , Self increasing id and uuid Little difference

2.3 Range like Inquire about , Self increasing ID Better performance than the UUID

2.4 Write test , Self increasing ID yes UUID Of 4 times

2.5、 Backup and recovery , Self increasing ID Better performance than the UUID

500W summary
stay 500W Under the test of the record sheet :
(1) Ordinary single or 20 Search about records ,uuid For the primary key, the difference is small, and the efficiency is almost the same ;
(2) But the range query, especially the query of hundreds of records , Self increasing id Is more efficient than uuid;
(3) During range query and statistical summary , Self increasing id Is more efficient than uuid;
(4) On top of the storage , Self increasing id The storage space occupied is uuid Of 1/2;
(5) On backup recovery , Self increasing ID The primary key is slightly better than UUID.
1000W summary
stay 1000W Under the test of the record sheet :
(1) Ordinary single or 20 Search about records , The self increasing primary key efficiency is uuid Primary key 2 To 3 times ;
(2) But the range query, especially the query of hundreds of records , Self increasing id Is more efficient than uuid;
(3) During range query and statistical summary , Self increasing id The efficiency of primary keys is uuid Primary key 1.5 To 2 times ;
(4) On top of the storage , Self increasing id The storage space occupied is uuid Of 1/2;
(5) On the write , Self increasing ID The efficiency of primary keys is UUID Primary key 3 To 10 times , The difference is obvious , especially update Data in a small range .
(6) On backup recovery , Self increasing ID The primary key is slightly better than UUID.
Self increasing ID Primary key + step , Suitable for medium-sized distributed scenarios
In each cluster node group master above , Set up (auto_increment_increment), Stagger the starting points of each cluster 1, The step size selection is greater than the number of cut diversity groups that are basically impossible to achieve in the future , Reach will ID Relative segmentation effect to meet Globally unique The effect of .
Advantage is : Implement a simple , Later maintenance is simple , Transparent to applications .
The disadvantage is that : The first setting is relatively complex , Because we need to calculate enough step length for the future business development ;
UUID, Suitable for small-scale distributed environment
about InnoDB For engines that aggregate primary key types , The data is sorted by primary key , because UUID The disorder of ,InnoDB It's going to produce huge IO pressure , And because indexes and data are stored together , String as primary key will double the storage space .
When storing and retrieving ,innodb The primary key will be physically sorted , This is right auto_increment_int It's good news , Because the primary key position of the last insertion is always at the end .
But yes. uuid Come on , This is bad news , because uuid It's messy , The primary key position of each insert is uncertain , Maybe at the beginning , Or in the middle , During physical sorting of primary keys , It is bound to cause a lot of IO Operation affects efficiency , When the amount of data keeps growing , Especially when there are tens of millions of records , The reading and writing performance is declining very severely .
advantage : It's easy to build , There is no need to handle the uniqueness of the primary key .
shortcoming : Take up twice the storage space ( It takes more money to store one piece in the cloud 2 Times the money ), In the later stage, the reading and writing performance declines sharply .
source :blog.csdn.net/qq_30108237/article/details/106856051
recommend
Technical involution group , Learn together !!

PS: Because the official account platform changed the push rules. , If you don't want to miss the content , Remember to click after reading “ Looking at ”, Add one “ Star standard ”, In this way, each new article push will appear in your subscription list for the first time . spot “ Looking at ” Support us !

边栏推荐
- Interceptors and filters
- day 1
- Getaverse,走向Web3的远方桥梁
- Mysql8.0 learning record 20 - trigger
- Sword finger offer 48. the longest substring without repeated characters
- Taokeeper environment setup
- Look at the interface control devaxpress WinForms - how to customize auxiliary function properties (Part 2)
- First knowledge database
- Reading notes: you only look once:unified, real time object detection
- Detailed explanation of the relationship between MySQL tables
猜你喜欢

Leetcode652 finding duplicate subtrees

Day 10 (inheritance, rewriting and use of super)

【德味】安全:如何为行人提供更多保护

Hold the C pointer

Biopharmaceutical safety, power supply and production guarantee
![2019 Hangdian multi school first 6581 vacation [thinking]](/img/38/5a74d3ef346d6801f9da8fd3a4b23a.png)
2019 Hangdian multi school first 6581 vacation [thinking]

Common methods of string class

Description of large and small end mode

The ark compiler is coming. What about APK reinforcement

Sword finger offer 52. The first common node of the two linked lists
随机推荐
Sword finger offer 46. translate numbers into strings
[Huawei lyevk-3861a intelligent IOT development board evaluation] unpacking experience and Hisilicon hi3861v100 chip learning experience
Siyuan notes V2.1.2 synchronization problem
Profile environment switching
MySQL version 5.7.9 SQL_ mode=only_ full_ group_ By question
PostgreSQL Elementary / intermediate / advanced certification examination (7.16) passed the candidates' publicity
Virbox compiler, which supports source code encryption of the whole platform and architecture
[understanding of opportunity-49]: three seasons and cognitive dimension
Create a life cycle aware MVP architecture
Unity2d~ game practice of decrypting Zhou mu (completed in three days)
Pyhanlp installation tutorial
Leetcode652 finding duplicate subtrees
Codeforces round 580 (Div. 2) c- almost equal [Law]
Solutions to oom caused by pictures in res directory
C language implementation of raii
Machine learning_ Softmax function (multi classification problem)
Channel state information (CSI) conjugate multiplication denoising method
mysql排序.按字段值排序
纯C实现----------尼科彻斯定理
Getting started with COM programming 1- creating projects and writing interfaces