Make WordPress Core


Ignore:
Timestamp:
09/29/2023 05:11:21 PM (2 years ago)
Author:
spacedmonkey
Message:

Comments: Improve WP_Comment_Query count query performance by setting 'order by' to 'none'.

In cases where WP_Comment_Query or get_comments is employed with the 'count' parameter set to true, specify 'order by' as 'none'. Since these queries serve solely to determine the count of comments matching specific query parameters, the 'order by' clause becomes redundant and places unnecessary strain on the database server, resulting in slower query execution. Given that count queries are executed on every admin request to retrieve comment counts, this change enhances the performance of the wp-admin interface.

Props guss77, davidbaumwald, SergeyBiryukov, westonruter, peterwilsoncc, foliovision, hareesh-pillai, spacedmonkey.
Fixes #58368

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/comment/query.php

    r56549 r56747  
    30923092        $found = $q->query(
    30933093            array(
    3094                 'count' => true,
     3094                'count'   => true,
     3095                'orderby' => 'none',
    30953096            )
    30963097        );
     
    31303131            array(
    31313132                'count'      => true,
     3133                'orderby'    => 'none',
    31323134                'meta_query' => array(
    31333135                    array(
     
    50025004        $query_1           = $q->query(
    50035005            array(
    5004                 'fields' => 'ids',
    5005                 'number' => 3,
    5006                 'order'  => 'ASC',
    5007                 'count'  => true,
     5006                'fields'  => 'ids',
     5007                'number'  => 3,
     5008                'orderby' => 'none',
     5009                'count'   => true,
    50085010            )
    50095011        );
     
    50125014        $query_2 = $q->query(
    50135015            array(
    5014                 'fields' => 'ids',
    5015                 'number' => 3,
    5016                 'order'  => 'ASC',
    5017                 'count'  => true,
     5016                'fields'  => 'ids',
     5017                'number'  => 3,
     5018                'orderby' => 'none',
     5019                'count'   => true,
    50185020            )
    50195021        );
Note: See TracChangeset for help on using the changeset viewer.