当前位置:网站首页>MySQL 45 learning notes (XI) how to index string fields
MySQL 45 learning notes (XI) how to index string fields
2022-07-04 06:37:00 【Tom Kong】
One . Prefix index
- MySQL Support prefix index , Sure Define part of the string Do the index
- Create an index statement Do not specify prefix length , that The index will contain the entire string
Two . How long prefix to use
Use prefix index , Define the length , Sure Save space , Don't add too many additional queries cost .
- Focus on the differentiation when building the index , The higher the discrimination, the better
- The more distinguishable , signify The fewer duplicate key values
- We can How many different values are there in the statistical index To determine how long prefix to use
Example : Count the differentiation of different fields with different lengths
select
count(distinct left(email,4))as L4,
count(distinct left(email,5))as L5,
count(distinct left(email,6))as L6,
count(distinct left(email,7))as L7,
from SUser;
3、 ... and . The influence of prefix index on overlay index
- If it is a full string , If the index coverage is supported, the table will not be returned .
- If it's just a part of a string , The system still depends on id Look back at the index , Because the system is not sure whether the prefix index definition truncates the complete information .
The longer the index , The more disk space it takes up , The smaller the index value that can be placed on the same data page , The less efficient the search .
Four . ID card scenario ( The front of the field should be highly differentiated from the back )
- Use flashback storage , If you turn them upside down when storing ID number
- Use hash Field
Use Flashback storage and Use hash Field The similarities and differences between the two methods
The same thing
- Range queries are not supported
Difference
- In terms of the extra space occupied , Flashbacks are stored in the primary key index , No additional storage is consumed
- hash Field method needs to add a field
CPU Consumption :
- The flashback method needs an additional call reverse function
- hash Field requires an additional call to the hash function ,reverse Function extra consumption CPU Resources will be smaller
The query efficiency :
- hash The query performance of field mode is relatively stable . because crc32 The calculated values have the probability of conflict , But the probability is very small
- After all, the reverse storage method is still the prefix index method , In other words, it will increase the number of scanning lines
边栏推荐
- 运算符<< >>傻瓜式测试用例
- Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage
- Background and current situation of domestic CDN acceleration
- Summary of leetcode BFS question brushing
- QT get random color value and set label background color code
- Learning multi-level structural information for small organ segmentation
- 云原生——上云必读之SSH篇(常用于远程登录云服务器)
- tars源码分析之4
- Redis面试题集
- STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
猜你喜欢
Cloud native - SSH article that must be read on the cloud (commonly used for remote login to ECS)
[untitled]
centos8安装mysql.7 无法开机启动
Reading notes of Clickhouse principle analysis and Application Practice (4)
After the festival, a large number of people change careers. Is it still time to be 30? Listen to the experience of the past people
Variables d'environnement personnalisées uniapp
How to use multithreading to export excel under massive data? Source code attached!
List of top ten professional skills required for data science work
Json Web token - jwt vs. Traditional session login Authentication
198. House raiding
随机推荐
颈椎、脚气
Explain in one sentence what social proof is
Learning multi-level structural information for small organ segmentation
What is tweeman's law?
Matlab remainder
Uniapp custom environment variables
Overview of convolutional neural network structure optimization
The width of the picture in rich text used by wechat applet exceeds the problem
Appium foundation - appium installation (II)
Native Cloud - SSH articles must be read on Cloud (used for Remote Login to Cloud Server)
Summary of leetcode BFS question brushing
tars源码分析之6
The sorting in C language realizes the number sorting method from small to large
Arcpy 利用updatelayer函数改变图层的符号系统
Inputstream/outputstream (input and output of file)
What is the "relative dilemma" in cognitive fallacy?
微信小程序使用rich-text中图片宽度超出问题
采用中微BATG135实现IIC数据/指令交互
【MySQL】数据库视图的介绍、作用、创建、查看、删除和修改(附练习题)
【问题记录】03 连接MySQL数据库提示:1040 Too many connections