我有这个查询,运行从phpbb3获得5个最近的帖子/主题。论坛有超过18万条记录。这个当前查询平均需要20秒才能完成..任何想法我可能会优化它以使其更快?需要一些帮助优化这个mySQL查询
SELECT t.topic_id, t.topic_title, t.topic_last_post_id, t.forum_id, p.post_id, p.poster_id, p.post_time, u.user_id, u.username
FROM phpbb_topics t, phpbb_forums f, phpbb_posts p, phpbb_users u
WHERE t.topic_id = p.topic_id AND
f.forum_id = t.forum_id AND
t.forum_id != 4 AND
t.topic_status <> 2 AND
p.post_id = t.topic_last_post_id AND
p.poster_id = u.user_id
ORDER BY p.post_id DESC LIMIT 5;
使用加入到优化所述 – DevT 2013-03-08 04:22:42
什么倾斜,你应该使用'JOIN's,而不是把所有的连接条件在'WHERE'条款。 – 2013-03-08 04:23:44
也可以使用EXPLAIN来查看添加索引可能有用的位置。 – Daedalus 2013-03-08 04:33:35