码迷,mamicode.com
首页 > 数据库 > 详细

MySQL是否使用索引实例

时间:2016-01-19 14:28:41      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

①使用组合索引(userName, userAge)  ②使用组合索引(userAge,userName)

1.select * from t_user where userName in (‘dd‘,‘gg‘)   在①下会使用索引  在②下不会使用索引 ;

2.select * from t_user where userAge=3     在①下不会使用索引  在②下会使用索引 ;

3.select * from t_user where userName like ‘saa%‘   在①下会使用索引 

4.select * from t_user where userName like ‘%saa%‘   在①不下会使用索引 

5.select * from t_user where userAge>3 (或between and )    在①②下都不会使用索引  在②下会使用索引 ;

6.采用UNION ALL操作符替代UNION,因为UNION ALL操作只是简单的将两个结果合并后就返回。而UNION会筛选掉重复的记录,所以在表链接后会对所产生的结果集进行排序运算,删除重复的记录再返回结果。

7.用>=替代>

 

MySQL是否使用索引实例

标签:

原文地址:http://www.cnblogs.com/jusanliusha/p/5141945.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!