English 中文(简体)
我的“BETWEEN”表现如何?
原标题:What s mysql s "BETWEEN" performance over..?

Is there any better performance when querying in (particularly) mysql of the following:

SELECT * FROM `table` WHERE `unix_date` BETWEEN 1291736700 AND 1291737300

页: 1

SELECT * FROM `table` WHERE `unix_date` >= 1291736700 AND `unix_date` <= 1291737300

或BETWEEN syntax刚改为第二 s?

最佳回答

我记得,没有区别。 但是,如果:

explain plan for 
SELECT * FROM `table` WHERE `unix_date` BETWEEN 1291736700 AND 1291737300

并且

explain plan for
SELECT * FROM `table` WHERE `unix_date` >= 1291736700 AND `unix_date` <= 1291737300

编制同样的计划。

问题回答

http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_between”rel=“noreferer” 文件:

  • expr BETWEEN min AND max

如果expr大于或等于minexpr小于或等于max>,则BETWEEN返回1,否则就返回。 页: 1 如果所有论点都是相同的。 否则,转换类型是根据第11.2节“Type换算成表达评价”所述规则进行的,但适用于所有三个论点。

因此,这实际上只是 s糖。

<>BETWEEN显示了更明确的意图,并读得更好(一些图表)。

以下三份声明将产生同样的结果:

  1. i BETWEEN x AND y
  2. x <= i AND i <= y
  3. i >= x AND i <= y

但是,在第3组中,我的sql可能(取决于你的指数)使用不同的指数:秩序似乎很重要,但你应当与EXPLAIN的询问一起测试,了解差异。 它也可能根据MySQL的版本而改变。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签