explain组合索引是否命中

时间:2020-08-19 12:49:01   收藏:0   阅读:180

新建组合索引

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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!