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

WordPress Trac noreply at wordpress.org
Mon Sep 14 19:09:12 UTC 2015


#33871: comment_exists() results in a bad query
-------------------------+-----------------------------
 Reporter:  apokalyptik  |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Import       |    Version:  trunk
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 The function `comment_exists()` which is located in `src/wp-
 admin/includes/comment.php` composes a query that checks on two fields
 which are not included in any indexes in the database: `comment_author`
 and `comment_date`.

 I am unaware of how often this function is used "in the wild" but I do
 know that extensive use of it is made in certain importer plugins
 (including the WXR importer)

 For small comments tables this is not a signifigant problem (which is
 probably why it's flown under the radar for so long.)  But for very large
 sites with considerable numbers of comments calling this function will
 result in a full table scan.

 Simply using `comment_date_gmt` instead of comment_date we get to make use
 of an index which should normally have very high cardinality (even on very
 large sites) making scanning on the found comment_author values a
 massively more performant operation.

 Since I don't imagine it's safe to update the function itself for all
 sites I'm attatching a patch to add a new function, `comment_exists_gmt()`
 to migrate to as a nearly drop-in replacement (only requiring the obvious
 change of having to supply the gmt date specifically)

--
Ticket URL: <https://core.trac.wordpress.org/ticket/33871>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list