Ticket #5649 (closed defect (bug): fixed)

Opened 4 years ago

Last modified 4 years ago

to_ping query optimization

Reported by: misterbisson Owned by: westi
Priority: normal Milestone: 2.5
Component: Optimization Version: 2.3.2
Severity: normal Keywords: to_ping, mysql, query, optimization
Cc:

Description

In wp-includes/comment.php, the following query requires a full table scan and can't be improved by adding an index:

<code>$trackbacks = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE CHAR_LENGTH(TRIM(to_ping)) > 7 AND post_status = 'publish'");</code>

I can't see any obvious reasons why do_trackbacks would leave cruft in the to_ping field, and any cruft that may exist would get cleared after going through do_trackbacks again. So I'm proposing this replacement:

$trackbacks = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE to_ping <> AND post_status = 'publish'");

Attachments

comment_to_ping.diff Download (551 bytes) - added by misterbisson 4 years ago.

Change History

  • Owner changed from anonymous to westi
  • Status changed from new to assigned
  • Milestone changed from 2.6 to 2.5

Checking through my live sites db - I have two posts with to_ping containing blank cruft.

  • Status changed from assigned to closed
  • Resolution set to fixed

(In [6603]) Simplify to_ping query. Fixes #5649 props misterbisson.

For reference: Andy Skelton asking him to submit the above patch, from [wp-hackers] to_ping query optimization Hey Casey! Your query looks great to my eyes. I would guess that the existing code was written to avoid selecting rows full of spaces or shorter than ' http://' (7 chars). It would be more efficient to a) use your query, and b) make sure the field is empty when all valid pings have been sent.

Note: See TracTickets for help on using tickets.