Title: SQL_Calc_found crashing website
Last modified: August 31, 2016

---

# SQL_Calc_found crashing website

 *  [Mitmin](https://wordpress.org/support/users/mitmin/)
 * (@mitmin)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/sql_calc_found-crashing-website/)
 * Our database has around 15,000 posts. And since 3 days the website crashes almost
   every hour. The problem is Select_Calc_found query.
 * I added the following queries
 * _[ Moderator note: code fixed. Please wrap code in the backtick character or 
   [use the code button](http://codex.wordpress.org/Forum_Welcome#Posting_Code).]_
 *     ```
       add_filter('pre_get_posts', 'optimized_get_posts', 100);
       function optimized_get_posts() {
       	global $wp_query, $wpdb;
   
       	$wp_query->query_vars['no_found_rows'] = 1;
       	$wp_query->found_posts = $wpdb->get_var( "SELECT COUNT(*) FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')" );
       	$wp_query->found_posts = apply_filters_ref_array( 'found_posts', array( $wp_query->found_posts, &$wp_query ) );
       	$wp_query->max_num_pages = ceil($wp_query->found_posts / $wp_query->query_vars['posts_per_page']);
   
        	return $wp_query;
       }
   
       function no_rows_found_function($query) {
       	if (!is_admin()) {
       		$query->set( 'no_found_rows', true );
       	}
       }
       add_action('pre_get_posts','no_rows_found_function');
       ```
   
 * The crashing has stopped. I got these from posts which are 5 years old.
 * But I couldn’t find any recent posts that could help resolve the issue. Our database
   is going to grow more. Should I just stick to this solution or is there more 
   I have to do to stop the website from crashing in the future.Any help or suggestion
   would be of great help.
 * And more over this solution has caused problem to pagination in the website. 
   What should I do regarding this? Please help

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [boonesimpson](https://wordpress.org/support/users/boonesimpson/)
 * (@boonesimpson)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/sql_calc_found-crashing-website/#post-7169574)
 * I’m running into the same issue
 *  Thread Starter [Mitmin](https://wordpress.org/support/users/mitmin/)
 * (@mitmin)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/sql_calc_found-crashing-website/#post-7169576)
 * If you are facing the SQL_Calc query problem, Copy the patch to function.php.
   
   I used Optimize database after deleting revision. I run this plugin twice in 
   a week. And updated all my plugin and wordpress to the latest version.
 * I also received suggestion saying that this not ususal. So some of my files might
   be corrupted. So I was asked to install wordpress again on top of my current.
   But I did not do this. But it is in future plan.
 * My website did not crash after this. But I’m not sure if there is a permanent
   solution this.
 * If you find anything interesting, please share your experience.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘SQL_Calc_found crashing website’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [Mitmin](https://wordpress.org/support/users/mitmin/)
 * Last activity: [10 years, 2 months ago](https://wordpress.org/support/topic/sql_calc_found-crashing-website/#post-7169576)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
