我有一个需要很长时间才能执行的查询(1.13s). user_articles和文章这两个表有大约25,000条记录.这是查询:
SELECT `user_articles`.*
FROM `user_articles`
INNER JOIN `articles` ON (`user_articles`.`article_id` = `articles`.`id`)
GROUP BY `articles`.`id`
ORDER BY `user_articles`.`created_at` DESC
我发现通过删除ORDER BY语句可以加快它(0.003s).这些是EXPLAIN的结果
+----+-------------+---------------+--------+---------------+------------+---------+-------------+-------+----------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------------+--------+---------------+------------+---------+-------------+-------+----------------------------------------------+
| 1 | SIMPLE | articles | index | PRIMARY | PRIMARY | 4 | NULL | 22678 | Using index; Using temporary; Using filesort |
| 1 | SIMPLE | user_articles | ref | article_id | article_id | 4 | articles.id | 1 | Using where |
+----+-------------+---------------+--------+---------------+------------+---------+-------------+-------+----------------------------------------------+
有什么方法可以加快我的查询速度吗?