当前位置:网站首页>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
边栏推荐
- Software keywords and process information intercepted by Golden Shield video player
- Variables d'environnement personnalisées uniapp
- tars源码分析之1
- Learning multi-level structural information for small organ segmentation
- Mysql 45讲学习笔记(十三)表数据删掉一半,表文件大小不变
- InputStream/OutputStream(文件的输入输出)
- C實現貪吃蛇小遊戲
- How to implement cross domain requests
- Common usage of time library
- C实现贪吃蛇小游戏
猜你喜欢

Can the out of sequence message complete TCP three handshakes

Fundamentals of SQL database operation

Native Cloud - SSH articles must be read on Cloud (used for Remote Login to Cloud Server)

2022 Xinjiang's latest eight members (Safety Officer) simulated examination questions and answers

centos8安装mysql.7 无法开机启动

如何实现视频平台会员多账号登录

Learning multi-level structural information for small organ segmentation

Sleep quality today 78 points

Tree DP

Another company raised the price of SAIC Roewe new energy products from March 1
随机推荐
The sorting in C language realizes the number sorting method from small to large
对List进行排序工具类,可以对字符串排序
MySQL installation and configuration
2022.7.3-----leetcode. five hundred and fifty-six
树形dp
R统计绘图-随机森林分类分析及物种丰度差异检验组合图
tars源码分析之10
Arcpy uses the updatelayer function to change the symbol system of the layer
手动对list进行分页(参数list ,当前页,页面大小)
Distributed cap theory
Data analysis notes 09
tcp socket 的 recv 如何接收指定长度消息?
微信小程序使用rich-text中图片宽度超出问题
The width of the picture in rich text used by wechat applet exceeds the problem
Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage
leetcode 310. Minimum Height Trees
How to help others effectively
Background and current situation of domestic CDN acceleration
Can the out of sequence message complete TCP three handshakes
What is a spotlight effect?