I'm looking at some code written by someone else that takes an array and formulates a SELECT query for MySQL that typically has a lot of terms in a WHERE IN clause. The language it's written in happens to be PHP but I think that might be irrelevant to my question.
Assuming some array of $record_ids with easily hundreds and potentially thousands of integers in it, the array is created sort of thusly:
$sql = "SELECT * FROM my_table WHERE id IN (" . implode(",", $record_ids) . ")";
This will result in a query that might look like this
SELECT * FROM my_table WHERE id IN (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,7,18,19, 20, 21, 22);
Except it might have literally thousand of IDs in the IN clause. My question is does MySQL enforce some upper limit to the number of terms you can put in a WHERE IN clause? If not, surely there must be some constraint or limit on how large this query can go -- what is that limit?