WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#34012 new enhancement

post_exists() results in a bad query

Reported by: apokalyptik Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.4
Component: Posts, Post Types Keywords: has-patch needs-unit-tests needs-testing
Focuses: performance Cc:

Description

The current post_exists() function in wp-admin/includes/post.php generates a poorly performing query (makes use of no indexes) This is basically a mirror issue to https://core.trac.wordpress.org/ticket/33871 for all the same reasons.

The fix is a little bit different because post_date_gmt is actually not indexed and post_date is deep inside of a compound index...

KEY `type_status_date` (`post_type`,`post_status`(1),`post_date`,`ID`),

I have attached a diff to modify post_exists such that it can take post_type and post_status in addition to post_date and so make use of the existing table indexes. In my testing this is almost always 2x as fast in the optimal circumstance and massively faster in exceptionally poor circumstances.

Attachments (2)

post.diff (2.2 KB) - added by apokalyptik 2 years ago.
fix for post_exists() query performance
34012.diff (3.4 KB) - added by MikeHansenMe 2 years ago.
Adds basic tests and includes previous patch

Download all attachments as: .zip

Change History (4)

@apokalyptik
2 years ago

fix for post_exists() query performance

#1 @DrewAPicture
2 years ago

  • Keywords has-patch needs-unit-tests needs-testing added

We're going to need unit tests for this.

@MikeHansenMe
2 years ago

Adds basic tests and includes previous patch

#2 @boonebgorges
2 years ago

In 34680:

Add unit tests for post_exists().

Props MikeHansenMe.
See #34012.

Note: See TracTickets for help on using tickets.