Question

I have a query that is taking a long time to execute (1.13s). The two tables user_articles and articles have around 25,000 records. This is the query:

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

I have found that by removing the ORDER BY statement it speeds it up (0.003s). These are the results from the 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                                  |
+----+-------------+---------------+--------+---------------+------------+---------+-------------+-------+----------------------------------------------+

Is there any way I can speed up my query?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top