• My website has picked up in numbers recently thanks to a couple of mentions on the web, and we would get up to 20 users joining every 5 minutes. This eventually leads to my website going down (apparently overloading their server), with the hosting providing the following reason:

    | 463295 | xxx | localhost | xxx | Query | 3047 | statistics | SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts JOIN wp_postmeta meta0 ON meta0.post_id=wp_pos |
    | 463997 | xxx | localhost | xxx | Query | 2730 | statistics | SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts JOIN wp_postmeta meta0 ON meta0.post_id=wp_pos |

    I selected the 2 slowest queries to show here. Obviously 3000 seconds is not a good thing. I don’t know WordPress coding at all, and need help to fix this code, or to just get everything running faster.

    Any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • There are many resultions to this problem to prevent this query without modifying the core. Here is the simplest and most straightforward:

    Hook into pre_get_posts, then in the hook function invoke the set method on the query object passing ‘no_found_rows’ to TRUE.

    In code,

    The hook,
    add_action(‘pre_get_posts’,’no_rows_found_function’);

    The hook function,
    function no_rows_found_function($query) {
    $query->set(‘no_found_rows’,true);
    }

    That’s it!

    The problem with slow query SELECT SQL_CALC_FOUND_ROWS because it had resolved modifying wp-includes/query.php, the WordPress 3.3.1 core, when we updated to version 3.4.1 we noticed that in wp-admin to posts not visualized paging. To solve the problem using the solution proposed phkcorp2005, without modifying the core WordPress 3.4.1 but still had the problem of not displaying the pagination in the wp-admin.

    To solve the problem using:

    function no_rows_found_function($query) {
    	if (!is_admin()) {
    		$query->set( 'no_found_rows', true );
    	}
    }
    add_action('pre_get_posts','no_rows_found_function');
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘SELECT SQL_CALC_FOUND_ROWS causing crashes’ is closed to new replies.