mysql 的“BETWEEN”是什么?性能超过..?
在(特别是)mysql 中查询以下内容时是否有更好的性能:
SELECT * FROM `table` WHERE `unix_date` BETWEEN 1291736700 AND 1291737300
over:
SELECT * FROM `table` WHERE `unix_date` >= 1291736700 AND `unix_date` <= 1291737300
或 BETWEEN 语法只是被第二个 sql 替换?
Is there any better performance when querying in (particularly) mysql of the following:
SELECT * FROM `table` WHERE `unix_date` BETWEEN 1291736700 AND 1291737300
over:
SELECT * FROM `table` WHERE `unix_date` >= 1291736700 AND `unix_date` <= 1291737300
or BETWEEN syntax is just being substituted with the second sql?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我记得,没有什么区别。但请亲自看看是否:
和:
制定相同的计划。
As I recall, there's no difference. But see for yourself if:
and:
produce the same plans.
来自文档:
所以它实际上只是语法糖。
From the documentation:
So it really is just syntax sugar.
BETWEEN
显示更清晰的意图并且可读性更好(SQL 打算这样做)。BETWEEN
shows clearer intent and reads better (something SQL set out to do).以下三个语句将产生相同的结果:
i BETWEEN x AND y
x <= i AND i <= y
i >= x AND i <= y
但在配置 3 中,mysql 可能(取决于您的索引)使用不同的索引:顺序似乎很重要,但您应该使用 EXPLAIN 查询进行测试以了解差异。它也可能会根据 MySQL 的版本而变化。
The following three statements will produce the same result:
i BETWEEN x AND y
x <= i AND i <= y
i >= x AND i <= y
But in configuration 3 mysql might (depending on your indexes) use different indexes: order seems to matter but you should be testing with EXPLAIN query to understand the difference. It might also change depending on the version of MySQL.