赞
踩
以下针对数据库存储引擎为InnoDB来说,假设针对字段a、b、c建立联合索引。
1、为什么索引支持最左索引前缀原则,构建了几个B+树?
只有一个B+树,这个B+树的非叶子节点按 a、b、c值顺序构造,叶子节点包括索引项和主键的记录。如果进行 select a,b,c from table 查询是不用进行回表,直接可以从索引表中获得结果。
2、使用联合索引时需注意设置的索引是否被正确使用上,举例说明:
select * from table_name where a ='' and b='' and c=''; //走索引查询
select * from table_name where b='' and a ='' and c=''; //索引查询
select * from table_name where a ='' and b=''; //走索引查询
select * from table_name where a ='' and c=''; //走索引查询
select * from table_name where b='' and c=''; //全表扫描
select * from table_name where a<'' and c=''; //索引查询
select * from table_name where a between '' and ''; //索引查询
select * from table_name where a like 'A%'; //走索引查询
select * from table_name where a like '%A'//全表查询
select * from table_name where a like '%A%'//全表查询
select * from table_name where a='' and c>''; //索引查询
select * from table_name order by a,b,c; //索引查询
3、索引失效情况总结
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。