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

发布于 2022-09-06 02:16:35 字数 631 浏览 14 评论 0

当查询为:
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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暗恋未遂 2022-09-13 02:16:35

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

动听の歌 2022-09-13 02:16:35

理论上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!=''
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文