当前位置:网站首页>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 .
边栏推荐
猜你喜欢
随机推荐
公司視頻加速播放
leaflet 地图
CoordinatorLayout+NestedScrollView+RecyclerView 上拉底部显示不全
2022 software testing workflow to know
Digital triangle model acwing 1015 Picking flowers
【API接口工具】postman-界面使用介绍
Redis 核心技术与实战之 基本架构:一个键值数据库包含什么?
误差的基本知识
数学三大核心领域概述:几何
isam2运行流程
Pat (Grade B) 2022 summer exam
Clock in during winter vacation
Linux regularly backs up MySQL database
曼哈顿距离与曼哈顿矩形-打印回字型矩阵
【Postman】Monitors 监测API可定时周期运行
Seven imperceptible truths in software testing
Buuctf-[[gwctf 2019] I have a database (xiaoyute detailed explanation)
Investment strategy discussion and market scale prediction report of China's solid state high power amplifier industry from 2022 to 2028
Gtest之TEST宏的用法
ContentType的作用









![[Thesis code] SML part code reading](/img/3c/0deccf499d9b1cbe30a302cb115d73.png)