How can I find the source of slow queries in WordPress?

I have a WordPress site with more than 8000 posts and everytime I add a new one the site becomes unresponsive. I checked the MySQL slow queries log and found out that it is performing a select that returns most of the rows in the posts table and is taking a lot of time to execute.

This is an example:

Query_time: 149.702704  
Lock_time: 0.000078  
Rows_sent: 4699  
Rows_examined: 9398  
Rows_affected: 0  
Rows_read: 4699
use 488726_wp;

SELECT `ID`, `post_author`, `post_date`, `post_date_gmt`, `post_status`, `post_name`, `post_modified`, `post_modified_gmt`, `post_parent`, `post_type`
    FROM `wp_posts` 
        WHERE ( (post_status="publish" AND (post_type="post" OR post_type=""))  
            OR  (post_status="publish" AND post_type="page") )  
        AND post_password='' 
        ORDER BY post_modified DESC;

How can I find the source of these queries?

4 s
4

Try using this plugin http://wordpress.org/extend/plugins/debug-queries/ for checking performance of your database queries. It shows lots of detatils about each and every query made and time the query needed to complete and the time needed to make the whole page.

Leave a Comment