Hi list,
I noticed that the
joind.in homepage is running a little slowly, so I had a quick look into it - it looks like there's a particularly expensive MySQL query running when the homepage is requested:
select t.talk_title, t.ID, count(tc.ID) as ccount, get_talk_rating(t.ID) as tavg, e.ID eid, e.event_name from talks t JOIN talk_comments tc ON tc.talk_id=t.ID AND tc.private = 0 JOIN events e ON e.ID=t.event_id where t.active=1 and (tc.user_id != 0 and tc.rating != 0) group by t.ID order by ccount desc limit 7;
This is taking nearly 1 second to run, during which time MySQL is fully using a CPU. I think it used to be really fast because we've got the query cache enabled, but recently it started using the get_talk_rating() user-defined function which automatically misses the query cache. Here's the explain plan on the current live DB:
mysql> explain select t.talk_title, t.ID, count(tc.ID) as ccount, get_talk_rating(t.ID) as tavg, e.ID eid, e.event_name from talks t JOIN talk_comments tc ON tc.talk_id=t.ID AND tc.private = 0 JOIN events e ON e.ID=t.event_id where t.active=1 and (tc.user_id != 0 and tc.rating != 0) group by t.ID order by ccount desc limit 7;
+----+-------------+-------+--------+-------------------+---------+---------+--------------------+-------+----------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+--------+-------------------+---------+---------+--------------------+-------+----------------------------------------------+
| 1 | SIMPLE | tc | ALL | idx_talk | NULL | NULL | NULL | 15508 | Using where; Using temporary; Using filesort |
| 1 | SIMPLE | t | eq_ref | PRIMARY,idx_event | PRIMARY | 4 | joindin.tc.talk_id | 1 | Using where |
| 1 | SIMPLE | e | eq_ref | PRIMARY | PRIMARY | 4 | joindin.t.event_id | 1 | |
+----+-------------+-------+--------+-------------------+---------+---------+--------------------+-------+----------------------------------------------+
3 rows in set (0.00 sec)
I'm pretty sure that it should be possible to run the get_talk_rating logic and have a fast query - does anyone fancy having a look? I can provide an anonymised version of the data if desired, and open a ticket on Jira for it, but I thought some discussion here would be good.
Thanks,
Kevin