[wp-trac] [WordPress Trac] #34012: post_exists() results in a bad query

WordPress Trac noreply at wordpress.org
Tue Feb 23 11:03:22 UTC 2021


#34012: post_exists() results in a bad query
-------------------------------------------------+-------------------------
 Reporter:  apokalyptik                          |       Owner:  whyisjake
     Type:  enhancement                          |      Status:  accepted
 Priority:  normal                               |   Milestone:  5.8
Component:  Posts, Post Types                    |     Version:  4.4
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch needs-testing has-unit-    |     Focuses:
  tests                                          |  performance
-------------------------------------------------+-------------------------
Description changed by SergeyBiryukov:

Old 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...
>
> {{{#!sql
> 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.

New 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 #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...

 {{{#!sql
 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.

--

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


More information about the wp-trac mailing list