I am using ruby to perform a query on a MySQL db. I’m looking for matches of uids with:
WHERE uid in #{VERY_LARGE_COMMA_SEPARATED_LIST}
The VERY_LARGE_COMMA_SEPARATED_LIST is over 30k entries
VERY_LARGE_COMMA_SEPARATED_LIST = ' "one","two","three",...,"30k" '
and it causes sql to dump error:
Mysql2::Error - MySQL server has gone away:
Does anyone know what is going on here?
You must be going over typical 1MB mysql SQL command buffer.
To solve your problem, you should create (possibly temporary) table
uidswhich contains just uid’s, something like(be sure that index exists for
uid).Then INSERT necessary uid’s into
uidstable in few statements like this:Finally, run your query as:
or join like this:
In the end, you may want to drop your
uidstable.EDIT: I missed that your
uidis not integer. Simply adjust definitions for it to useVARCHARinstead.