0

Is there any limit for a no. of value inside IN function of MySQL, Currently I am building social network and I am trying to fetch all feeds from people who person follow.

But my concern here is, what if a user has 1000 or 10,000 following. Can IN function inside MySQL take those 10,000 inside IN and get the value? Also, will it have speed impact?

E.g, SELECT * from feeds where ID in(1,2,3,4,5,6,7,....,1000,...10000)

Thanks

1 Answers1

0

This is properly documented:

The number of values in the IN() list is only limited by the max_allowed_packet value.

So basically the limit is based on the maximum length of a SQL statement - which defaults to 64 MB. There is little chance that you will ever hit this limit.

However, performance will suffer if you use a very large list of values to filter your data. In that case, a better option would be to put the list values in a table (as rows), and then use exists for filtering.

GMB
  • 216,147
  • 25
  • 84
  • 135