查询时间加大,索引不生效

新手上路,请多包涵

当查询为:
explain select mail from client_login_logs where create_time>='2017-10-11' and create_time<='2017-10-21' and device_type=5 and mail!=''
结果为:
clipboard.png

当查询的日期增加一天,如下:
explain select mail from client_login_logs where create_time>='2017-10-11' and create_time<='2017-10-22' and device_type=5 and mail!=''
结果为

clipboard.png

阅读 4.7k
2 个回答

idx_cdate_dtype_staus 这个索引列存在空值。
建议加上cdate_dtype_staus!=null

理论上mysql自己会选择成本最低的执行计划,如果人工确认使用索引更合适,可以通过hints强制使用索引

SELECT *
FROM client_login_logs 
USE INDEX (idx_create_dtype_status) 
WHERE reate_time>='2017-10-11' and create_time<='2017-10-21' and device_type=5 and mail!=''
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题