Ticket #5649 (closed defect: fixed)

Opened 8 months ago

Last modified 8 months ago

to_ping query optimization

Reported by: misterbisson Assigned to: 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 (0.5 kB) - added by misterbisson on 01/12/08 16:46:53.

Change History

01/12/08 16:46:53 changed by misterbisson

  • attachment comment_to_ping.diff added.

01/12/08 16:51:34 changed by westi

  • owner changed from anonymous to westi.
  • status changed from new to assigned.
  • milestone changed from 2.6 to 2.5.

01/12/08 17:13:10 changed by westi

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

01/12/08 17:31:17 changed by westi

  • status changed from assigned to closed.
  • resolution set to fixed.

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

01/12/08 23:01:34 changed by lloydbudd

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.