explain组合索引是否命中

新建组合索引

alter table table1 add index col_index(col1, col2, col3);

查询:组合查询有向左匹配规则

使用查询

select * from table1 where col1='1';//使用索引

select * from table1 where col1='1' and col2 = '2'; 使用索引

select * from table1 where col1='1' and col2 = '2' and col3= '3';// 使用索引

//有 or 条件不是用索引

select * from table1 where col1='1' or col2='2' ;//不使用索引

select * from table1 where col1='1' and col2='2' or col3 = '3';//不使用索引;

//有like的条模糊查询没使用索引,后模糊查询使用索引

select * from table1 where col1 like '1%'; //使用索引

select * from table1 where col1 like '%1'; //不使用索引

//有 > 或者 < 的都不使用索引

//select * from table1 where col1 > 12 ; //不实用索引

原文地址:https://www.cnblogs.com/wxdr/p/13528050.html