[wp-trac] [WordPress Trac] #50161: Slow query in WP_Posts_List_Table, no way to avoid with filters/hooks

WordPress Trac noreply at wordpress.org
Wed Jul 30 21:12:08 UTC 2025


#50161: Slow query in WP_Posts_List_Table, no way to avoid with filters/hooks
--------------------------------+------------------------------------------
 Reporter:  LucasMS             |       Owner:  (none)
     Type:  enhancement         |      Status:  reopened
 Priority:  normal              |   Milestone:  6.9
Component:  Posts, Post Types   |     Version:  5.4.1
 Severity:  normal              |  Resolution:
 Keywords:  has-patch 2nd-      |     Focuses:  administration, performance
  opinion                       |
--------------------------------+------------------------------------------

Comment (by siliconforks):

 Replying to [comment:16 josephscott]:
 > I used a smaller data set, to make it easier to quickly import into
 different environments.  This reduced `wp_posts` table only has 1,848
 rows.

 I'm not sure what's going on there, but did you try it with your
 [comment:7 original data set]?

 This is what I used to populate the `wp_posts` table for testing (using
 `wp eval-file`):

 {{{#!php
 <?php

 define( 'NUM_BATCHES', 3400 );
 define( 'POST_CONTENT', 'XXX' );
 define( 'STARTING_TIMESTAMP', 500 * 1000 * 1000 );

 global $wpdb;

 $unix_timestamp = STARTING_TIMESTAMP;
 for ( $batch = 0; $batch < NUM_BATCHES; ++$batch ) {
         $sql = [];
         for ( $i = 0; $i < 100; ++$i ) {
                 if ( $batch === 0 && $i === 0 ) {
                         $post_author = 2;
                 } else {
                         $post_author = 1;
                 }
                 $post_date = gmdate( 'Y-m-d H:i:s', $unix_timestamp );
                 $post_content = POST_CONTENT;
                 $post_title = 'Posted at ' . $post_date;
                 $post_excerpt = POST_CONTENT;
                 if ( $batch === 3398 ) {
                         $post_status = 'draft';
                 } elseif ( $batch === 3399 ) {
                         $post_status = 'private';
                 } else {
                         $post_status = 'publish';
                 }
                 $post_name = $post_title;
                 $post_name = strtolower( $post_name );
                 $post_name = preg_replace( '/[^a-z0-9]/', '-', $post_name
 );
                 $to_ping = '';
                 $pinged = '';
                 $post_content_filtered = POST_CONTENT;

                 $sql[] = $wpdb->prepare( '(%s, %s, %s, %s, %s, %s, %s, %s,
 %s, %s, %s, %s, %s)', $post_author, $post_date, $post_date, $post_content,
 $post_title, $post_excerpt, $post_status, $post_name, $to_ping, $pinged,
 $post_date, $post_date, $post_content_filtered );
                 $unix_timestamp += 600;
         }
         $sql = 'INSERT INTO ' . $wpdb->posts . ' (post_author, post_date,
 post_date_gmt, post_content, post_title, post_excerpt, post_status,
 post_name, to_ping, pinged, post_modified, post_modified_gmt,
 post_content_filtered) VALUES ' . implode( ', ', $sql );
         $wpdb->query( $sql );
         echo '.';
         flush();
 }
 echo "\n";
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/50161#comment:17>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list