I am new to mySQL and PHP and I'm stuck into a performance problem. I have a database with different unique ids and I want to extract several rows by id (from an array) out of over 5000. The best solution I came up so far is to use:
SELECT * FROM `table` WHERE id IN ($idArray);
Is there a more efficient way to do this? The 'id' in 'table' is a unique string.
I have seen 70,000 numbers in an IN
list be "sluggish".
Part of the issue is indexing. Your table
needs INDEX(id)
(or, better yet, PRIMARY KEY(id)
).
Part of the issue is caching. If table
is small enough to fit in the buffer_pool, and that cache is warm, then it is more like warm and wet stuff falling off a shovel.
But... If your "array" is already in a table, then simply JOIN
to that table. That will probably be faster. OTOH, building a table just for this purpose will probably be slower.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.