当前位置:网站首页>How MySQL optimizes the use of joint index ABC
How MySQL optimizes the use of joint index ABC
2022-06-13 05:46:00 【Coffee is not bitter**】
Catalog
mysql I have talked about the classification and application of indexes before mysql Index application This article is mainly aimed at the joint index abc To carry out practical operation instructions .
Everybody wants to find employees The data package can be viewed from the above link blog .
One 、 Data background
Create a federated index abc
Indexed type as well as length as follows :
Two 、key-len Calculation rules for Columns
3、 ... and 、SQL Perform the test
1)sql perform a,b,c Fields exist
1>abc perform
explain select * from employees where
uid
=4 andfirst_name
=“Cristinel” andlast_name
=“Haddadi”
type by ref, Prove that the index is gone ,key_len=42, We can calculate that .uid Of type by bigint, So is 8 Bytes .first_name and last_name Are all varchar The type is n+2, That is to say 14+2+16+2=34+8=42.
explain select * from employees where
first_name
=“Cristinel” anduid
=“4” andlast_name
=“Haddadi”
explain select * from employees where
uid
=“4” andlast_name
=“Haddadi” andfirst_name
=“Cristinel”
key_len All are 42, So we all went to the full index
2)sql perform a,b,c Some index fields are query criteria
1>ac perform
explain select * from employees where
uid
=“4” andlast_name
=“Haddadi”We found that key_len=8, That is, only uid Indexes ,last_name The index is not valid .
2> ba perform
explain select * from employees where
first_name
=“Cristinel” anduid
=“4”
We calculate key_len The calculation shows that ,14+2+8=24, He walked two indexes ,ab It's all used .
3) For conditions , Optimized index
I once met such a problem , Two query statements need to be satisfied
select * from A where a=a and b=b and c=c;
select * from A where a=a and c=c;
How to build an index ?
Well, if we continue a,b,c The statement is definitely not satisfied 2 It's all indexed . So let's change , Change it to a,c,b Indexes can meet the above two requirements .
Pictured above , I reset an index a,c,b Pattern , Through the above test, we can determine that the above statement is satisfied .
1>a,b,c perform
explain select * from employees where
uid
=“4” andfirst_name
=“Cristinel” andlast_name
=“Haddadi”
2>a,c perform
explain select * from employees where
uid
=4 andlast_name
=“Haddadi”
key_len:16+2+8=26, Indexes are used .
Four 、 summary
Leftmost prefix principle , From the above we can conclude that , As long as the fields of join and index participate in the query , So whatever the sequence , All of them can be indexed directly .
If there are too many indexes in the table , It will affect INSERT And UPDATE performance , Simply put, it will affect the data writing performance . Because while updating the data , Also update the index at the same time .
So it can complete the work with an index , It is definitely not recommended to establish two .
边栏推荐
- ZABBIX proxy, sender (without agent monitoring), performance optimization
- Top slide immersive dialog
- 2021.9.29学习日志-Restful架构
- JS output uincode code
- Working principle of sentinel series (concept)
- First assessment
- Some methods of string
- 890. Find and Replace Pattern
- Error: unmapped character encoding GBK
- The 13th week of the second semester of sophomore year
猜你喜欢
How to Algorithm Evaluation Methods
powershell优化之一:提示符美化
890. Find and Replace Pattern
OpenGL mosaic (VIII)
2021.9.30学习日志-postman
Sentinel series hot spot current limiting
Validation set: ‘flowable-executable-process‘ | Problem: ‘flowable-servicetask-missing-implementatio
Timeout thread log for tongweb
MySQL fuzzy query and sorting by matching degree
MySQL transactions and foreign keys
随机推荐
About Evaluation Metrics
零拷贝技术
Compilation croisée helloworld avec cmake
MySQL installation in Linux Environment
Windbos common CMD (DOS) command set
Small project - household income and expenditure software (2)
How to Algorithm Evaluation Methods
Current limiting and fusing of gateway gateway in Spirng cloud
Config server configuration center of Nacos series
Mongodb Multi - field Aggregation group by
设置自定义dialog的正确宽高
MySQL fuzzy query and sorting by matching degree
2021.9.29 learning log restful architecture
12 error end event and terminateendevent of end event
How to Algorithm Evaluation Methods
About the solution of pychart that cannot be opened by double clicking
2021.9.30 learning log -postman
Building Nacos 2 based on docker compose (using MySQL for persistence)
OpenGL馬賽克(八)
Byte buddy print execution time and method link tracking