#34012 closed enhancement (fixed)
post_exists() results in a bad query
Reported by: | apokalyptik | Owned by: | whyisjake |
---|---|---|---|
Milestone: | 5.8 | Priority: | normal |
Severity: | normal | Version: | 4.4 |
Component: | Posts, Post Types | Keywords: | has-patch needs-testing has-unit-tests needs-dev-note |
Focuses: | performance | Cc: |
Description (last modified by )
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 #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 (4)
Change History (16)
#1
@
9 years ago
- Keywords has-patch needs-unit-tests needs-testing added
We're going to need unit tests for this.
#3
@
4 years ago
- Keywords has-unit-tests added; needs-unit-tests removed
I have an updated patch for this ticket with some relevant unit tests.
I'd really like to see how we can move this forward, large sites using the WordPress Importer plugin would really benefit from this performance fix.
This is my first patch, but please let me know if there's anything else I can do.
#4
@
4 years ago
- Milestone set to 5.8
- Owner set to whyisjake
- Status changed from new to accepted
Changes look good to me too. @SergeyBiryukov or @desrosj, any thoughts here?
#6
@
4 years ago
44314.diff is essentially @brettshumaker's patch with the following changes:
- Added a
@since
tag to the docblock for the new argument - A few coding standards nitpicks fixed in the unit tests
- Added a couple of tests for post type and post status combos: both happy and unhappy paths
Adding the status parameter to improve the query makes sense to me.
Edit: Sorry about the bad ticket number in the file name.
fix for post_exists() query performance