Optimizing MySQL queries with IN operator

Posted by Arkadiusz Kondas on Stack Overflow See other posts from Stack Overflow or by Arkadiusz Kondas
Published on 2010-03-09T10:23:46Z Indexed on 2010/03/09 10:36 UTC
Read the original article Hit count: 135

Filed under:
|
|
|

I have a MySQL database with a fairly large table where the products are. Each of them has its own id and categoryId field where there is a category id belongs to this product. Now I have a query that pulls out products from given categories such as:

SELECT * FROM products WHERE categoryId IN ( 1, 2, 3, 4, 5, 34, 6, 7, 8, 9, 10, 11, 12 )

Of course, come a WHERE clause and ORDER BY sort but not in this thing. Let's say that these products is 250k and the visits are over 100k per day. Under such conditions in the table slow_log registered weight of these queries with large generation time.

Do you have any ideas how to optimize the given problem?

Table engine is MyISAM.

© Stack Overflow or respective owner

Related posts about mysql

Related posts about sql