MYSQL OR vs IN performance

2018-12-31 06:34发布

I am wondering if there is any difference in regards to performance between the following

SELECT ... FROM ... WHERE someFIELD IN(1,2,3,4)

SELECT ... FROM ... WHERE someFIELD between  0 AND 5

SELECT ... FROM ... WHERE someFIELD = 1 OR someFIELD = 2 OR someFIELD = 3 ... 

or will MySQL optimize the SQL in the same way compilers will optimize code ?

EDIT: Changed the AND's to OR's for the reason stated in the comments.

13条回答
倾城一夜雪
2楼-- · 2018-12-31 07:33

2018: IN is faster. But >= && <= is even faster than IN.

Here's my benchmark.

查看更多
登录 后发表回答