Jake B.
Well-known member
- Affected version
 - 2.1.11
 
I'm fairly certain this query is coming from a new posts widget, but not 100% certain. Looks like there is no 
	
	
	
		
This is the full query, with most of the node IDs excluded since it was quite a long list, and makes reading through the query quite a bit more difficult:
	
	
	
		
Explain from the query:
	
	
	
		
				
			node_id index on xf_thread, and there's also an issue with this portion: portion
		Code:
	
	(`xf_forum_Forum_2`.`find_new` = 1)
	This is the full query, with most of the node IDs excluded since it was quite a long list, and makes reading through the query quite a bit more difficult:
		Code:
	
	SELECT `xf_thread`.*, `xf_poll_Poll_1`.*, `xf_forum_Forum_2`.*, `xf_node_Node_3`.*, `xf_permission_cache_content_Permissions_4`.*, `xf_user_User_5`.*, `xf_user_profile_Profile_6`.*, `xf_user_privacy_Privacy_7`.*, `xf_user_option_Option_8`.*, `xf_session_activity_Activity_9`.*, `xf_admin_Admin_10`.*, `xf_thread_user_post_UserPosts_11`.*, `xf_thread_watch_Watch_12`.*, `xf_thread_reply_ban_ReplyBans_13`.*, `xf_post_FirstPost_14`.*
                        FROM `xf_thread`
                        LEFT JOIN `xf_poll` AS `xf_poll_Poll_1` ON (`xf_poll_Poll_1`.`content_type` = 'thread' AND `xf_poll_Poll_1`.`content_id` = `xf_thread`.`thread_id`)
LEFT JOIN `xf_forum` AS `xf_forum_Forum_2` ON (`xf_forum_Forum_2`.`node_id` = `xf_thread`.`node_id`)
LEFT JOIN `xf_node` AS `xf_node_Node_3` ON (`xf_node_Node_3`.`node_id` = `xf_forum_Forum_2`.`node_id`)
LEFT JOIN `xf_permission_cache_content` AS `xf_permission_cache_content_Permissions_4` ON (`xf_permission_cache_content_Permissions_4`.`content_type` = 'node' AND `xf_permission_cache_content_Permissions_4`.`content_id` = `xf_node_Node_3`.`node_id` AND `xf_permission_cache_content_Permissions_4`.`permission_combination_id` = '42')
LEFT JOIN `xf_user` AS `xf_user_User_5` ON (`xf_user_User_5`.`user_id` = `xf_thread`.`user_id`)
LEFT JOIN `xf_user_profile` AS `xf_user_profile_Profile_6` ON (`xf_user_profile_Profile_6`.`user_id` = `xf_user_User_5`.`user_id`)
LEFT JOIN `xf_user_privacy` AS `xf_user_privacy_Privacy_7` ON (`xf_user_privacy_Privacy_7`.`user_id` = `xf_user_User_5`.`user_id`)
LEFT JOIN `xf_user_option` AS `xf_user_option_Option_8` ON (`xf_user_option_Option_8`.`user_id` = `xf_user_User_5`.`user_id`)
LEFT JOIN `xf_session_activity` AS `xf_session_activity_Activity_9` ON (`xf_session_activity_Activity_9`.`user_id` = `xf_user_User_5`.`user_id` AND `xf_session_activity_Activity_9`.`unique_key` = CONCAT(`xf_user_User_5`.`user_id`, ''))
LEFT JOIN `xf_admin` AS `xf_admin_Admin_10` ON (`xf_admin_Admin_10`.`user_id` = `xf_user_User_5`.`user_id`)
LEFT JOIN `xf_thread_user_post` AS `xf_thread_user_post_UserPosts_11` ON (`xf_thread_user_post_UserPosts_11`.`thread_id` = `xf_thread`.`thread_id` AND `xf_thread_user_post_UserPosts_11`.`user_id` = '450224')
LEFT JOIN `xf_thread_watch` AS `xf_thread_watch_Watch_12` ON (`xf_thread_watch_Watch_12`.`thread_id` = `xf_thread`.`thread_id` AND `xf_thread_watch_Watch_12`.`user_id` = '450224')
LEFT JOIN `xf_thread_reply_ban` AS `xf_thread_reply_ban_ReplyBans_13` ON (`xf_thread_reply_ban_ReplyBans_13`.`thread_id` = `xf_thread`.`thread_id` AND `xf_thread_reply_ban_ReplyBans_13`.`user_id` = '450224')
LEFT JOIN `xf_post` AS `xf_post_FirstPost_14` ON (`xf_post_FirstPost_14`.`post_id` = `xf_thread`.`first_post_id`)
                        WHERE (`xf_thread`.`discussion_type` != 'redirect') AND (`xf_forum_Forum_2`.`find_new` = 1) AND (`xf_thread`.`node_id` IN (11249, 11251, 11253, 11255, 11257, 11259, 11263, 11265, 11267, 11269, 11271, 11273, 11275)) AND (`xf_thread`.`discussion_state` = 'visible')
                        ORDER BY `xf_thread`.`post_date` DESC
