Writers on our large WordPress installation love to use the the content searching functionality. As convenient as this functionality is, the complexity of its queries slows down our database considerably. Here’s an example of an SQL query I found in our slow query log from just a few minutes ago:
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
FROM wp_posts
WHERE 1=1
AND (
((wp_posts.post_title LIKE '%Made%') OR (wp_posts.post_content LIKE '%Made%'))
AND ((wp_posts.post_title LIKE '%in%') OR (wp_posts.post_content LIKE '%in%'))
AND ((wp_posts.post_title LIKE '%the%') OR (wp_posts.post_content LIKE '%the%'))
AND ((wp_posts.post_title LIKE '%shade:%') OR (wp_posts.post_content LIKE '%shade:%'))
AND ((wp_posts.post_title LIKE '%Easy%') OR (wp_posts.post_content LIKE '%Easy%'))
AND ((wp_posts.post_title LIKE '%tips%') OR (wp_posts.post_content LIKE '%tips%'))
AND ((wp_posts.post_title LIKE '%to%') OR (wp_posts.post_content LIKE '%to%'))
AND ((wp_posts.post_title LIKE '%care%') OR (wp_posts.post_content LIKE '%care%'))
AND ((wp_posts.post_title LIKE '%for%') OR (wp_posts.post_content LIKE '%for%'))
AND ((wp_posts.post_title LIKE '%your%') OR (wp_posts.post_content LIKE '%your%'))
AND ((wp_posts.post_title LIKE '%outdoor%') OR (wp_posts.post_content LIKE '%outdoor%'))
AND ((wp_posts.post_title LIKE '%furniture%') OR (wp_posts.post_content LIKE '%furniture%'))
)
AND wp_posts.post_type="s5_post"
AND (
wp_posts.post_status="publish"
OR wp_posts.post_status="future"
OR wp_posts.post_status="draft"
OR wp_posts.post_status="pending"
OR wp_posts.post_status="private"
)
ORDER BY wp_posts.post_date DESC LIMIT 0, 20
Check out the size of that guy! It’s no wonder it runs slowly.
I’d be interested to hear ideas on how to code up some tweaks to this functionality to make it be a bit more efficient. (I already have a few ideas of my own; hopefully yours are better than mine! 🙂 )