Hi all,
I have a PhP/MySQL app running on Joyent virtual servers that has been humming along nicely for a year, but now is hitting serious problems. Queries that used to run fine are now sometimes taking 10 or 20 seconds to complete (but sometimes <1 second). Table are MyISAM, and locking is not a big issue. There are usually only a couple users at once. The user_book table has about 600k rows and the book table has about 300k rows.
Here is output of a slow log (some info anonymized):
Time: ****
User@Host: [] @ ****
Query_time: 12 Lock_time: 0 Rows_sent: 22 Rows_examined: 44
SELECT id, title, author, count, status, user_book.ranking, asin, locale, image_url, user_book.uid, review.uid as review FROM book LEFT JOIN user_book ON id=bid LEFT JOIN review ON user_book.uid=review.uid AND user_book.bid=review.bid WHERE user_book.uid=25103032;
and here is an explain of the same query.
±—±------------±----------±-------±--------------±-- ------±--------±-------------------------------------±— --±------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
±—±------------±----------±-------±--------------±-- ------±--------±-------------------------------------±— --±------------+
| 1 | SIMPLE | user_book | ref | PRIMARY,bid | PRIMARY | 4 | const | 21 | Using where |
| 1 | SIMPLE | review | eq_ref | PRIMARY,bid | PRIMARY | 8 | const,****.user_book.bid | 1 | Using index |
| 1 | SIMPLE | book | eq_ref | PRIMARY | PRIMARY | 4 | ****.user_book.bid | 1 | |
±—±------------±----------±-------±--------------±-- ------±--------±-------------------------------------±— --±------------+
I am at a loss. I am a professional software developer, but I know only the very basics when it comes to databases. I’m guessing there is some configuration problem here, as I see no other reason why this query would take 12 seconds to evaluate.
Any ideas?
Thanks,
Garth