WordPress to_ping Query Optimization

The WordPress team has taken up the issue of performance optimization pretty seriously, and I look forward to the fruits of their efforts, but I’m also casting a critical eye on my own code. Thanks to caching and a hugely optimized query architecture, Scriblio is now performing better than ever, and I’m now looking at the next tier of problems.

First among them is a WordPress query that runs to find which posts have pingbacks or trackbacks waiting to be processed. As it was originally written, it looked like this:

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

The problem is that the query requires a full table scan, and it can’t be optimized simply by creating an index on to_ping because CHAR_LENGTH(TRIM(to_ping)) > 7 requires inspecting every row and applying the functions before the result can be tested. As written, the query could take as long as 15 minutes to execute on a busy table of 350,000 rows.

Once I read through the code and determined that it’s very unlikely that cruft would be left in to_ping, or that any that was there would get removed once processed through the ping functions, I decided to try the query below. (Hat tip also to Andy Skelton for sanity checking my reading of the code.)

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

A trac ticket has been created and patch added, but despite the optimized query, a table as large as I’m working with probably needs an index to keep things running smoothly. So here’s what I’ve got:

KEY ping_status ( to_ping(1), post_status )

I’ve not yet confirmed that this is the most optimal index, but queries now take a fraction of a second to complete.

No Comments

No comments yet.

Comments RSS TrackBack Identifier URI

Leave a comment

 

User contributed tags for this post:

ping www.sex.com (16) - wordpress to_ping (13) - wordpress query (12) - wordpress queries (8) - wordpress query comments (5) - PING WWW XXL COM (5) - ping.www.xxl (4) - to_ping (4) - PING www.xxL.com (4) - query optimization (4) - WWW.XXL SEX.NET (4) - WORDPRESS query post (3) - query (3) - wordpress search query (3) - wordpress mysql optimization (3) - wordpress (3) - wordpress mysql query optimization (2) - wordpress optimization (2) - xxl.sex.net (2) - optimize wordpress (2) - wordpress query posts (2) - to_ping wordpress (2) - wordpress query $post->ID (2) - ping www.89.com (2) - www.sex clip ping.com (2) - wordpress latest posts optimize query (2) - wordpress reduce mysql query (2) - how to find wordpress query long (2) - wordpress to_ping query optimization (2) - optimize mysql queries wordpress (2) - optimize wordpress queries (2) - optimizing wordpress tables for mysql query cache (1) - temp wordpress query (1) - ping://www.xxl.com (1) - optimize 2 select in one query (1) - wordpress comments query (1) - post query in wordpress (1) - wordpress query posts by latest comment (1) - wordpress reduce querey (1) - optimize wordpress mysql queries (1) - reducing wordpress queries (1) - mysql query wordpress recent posts (1) - what is wordpress query (1) - wordpress query once (1) - getting wordpress to include comments in search query (1) - wordpress querypost (1) - xxxl sex.net (1) - www.xxl.com for sex download (1) - mysql 4 query optimizer (1) - query optimizer plugin wordpress (1) - search query post in wordpress (1) - open source projects query optimization (1) - how to reduce mysql query (1) - optimize apache mysql wordpress (1) - to_ping in wordpress (1) - query post wordpress (1) - wordpress table query (1) - mysql optimization wordpress (1) - optimization index query mysql (1) - wordpress query most comments (1) - catalog php wordpress table (1) - wordpress $query (1) - MYSQL query to select post category wordpress (1) - query wordpress table (1) - wordpress select optimisation (1) - open source query optimizers (1) - PING www.Sex.com/ (1) - wordpress optimizing queries (1) - www.xxl.sex (1) - reduce mysql wordpress queries (1) - how to optimize wordpress queries (1) - wordpress comment query (1) - 3 most popular posts wordpress query (1) - wordpress search query optimize (1) - mysql query optimization casting (1) - wordpress apache optimization (1) - what is the query optimization how to do query optimise (1) - comments query wordpress (1) - wordpress popular searches (1) - optimize wordpress apache mysql (1) - mysql query optimization (1) - wordpress reduce queries (1) - reduce queries wordpress (1) - wordpress query log (1) - how to reduce wordpress queries (1) - WWW XXL SEXNET (1) - sync replaced iphone contacts (1) - ralph simpsons fox intro movie download (1) - how queries wordpress (1) - 61 queries wordpress (1) - log wordpress query (1) - post optimization of search query (1) - wordpress query-comments (1) - wordpress optimize query (1) - wordpress query select post (1) - wordpress optimize queries (1) - reduce query wordpress (1) - queries seconds wordpress (1) - www.wolde sex.com (1) - www.xxl sex .net (1) - query optimization wordpress (1) - www 89 ping com (1) - optimize wordpress for large tables (1) - optimize wordpress apache (1) - wordpress query catalog id (1) - wordpress url optimization (1) - reduce wordpress queries (1) - wordpress search query optimization (1) - wordpress query post length (1) - library catalog query wordpress (1) -