[wp-hackers] to_ping query optimization

Casey Bisson casey.bisson at gmail.com
Fri Jan 11 23:00:17 GMT 2008


This query from wp-includes/comment.php pops up regularly in my slow  
query logs:

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

It wouldn't be so bad if I didn't have 350,000 posts (it's a library  
catalog), but I'm at a lost about how to optimize the query without  
getting rid of the CHAR_LENGTH and TRIM functions. I created an index  
on to_ping, but mysql appears to ignore it because of the calculations.

It works beautifully when written as below, but what am I losing? How  
important is the "CHAR_LENGTH(TRIM(to_ping)) > 7" piece?

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

--Casey


More information about the wp-hackers mailing list