Hey guys,
sorry for the bad topic title, but I could not think of anything better. My problem is, that I have a really slow query, that I need help with:
There are approx. ~160 000 rows that would match this. The whole table has 500 000 records and the query executes in like 48s! There is an index on 'account_id' and one on 'created'. Unfortunately there is no compound index.Code:SELECT `Assembly`.`id`, `Assembly`.`created` FROM `assemblies` AS `Assembly` WHERE `Assembly`.`account_id` = 'some_id';
This is the output of EXPLAIN:
For other account_id's that would contain less rows the query runs really fast. Can someone explain to me how mysql processes this query and why it is not using the account_id index? That would be great as it makes our production site really slow (for that particular client).Code:| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+----------+------+---------------+------------+---------+-------+--------+-------------+ | 1 | SIMPLE | Assembly | ref | account_id | account_id | 97 | const | 157122 | Using where |
Thanks a lot in advance.
PS: The table engine is InnoDB.



Reply With Quote







Bookmarks