MySQL Test Optimization "WHERE (X = 0 or X = 1)" versus "WHERE X <2"

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 |
+----+-------------+---------+------+---------------+------+---------+------+---------+-------------+
+3
source share
4 answers

Use SQL_NO_CACHE:

SELECT SQL_NO_CACHE id FROM mytable where x<2
+2
source

, , . .

, . A B A,B,A,B,A,B,A,B,A,B .

( MySQL) , .

, id , .


, EXPLAIN . , , .

, , ( ), x. , , ( x, , , ).

+1

EXPLAIN.

, .


, EXPLAIN , - ( " " "NULL", .) x .

+1

, ? . , , .

, 0, .

:

SELECT id FROM mytable WHERE x BETWEEN 0 AND 1

, , , .

, , , , , . , , , .

+1
source

All Articles