Title: SELECT SQL_CALC_FOUND_ROWS  causing crashes
Last modified: August 20, 2016

---

# SELECT SQL_CALC_FOUND_ROWS causing crashes

 *  [Cheg](https://wordpress.org/support/users/cheg/)
 * (@cheg)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/select-sql_calc_found_rows-causing-crashes/)
 * 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)

 *  [PressPage Entertainment Inc](https://wordpress.org/support/users/phkcorp2005/)
 * (@phkcorp2005)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/select-sql_calc_found_rows-causing-crashes/#post-2212350)
 * 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!
 *  [Saul Diaz](https://wordpress.org/support/users/idevol/)
 * (@idevol)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/select-sql_calc_found_rows-causing-crashes/#post-2212363)
 * 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.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 3 participants
 * Last reply from: [Saul Diaz](https://wordpress.org/support/users/idevol/)
 * Last activity: [13 years, 10 months ago](https://wordpress.org/support/topic/select-sql_calc_found_rows-causing-crashes/#post-2212363)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
