Is there a performance difference between using a BETWEEN clause or using <= AND >= comparisons?
i.e. these two queries:
SELECT *
FROM table
There is no performance difference between the two example queries because BETWEEN
is simply a shorthand way of expressing an inclusive range comparison. When Oracle parses the BETWEEN
condition it will automatically expand out into separate comparison clauses:
ex.
SELECT *
FROM table
WHERE column BETWEEN :lower_bound AND :upper_bound
...will automatically become:
SELECT *
FROM table
WHERE :lower_bound <= column
AND :upper_bound >= column
It may be worth considering the SQL standard for this (although this might not correspond to all implementations, even if it should):
Format
<between predicate> ::=
<row value constructor> [ NOT ] BETWEEN
<row value constructor> AND <row value constructor>
Syntax Rules
[...]
6) "X BETWEEN Y AND Z" is equivalent to "X>=Y AND X<=Z".
Having said so, there is no difference in behaviour, although for complex X
, there may be a difference in parsing time, as mentioned by Benoit here
Found in http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt