I have one query that is preventing me from going live with this application, because it can take up to 7 seconds to complete when it isn't cached.
SELECT attribute1
FROM `product_applications`
WHERE `product_applications`.`brand_id` IN (.. like 500 ids...)
GROUP BY attribute1
I have the brand_id indexed. I used to have this doing a SELECT DISTINCT, but opted for the GROUP BY and performance has improved slightly.
This table is using InnoDB, and has about 2.3 million rows. I have run an EXPLAIN on it and it uses the index, it just takes forever.
I know there are a lot of variables to getting something like this to perform. The db is on an Amazon EC2 instance.
Is there some sort of table splitting I could do to get the query to perform better? I really appreciate any help anybody can offer.
EDIT:
Here are the results on my explain, from NewRelic:
Id 1
Select Type SIMPLE
Table product_applications
Type range
Possible Keys brand_search_index_1,brand_search_index_2,brand_search_index_3,brand_search_index_4,brand_sarch_index_5
Key brand_search_index_1
Key Length 5
Ref
Rows 843471
Extra Using where; Using index; Using temporary; Using filesort
See, it's using the index. But it's also using a temp table and filesort. How can I overcome that stuff?
EDIT:
Since the time I opened this question, I changed the engine on this table from InnoDB to MyISAM. I also vertically partitioned the table by moving attributes 5 through 60 to another table. But this select statement STILL TAKES BETWEEN 2 AND 3 SECONDS!!!! The poor performance of this query is absolutely maddening.