对时间字段 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‘;
这时又使用了索引,说明时间字段 使用大于 时是否使用索引 是和结果的数量有关的,当数量较少(网上查到是有一个比例)时时使用索引的。
关于mysql where 时间字段 大于 小于是否使用索引
原文:https://www.cnblogs.com/zhangchenglzhao/p/11187494.html