Is there a performance advantage for deleting OR statements?
Which compiles faster
SELECT id FROM mytable where (x=0 or x=1)
or
SELECT id FROM mytable where x<2
I did the test myself, and the second is a little faster. BUT I am not sure if this is due to caching that occurs when I run the first command. Is there a good way to evaluate two competing requests without caching them and affecting others?
EXPLAIN produces the same output:
+----+-------------+---------+------+---------------+------+---------+------+---------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+---------+------+---------------+------+---------+------+---------+-------------+ | 1 | SIMPLE | mytable | ALL | NULL | NULL | NULL | NULL | 1407715 | Using where | +----+-------------+---------+------+---------------+------+---------+------+---------+-------------+
Use SQL_NO_CACHE:
SELECT SQL_NO_CACHE id FROM mytable where x<2
, , . .
, . A B A,B,A,B,A,B,A,B,A,B .
A
B
A,B,A,B,A,B,A,B,A,B
( MySQL) , .
, id , .
id
, EXPLAIN . , , .
, , ( ), x. , , ( x, , , ).
x
EXPLAIN.
, .
, EXPLAIN , - ( " " "NULL", .) x .
, ? . , , .
, 0, .
:
SELECT id FROM mytable WHERE x BETWEEN 0 AND 1
, , , .
, , , , , . , , , .