LIMIT 20
	Explain from the query:
		Code:
	
	mysql> explain SELECT `xf_thread`.*, `xf_poll_Poll_1`.*, `xf_forum_Forum_2`.*, `xf_node_Node_3`.*, `xf_permission_cache_content_Permissions_4`.*, `xf_user_User_5`.*, `xf_user_profile_Profile_6`.*, `xf_user_privacy_Privacy_7`.*, `xf_user_option_Option_8`.*, `xf_session_activity_Activity_9`.*, `xf_admin_Admin_10`.*, `xf_thread_user_post_UserPosts_11`.*, `xf_thread_watch_Watch_12`.*, `xf_thread_reply_ban_ReplyBans_13`.*, `xf_post_FirstPost_14`.*
    ->                         FROM `xf_thread`
    ->                         LEFT JOIN `xf_poll` AS `xf_poll_Poll_1` ON (`xf_poll_Poll_1`.`content_type` = 'thread' AND `xf_poll_Poll_1`.`content_id` = `xf_thread`.`thread_id`)
    -> LEFT JOIN `xf_forum` AS `xf_forum_Forum_2` ON (`xf_forum_Forum_2`.`node_id` = `xf_thread`.`node_id`)
    -> LEFT JOIN `xf_node` AS `xf_node_Node_3` ON (`xf_node_Node_3`.`node_id` = `xf_forum_Forum_2`.`node_id`)
    -> LEFT JOIN `xf_permission_cache_content` AS `xf_permission_cache_content_Permissions_4` ON (`xf_permission_cache_content_Permissions_4`.`content_type` = 'node' AND `xf_permission_cache_content_Permissions_4`.`content_id` = `xf_node_Node_3`.`node_id` AND `xf_permission_cache_content_Permissions_4`.`permission_combination_id` = '42')
    -> LEFT JOIN `xf_user` AS `xf_user_User_5` ON (`xf_user_User_5`.`user_id` = `xf_thread`.`user_id`)
    -> LEFT JOIN `xf_user_profile` AS `xf_user_profile_Profile_6` ON (`xf_user_profile_Profile_6`.`user_id` = `xf_user_User_5`.`user_id`)
    -> LEFT JOIN `xf_user_privacy` AS `xf_user_privacy_Privacy_7` ON (`xf_user_privacy_Privacy_7`.`user_id` = `xf_user_User_5`.`user_id`)
    -> LEFT JOIN `xf_user_option` AS `xf_user_option_Option_8` ON (`xf_user_option_Option_8`.`user_id` = `xf_user_User_5`.`user_id`)
    -> LEFT JOIN `xf_session_activity` AS `xf_session_activity_Activity_9` ON (`xf_session_activity_Activity_9`.`user_id` = `xf_user_User_5`.`user_id` AND `xf_session_activity_Activity_9`.`unique_key` = CONCAT(`xf_user_User_5`.`user_id`, ''))
    -> LEFT JOIN `xf_admin` AS `xf_admin_Admin_10` ON (`xf_admin_Admin_10`.`user_id` = `xf_user_User_5`.`user_id`)
    -> LEFT JOIN `xf_thread_user_post` AS `xf_thread_user_post_UserPosts_11` ON (`xf_thread_user_post_UserPosts_11`.`thread_id` = `xf_thread`.`thread_id` AND `xf_thread_user_post_UserPosts_11`.`user_id` = '450224')
    -> LEFT JOIN `xf_thread_watch` AS `xf_thread_watch_Watch_12` ON (`xf_thread_watch_Watch_12`.`thread_id` = `xf_thread`.`thread_id` AND `xf_thread_watch_Watch_12`.`user_id` = '450224')
    -> LEFT JOIN `xf_thread_reply_ban` AS `xf_thread_reply_ban_ReplyBans_13` ON (`xf_thread_reply_ban_ReplyBans_13`.`thread_id` = `xf_thread`.`thread_id` AND `xf_thread_reply_ban_ReplyBans_13`.`user_id` = '450224')
    -> LEFT JOIN `xf_post` AS `xf_post_FirstPost_14` ON (`xf_post_FirstPost_14`.`post_id` = `xf_thread`.`first_post_id`)
    ->                         WHERE (`xf_thread`.`discussion_type` != 'redirect') AND (`xf_forum_Forum_2`.`find_new` = 1) AND (`xf_thread`.`node_id` IN (11249, 11251, 11253, 11255, 11257, 11259, 11263, 11265, 11267, 11269, 11271, 11273, 11275)) AND (`xf_thread`.`discussion_state` = 'visible')
    ->                         ORDER BY `xf_thread`.`post_date` DESC
    -> LIMIT 20;
