What's mysql's "BETWEEN" performance over..?

Daveel picture Daveel · Dec 8, 2010 · Viewed 23.4k times · Source

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?

Answer

tpdi picture tpdi · Dec 8, 2010

As I recall, there's no difference. But see for yourself if:

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

and:

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

produce the same plans.