当前位置:网站首页>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
边栏推荐
猜你喜欢

期末周,我裂开

How to realize multi account login of video platform members

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

C實現貪吃蛇小遊戲

Notes and notes

Matlab remainder

How to avoid JVM memory leakage?

Appium foundation - appium installation (II)

分布式CAP理论

雲原生——上雲必讀之SSH篇(常用於遠程登錄雲服務器)
随机推荐
Functions in C language (detailed explanation)
Bicolor case
Mysql 45讲学习笔记(十三)表数据删掉一半,表文件大小不变
What is the "relative dilemma" in cognitive fallacy?
What is a spotlight effect?
Mysql 45讲学习笔记(六)全局锁
tars源码分析之7
《ClickHouse原理解析与应用实践》读书笔记(4)
4G wireless all network solar hydrological equipment power monitoring system bms110
C实现贪吃蛇小游戏
InputStream/OutputStream(文件的输入输出)
uniapp 自定義環境變量
How to use multithreading to export excel under massive data? Source code attached!
tars源码分析之1
ABCD four sequential execution methods, extended application
Abap:ooalv realizes the function of adding, deleting, modifying and checking
颈椎、脚气
Tar source code analysis 8
Download kicad on Alibaba cloud image station
C language exercises (recursion)