什么是Mysql最左匹配
假设T表是有a,b,c三个字段的联合索引表。
那么下面能用索引的查询是1,4。
Select * From T Where a=1 and b=2 and c=3
Select * From T Where b=2 and c=3
Select * From T Where c=3
Select * From T Where b=2 and c=3 and a=1
Select * From T Where b>1
解释:
最左匹配指的是创建的索引字段最左边的字段必须在查询中存在,就能直接使用该联合索引。
当然如果是只用到了部分联合索引的字段,查询时,mysql也有一定的条件优化:索引下推-Using index condition