关于mysql where 时间字段 大于 小于是否使用索引

时间:2019-07-15 11:16:36   收藏:0   阅读:1000

对时间字段 trans_date 添加普通索引。

使用where trans_date = ‘’  是肯定会使用索引的。

但是使用<  , > 比较符时就不一定了。

select count(1) from A; // 40000

EXPLAIN select * from A where trans_date = 20190428; 

技术分享图片

2. 使用> ,  查询语句没有使用索引

select count(1) from t_trans_log_info where trans_date > 20190428; //11200

EXPLAIN select * from t_trans_log_info where trans_date > 20190410;

技术分享图片

3. 

select count(1) from t_trans_log_info where trans_date > 20190528; //1120

EXPLAIN select * from t_trans_log_info where trans_date > 20190528;

技术分享图片

这时又使用了索引,说明时间字段 使用大于 时是否使用索引 是和结果的数量有关的,当数量较少(网上查到是有一个比例)时时使用索引的。 

 

原文:https://www.cnblogs.com/zhangchenglzhao/p/11187494.html

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