Index: query.php
===================================================================
--- query.php	(revision 17791)
+++ query.php	(working copy)
@@ -2591,7 +2591,10 @@
 			$orderby = 'ORDER BY ' . $orderby;
 
 		$found_rows = '';
-		if ( !$q['no_found_rows'] && !empty($limits) )
+		// performance tests have shown that when no grouping is involved, a simple
+		// count afterwards performs much better on large tables
+		// http://core.trac.wordpress.org/ticket/10964
+		if ( !$q['no_found_rows'] && !empty($limits) && !empty($groupby) )
 			$found_rows = 'SQL_CALC_FOUND_ROWS';
 
 		$this->request = " SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits";
@@ -2634,7 +2637,10 @@
 		}
 
 		if ( !$q['no_found_rows'] && !empty($limits) ) {
-			$found_posts_query = apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) );
+			$found_posts_query = "SELECT FOUND_ROWS()";
+			if ( empty( $groupby ) ) 
+				$found_posts_query = "SELECT count(*) FROM $wpdb->posts $join WHERE 1=1 $where $orderby";
+			$found_posts_query = apply_filters_ref_array( 'found_posts_query', array( $found_posts_query, &$this ) );
 			$this->found_posts = $wpdb->get_var( $found_posts_query );
 			$this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) );
 			$this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']);