+----+-------------+-------------------------------------------+--------+-------------------------------------------------------------------------------+-------------------------+---------+---------------------------------------------------------+------+----------------------------------------------+
| id | select_type | table                                     | type   | possible_keys                                                                 | key                     | key_len | ref                                                     | rows | Extra                                        |
+----+-------------+-------------------------------------------+--------+-------------------------------------------------------------------------------+-------------------------+---------+---------------------------------------------------------+------+----------------------------------------------+
|  1 | SIMPLE      | xf_forum_Forum_2                          | range  | PRIMARY                                                                       | PRIMARY                 | 4       | NULL                                                    |   13 | Using where; Using temporary; Using filesort |
|  1 | SIMPLE      | xf_node_Node_3                            | eq_ref | PRIMARY                                                                       | PRIMARY                 | 4       | xenforo_import_clean.xf_forum_Forum_2.node_id           |    1 | NULL                                         |
|  1 | SIMPLE      | xf_permission_cache_content_Permissions_4 | eq_ref | PRIMARY                                                                       | PRIMARY                 | 35      | const,const,xenforo_import_clean.xf_node_Node_3.node_id |    1 | Using where                                  |
|  1 | SIMPLE      | xf_thread                                 | ref    | node_id_last_post_date,node_id_sticky_state_last_post,node_id,discussion_type | node_id                 | 4       | xenforo_import_clean.xf_forum_Forum_2.node_id           |  252 | Using where                                  |
|  1 | SIMPLE      | xf_poll_Poll_1                            | eq_ref | content_type_content_id                                                       | content_type_content_id | 31      | const,xenforo_import_clean.xf_thread.thread_id          |    1 | Using where                                  |
|  1 | SIMPLE      | xf_user_User_5                            | eq_ref | PRIMARY                                                                       | PRIMARY                 | 4       | xenforo_import_clean.xf_thread.user_id                  |    1 | NULL                                         |
|  1 | SIMPLE      | xf_user_profile_Profile_6                 | eq_ref | PRIMARY                                                                       | PRIMARY                 | 4       | xenforo_import_clean.xf_user_User_5.user_id             |    1 | NULL                                         |
|  1 | SIMPLE      | xf_user_privacy_Privacy_7                 | eq_ref | PRIMARY                                                                       | PRIMARY                 | 4       | xenforo_import_clean.xf_user_User_5.user_id             |    1 | NULL                                         |
|  1 | SIMPLE      | xf_user_option_Option_8                   | eq_ref | PRIMARY                                                                       | PRIMARY                 | 4       | xenforo_import_clean.xf_user_User_5.user_id             |    1 | NULL                                         |
|  1 | SIMPLE      | xf_session_activity_Activity_9            | eq_ref | PRIMARY                                                                       | PRIMARY                 | 22      | xenforo_import_clean.xf_user_User_5.user_id,func        |    1 | Using where                                  |
|  1 | SIMPLE      | xf_admin_Admin_10                         | eq_ref | PRIMARY                                                                       | PRIMARY                 | 4       | xenforo_import_clean.xf_user_User_5.user_id             |    1 | NULL                                         |
|  1 | SIMPLE      | xf_thread_user_post_UserPosts_11          | eq_ref | PRIMARY,user_id                                                               | PRIMARY                 | 8       | xenforo_import_clean.xf_thread.thread_id,const          |    1 | NULL                                         |
|  1 | SIMPLE      | xf_thread_watch_Watch_12                  | eq_ref | PRIMARY,thread_id_email_subscribe                                             | PRIMARY                 | 8       | const,xenforo_import_clean.xf_thread.thread_id          |    1 | NULL                                         |
|  1 | SIMPLE      | xf_thread_reply_ban_ReplyBans_13          | eq_ref | thread_id,user_id                                                             | thread_id               | 8       | xenforo_import_clean.xf_thread.thread_id,const          |    1 | NULL                                         |
|  1 | SIMPLE      | xf_post_FirstPost_14                      | eq_ref | PRIMARY                                                                       | PRIMARY                 | 4       | xenforo_import_clean.xf_thread.first_post_id            |    1 | NULL                                         |
+----+-------------+-------------------------------------------+--------+-------------------------------------------------------------------------------+-------------------------+---------+---------------------------------------------------------+------+----------------------------------------------+
15 rows in set (0.00 sec)
	
			
				Last edited: