当前位置:网站首页>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 .
边栏推荐
- 安装harbor(在线|离线)
- 使用cmake交叉編譯helloworld
- Calculate the number of days between two times (supports cross month and cross year)
- Mongodb Multi - field Aggregation group by
- Dynamic programming - longest common substring
- JS output uincode code
- Comment procéder à l'évaluation des algorithmes
- Standard input dialog for pyqt5 qinputdialog
- No assessment summary
- Basic application of sentinel series
猜你喜欢

1 Introduction to drools rule engine (usage scenarios and advantages)

Byte buddy print execution time and method link tracking

Pychart error resolution: process finished with exit code -1073741819 (0xc0000005)

redis

powershell优化之一:提示符美化

Service architecture diagram of Nacos series
![[China & some provinces and cities] JSON file for offline map visualization](/img/ea/0c552e1e133f693b9902c54c2e09c8.jpg)
[China & some provinces and cities] JSON file for offline map visualization

890. Find and Replace Pattern

About Evaluation Metrics

Database design
随机推荐
Etcd fast cluster building
Jeffery0207 blog navigation
Error: unmapped character encoding GBK
Mongodb Multi - field Aggregation group by
通过命令行创建harbor镜像库
Qmessagebox in pyqt5
Service architecture diagram of Nacos series
10 signalstartevent and signalcatchingevent of flowable signal events
[China & some provinces and cities] JSON file for offline map visualization
Comment procéder à l'évaluation des algorithmes
Database design
Quartz basic use
Browser screenshot method (long screenshot, node screenshot, designated area screenshot)
设置自定义dialog的正确宽高
Windbos common CMD (DOS) command set
Problems encountered in the use of PgSQL
Find out the missing numbers from the natural numbers arranged in order from 0 to 100, and the solution provides
12 error end event and terminateendevent of end event
Explanation of service registration and discovery API of Nacos series
Basic operations of MySQL auto correlation query



We found that key_len=8, That is, only uid Indexes ,last_name The index is not valid .

