Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#5649 closed defect (bug) (fixed)

to_ping query optimization

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


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 (1)

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

Download all attachments as: .zip

Change History (5)

#1 @westi
13 years ago

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

#2 @westi
13 years ago

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

#3 @westi
13 years ago

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

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

#4 @lloydbudd
13 years ago

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.