Make WordPress Core

Ticket #10964: simple_modified.10964.diff

File simple_modified.10964.diff, 1.4 KB (added by mwidmann, 13 years ago)
  • query.php

     
    25912591                        $orderby = 'ORDER BY ' . $orderby;
    25922592
    25932593                $found_rows = '';
    2594                 if ( !$q['no_found_rows'] && !empty($limits) )
     2594                // performance tests have shown that when no grouping is involved, a simple
     2595                // count afterwards performs much better on large tables
     2596                // http://core.trac.wordpress.org/ticket/10964
     2597                if ( !$q['no_found_rows'] && !empty($limits) && !empty($groupby) )
    25952598                        $found_rows = 'SQL_CALC_FOUND_ROWS';
    25962599
    25972600                $this->request = " SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits";
     
    26342637                }
    26352638
    26362639                if ( !$q['no_found_rows'] && !empty($limits) ) {
    2637                         $found_posts_query = apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) );
     2640                        $found_posts_query = "SELECT FOUND_ROWS()";
     2641                        if ( empty( $groupby ) )
     2642                                $found_posts_query = "SELECT count(*) FROM $wpdb->posts $join WHERE 1=1 $where $orderby";
     2643                        $found_posts_query = apply_filters_ref_array( 'found_posts_query', array( $found_posts_query, &$this ) );
    26382644                        $this->found_posts = $wpdb->get_var( $found_posts_query );
    26392645                        $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) );
    26402646                        $this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']);