当前位置:网站首页>Left matching principle of joint index
Left matching principle of joint index
2022-07-06 06:14:00 【Snow peak expensive】
Joint index :
key : ‘index_name_age’(‘name’,‘age’)
scene :
case1:
select * from person_info where name='gxf' and age = '18';
At this time, I will go index_name_age Joint index .
case2:
select * from person_info where name='gxf' ;
At this time, I will go index_name_age Joint index .
case3:
select * from person_info where age = '18';
here Not going index_name_age Joint index . Will scan the whole table .
Be careful
1. Left most prefix The matching principle
mysql Will match all the way to the right Until I met > 、< 、 between 、like Just stop matching .
where a=1 and b=2 and c=3 and d>4;
If set up index(a,b,d,c) be c There is no index .
If set up index(a,b,c,d) Are available to the index .
If set up index(b,c,a,d) Are available to the index .
2.= and in
You can order
If set up index(a,b,c,d).
where a=1 and b=2 and c=3 and d in(4,5);
where a=1 and d in(4,5) and b=2 and c=3 ;
All can be indexed , because mysql Will optimize your SQL Adjust the order to use the index .
Why? case3 Do not go through the joint index :

hypothesis : Now there is a joint index index(col3,col2);
be , There will be one stored in the joint index file B+ Trees , Leaf nodes store two Alice Row data , And on this basis , According to col2 Sort . final result :34 Of Alice It's in line 77 Of Alice In front of .
Now? where col3 = ‘Alice’ and col2=34; Then the leaf node will be found first , I'll find it again 34. That's the index .
if where col2 = 34; Then the joint index file is saved B+ The tree is useless . That is, you can't go through the index .
边栏推荐
- (中)苹果有开源,但又怎样呢?
- 对数据安全的思考(转载)
- LeetCode 731. 我的日程安排表 II
- IP day 16 VLAN MPLS configuration
- Cognitive introspection
- Amazon Engineer: eight important experiences I learned in my career
- [wechat applet] build a development tool environment
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- 数据库-当前读与快照读
- HCIA review
猜你喜欢
随机推荐
Bit operation rules
公司视频加速播放
联合索引的左匹配原则
What are the test sites for tunnel engineering?
全链路压测:构建三大模型
Caused by:org. gradle. api. internal. plugins . PluginApplicationException: Failed to apply plugin
Application du Groupe Li dans gtsam
[API interface tool] Introduction to postman interface
【无App Push 通用测试方案
对数据安全的思考(转载)
数学三大核心领域概述:几何
selenium源码通读·9 |DesiredCapabilities类分析
Buuctf-[bjdctf2020]zjctf, but so (xiaoyute detailed explanation)
nodejs实现微博第三方登录
MPLS test report
Thoughts on data security (Reprint)
使用Nacos管理配置
Function of contenttype
把el-tree选中的数组转换为数组对象
功能安全之故障(fault),错误(error),失效(failure)









