首页 > 数据库技术 > 详细

mysql何时使用组合索引

时间:2020-07-03 11:54:20      阅读:84      评论:0      收藏:0      [点我收藏+]

create table test(
  id1 int ,
  id2 int,
  id3 int,
  id4 int,
  key index_id12(id1,id2)
);

用到索引
explain select * from test where id1 < 10;
用到索引
explain select * from test where id1 < 10 and id2 > 1;
用到索引
explain select * from test where id2 > 1 and id1 < 2;

用到索引
explain select id1 from test order by id1 desc ;
explain select id1,id2 from test order by id1 desc ;

 

未用到索引

explain select * from test order by id1 desc ;

未用到索引
explain select * from test where id2 > 1;
未用到索引
explain select * from test order by id1 desc ;
未用到索引
explain select id1,id2,id3 from test order by id1 desc ;

 

组合索引与order by的相互使用影响不是很熟悉,求大神留言解答

mysql何时使用组合索引

原文:https://www.cnblogs.com/lzghyh/p/13229170.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!