Mysql – Maximum or suggested number of bound query-parameters in InnoDB (MySQL)

innodbMySQLparameter

We have code that adds thousands of parameters to a query as members of an IN (…) criterion. My aesthetics say to bucket it into multiple queries, but I want an objective reason.

Does InnoDB have a maximum number of parameters per query? Does it hurt performance to have over a certain number?

Best Answer

With that many values you are likely to run into estimation errors during query plan generation. This will lead to it choosing worse (slower-performing) plans than it might otherwise.

With that many values I would suggest INSERTing them into an actual table, with index(es), which is JOINed to in the query. Logically the two are the same. Practically, aesthetically and performance wise it is likely to be better, even with the additional writes.