Skip to content

Commit 601ddd4

Browse files
Database: Add type_status_author index for the posts table.
This aims to improve performance of some queries on installations with a large number of posts. Follow-up to [3678], [3690], [9290], [13576]. Props josephscott, LucasMS, Otto42, flixos90, matt, johnjamesjacoby, siliconforks, mukesh27, jonsurrell, SirLouen, SergeyBiryukov. Fixes #50161. git-svn-id: https://develop.svn.wordpress.org/trunk@60717 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 94bfca7 commit 601ddd4

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/wp-admin/includes/schema.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ function wp_get_db_schema( $scope = 'all', $blog_id = null ) {
184184
KEY post_name (post_name($max_index_length)),
185185
KEY type_status_date (post_type,post_status,post_date,ID),
186186
KEY post_parent (post_parent),
187-
KEY post_author (post_author)
187+
KEY post_author (post_author),
188+
KEY type_status_author (post_type,post_status,post_author)
188189
) $charset_collate;\n";
189190

190191
// Single site users table. The multisite flavor of the users table is handled below.

src/wp-admin/includes/upgrade.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2488,7 +2488,8 @@ function ( $url ) {
24882488
* @ignore
24892489
* @since 6.9.0
24902490
*
2491-
* @global int $wp_current_db_version The old (current) database version.
2491+
* @global int $wp_current_db_version The old (current) database version.
2492+
* @global wpdb $wpdb WordPress database abstraction object.
24922493
*/
24932494
function upgrade_690() {
24942495
global $wp_current_db_version, $wpdb;
@@ -2503,6 +2504,10 @@ function upgrade_690() {
25032504
$active_plugins[ $key ] = $new_plugin;
25042505
update_option( 'active_plugins', $active_plugins );
25052506
}
2507+
2508+
if ( $wp_current_db_version < 60716 ) {
2509+
$wpdb->query( "ALTER TABLE $wpdb->posts ADD INDEX type_status_author (post_type,post_status,post_author)" );
2510+
}
25062511
}
25072512

25082513
/**

src/wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
* @global int $wp_db_version
2525
*/
26-
$wp_db_version = 60497;
26+
$wp_db_version = 60716;
2727

2828
/**
2929
* Holds the TinyMCE version.

0 commit comments

Comments
 (0)