Luke F
Well-known member
Can this query be fixed so it doesn't take almost 7 seconds to load?
Code:SELECT thread.* , user.*, IF(user.username IS NULL, thread.username, user.username) AS username, deletion_log.delete_date, deletion_log.delete_reason, deletion_log.delete_user_id, deletion_log.delete_username, IF(thread_read.thread_read_date > 1483027983, thread_read.thread_read_date, 1483027983) AS thread_read_date, IF(thread_watch.user_id IS NULL, 0, IF(thread_watch.email_subscribe, 'watch_email', 'watch_no_email')) AS thread_is_watched, thread_user_post.post_count AS user_post_count, pr_cache.rating_cache FROM xf_thread AS thread LEFT JOIN xf_user AS user ON (user.user_id = thread.user_id) LEFT JOIN xf_deletion_log AS deletion_log ON (deletion_log.content_type = 'thread' AND deletion_log.content_id = thread.thread_id) LEFT JOIN xf_thread_read AS thread_read ON (thread_read.thread_id = thread.thread_id AND thread_read.user_id = 374904) LEFT JOIN xf_thread_watch AS thread_watch ON (thread_watch.thread_id = thread.thread_id AND thread_watch.user_id = 374904) LEFT JOIN xf_thread_user_post AS thread_user_post ON (thread_user_post.thread_id = thread.thread_id AND thread_user_post.user_id = 374904) left join dark_postrating_post_cache pr_cache ON (thread.first_post_id = pr_cache.post_id) WHERE (thread.node_id = 881) AND (thread.sticky = 0) AND (thread.discussion_state IN ('visible','deleted','moderated')) ORDER BY thread.last_post_date DESC
That query is not slow because of Post Ratings. If you remove everything added by post ratings it is still having to fetch and sort a large number of rows
(i.e. the lines containing 'pr_cache')