MySQL “IN” operator performance on (large?) number of values

后端 未结 6 762
囚心锁ツ
囚心锁ツ 2020-11-28 03:26

I have been experimenting with Redis and MongoDB lately and it would seem that there are often cases where you would store an array of id\'s in either Mongo

6条回答
  •  心在旅途
    2020-11-28 03:48

    Using IN with a large parameter set on a large list of records will in fact be slow.

    In the case that I solved recently I had two where clauses, one with 2,50 parameters and the other with 3,500 parameters, querying a table of 40 Million records.

    My query took 5 minutes using the standard WHERE IN. By instead using a subquery for the IN statement (putting the parameters in their own indexed table), I got the query down to TWO seconds.

    Worked for both MySQL and Oracle in my experience.

提交回复
热议问题