当前位置:网站首页>MySQL autoincrement ID, UUID and snowflake ID
MySQL autoincrement ID, UUID and snowflake ID
2022-07-19 11:13:00 【The clouds are idle】
The concept is introduced
Three primary keys
Self increasing id :1 2 3 4 5……
uuid :UUID yes Universally Unique Identifier Abbreviation , It is within a certain range ( From a specific namespace to the world ) Unique machine generated identifier . The meaning of universal unique identifier , It can be based on business practice user id Primary key such as QQ Number Phone number etc.
snow id : comparison UUID Disorderly id for , The snowflake algorithm is ordered ( With time parameters ), And they are all composed of numbers . snow id The maximum is 64 position , accord with java in long The length of 64 position . Suitable for large-scale distributed
Clustered index and non clustered index
Self increasing id
The values of the self increasing primary key are sequential , therefore Innodb Store each record at the end of a record . When the maximum fill factor of the page is reached (innodb The default maximum fill factor is page size 15/16, Will be set aside 1/16 Space for future modify ):
① The next record will be written to the new page , Once the data is loaded in this order , The primary key page will be almost filled with records in sequence , Improved the maximum fill rate of the page , There will be no waste of pages
② The newly inserted row must be next to the original maximum data row ,mysql Location and addressing are fast , There is no additional cost to calculate the position of the new row
③ Reduced page fragmentation and fragmentation
advantage :
1. Self increasing , The trend is self increasing , It can be used as a clustered index , Improve query efficiency
2. Save disk space .500W data ,UUID Occupy 5.4G, Self increasing ID Occupy 2.5G.
3. Inquire about , High write efficiency : The query is slightly better . When there is a large amount of data higher than uuid Insertion speed
shortcoming :
1. When importing old data , May be ID repeat , Causes the import to fail .
2. Distributed architecture , Multiple Mysql Instances may lead to ID repeat .
3. Easy to be broken by the outside , Know the actual situation of the business . And for example : Show the announcement index?id=3 In this way, it is easy to be tampered with as index?id=2. You can adjust to the content of Article 2 .
4 For high concurrency loads ,innodb When inserting by primary key, there will be obvious lock contention , The upper bound of the primary key will become a hot topic of contention , Because all the insertions happen here , Concurrent inserts can lead to gap lock contention .Auto_Increment The lock mechanism will cause the preemption of self increasing lock , There is a certain loss of performance
uuid
Look at the shortcomings above
snow id
边栏推荐
- Nombre d'entrées nombre d'entrées numériques pures limite de longueur maximale
- vSphere 下借助 vDS 或 NSX 做端口镜像的方法总结
- Svn learning
- Integrated network architecture and network slicing technology of air, earth and sea
- Tencent cloud server uses image to deploy WordPress personal website!
- input number 純數字輸入 限制長度 限制 最大值
- Getting started with web security - deploy snort open source ids/ips system
- CodeForces - 587E(线性基+线段树+差分)
- The difference between journal log and oplog log
- Over fitting and under fitting
猜你喜欢
XSS.haozi.me刷题
Category imbalance in classification tasks
Four methods of traversing key value in map
Mobile keyboard (simulation question)
(2) Using MySQL
web安全入门-部署Snort开源IDS/IPS系统
How to build dashboard and knowledge base in double chain note taking software? Take the embedded widget library notionpet as an example
Deep Learning for Generic Object Detection: A Survey-论文阅读笔记
How much money can you make by inventing flash memory? This is a Japanese dog blood story
antd 下拉多选传值到后台做查询操作
随机推荐
Accident caused by the combination of annotation transaction + distributed lock at the read committed level -- disorder of activity purchase opportunities
Game theory (Depu) and investment (40/100)
LeetCode 558. Intersection of quadtree
Evaluation method of machine learning model
LeetCode 2249. Count the number of grid points in the circle
Unity3d 读取mpu9250 例子原代码
PowerCLI 脚本性能优化
Pytoch realizes multi-layer perceptron manually
Introduction to the universal theme system of SAP appgyver
2022/7/15
要想组建敏捷团队,这些方法不可少
(2) Using MySQL
Antd drop-down multiple options to transfer values to the background for query operations
[in vivado middle note ILA IP core]
Some methods of early MCU encryption [get data in the comment area]
466-82(3、146、215)
mpu9250 ky9250姿态、角度模块和mpu9250 mpl dma对比
如何在 RHEL 9 中更改和重置忘记的root密码
input number 纯数字输入 限制长度 限制 最大值
Win10的环境变量配置