MYSQL OR vs IN performance

后端 未结 14 1006
一向
一向 2020-11-22 04:12

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 ..         


        
14条回答
  •  醉梦人生
    2020-11-22 04:52

    I also did a test for future Googlers. Total count of returned results is 7264 out of 10000

    SELECT * FROM item WHERE id = 1 OR id = 2 ... id = 10000
    

    This query took 0.1239 seconds

    SELECT * FROM item WHERE id IN (1,2,3,...10000)
    

    This query took 0.0433 seconds

    IN is 3 times faster than OR

提交回复
热议问题