当前位置:网站首页>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 !

边栏推荐
- 拦截器和过滤器
- [in depth study of 4g/5g/6g topic -39]: urllc-10 - in depth interpretation of 3GPP urllc related protocols, specifications and technical principles -3- how to distinguish urllc services? Detailed expl
- Flink window & time principle
- 文献阅读:GoPose 3D Human Pose Estimation Using WiFi
- Unity2d~ game practice of decrypting Zhou mu (completed in three days)
- Zooinspector Download
- Feature extraction tool transformer Bert
- MySQL sort. Sort by field value
- Talk about your transformation test development process
- Hucang integrated release of full data value, sequoiadb V5.2 online conference heavy attack
猜你喜欢

【JVM学习04】JMM内存模型

Feature extraction tool transformer Bert

Literature reading: gopose 3D human pose estimation using WiFi

This visual analysis library makes it easy for you to play with data science!

In the spring of domestic databases

Meshlab & PCL ISS key points
![[JVM learning 04] JMM memory model](/img/8c/0f76be122556301a5af140e34b55f4.png)
[JVM learning 04] JMM memory model

How to encrypt your own program with dongle

Emergency lighting design of large stadiums and gymnasiums

Timed task framework
随机推荐
Convolutional neural network CNN
Common methods of string class
Process pool and fallback function [easy to understand]
How does PostgreSQL decide PG's backup strategy
Sword finger offer 42. maximum sum of continuous subarrays
思源笔记 v2.1.2 同步问题
Mysql8.0 learning record 19 - Page segments and tablespaces
Talk about your transformation test development process
Description of large and small end mode
First knowledge database
Analysis and Simulation of strlen function
Implement a proxy pool from 0
Oneinstack installation and configuration PHP 8.1 and MySQL 8.0-oneinstack site building novice tutorial
纯C实现----------尼科彻斯定理
How to select software dongle
Setting up a dual machine debugging environment for drive development (vs2017)
Introduction to WDK development 1- basic environment construction and the first driver (VS2010)
Integer
[laser principle and application -6]:q switching element and Q drive circuit board
[face to face experience of school recruitment] 8 real questions of pointer interview. Come and test how many you have mastered.