在 MySQL 中的日期字段上放置索引
将索引放在日期字段上对我来说是否有任何真正的好处,这些字段将主要用于使用诸如.
dateField < 'var'
搜索
'var' BETWEEN dateField1 AND dateField2
已经完成了很多,但我从来没有对它们进行直接比较“=”。
Is there going to be any real benefit to me putting indexes onto date fields that are going to be mainly used in queries using stuff like.
dateField < 'var'
And
'var' BETWEEN dateField1 AND dateField2
The searches get done a lot but I am never doing a direct comparison "=" on them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的当然。范围搜索将受益于索引,就像相等搜索一样。
引自 MySQL 参考手册:MySQL 如何使用索引:
在某些情况下,如果范围最终太大,优化器可能决定不使用索引,因为表扫描实际上可能更快。使用
EXPLAIN
查看哪个 (如果有)索引将用于您的查询。Yes of course. Range searches will benefit from an index, just as much as equality searches.
Quoting from the MySQL Reference Manual :: How MySQL Uses Indexes:
In some situations, the optimiser may decide not to use the index if the range will end up to be too big, as a table scan might actually be faster. Use
EXPLAIN
to see which (if any) indexes will be used on your query.