What is wrong with this query that causes MySQL cpu usage to spike? The cpu usage is like this until the db runs out of memory.
$sql = "SELECT c.*
FROM hatt_postmeta a
inner join hatt_postmeta b
ON a .post_id = b .post_id
inner join hatt_postmeta c
ON a .post_id = c .post_id
WHERE ( a .meta_key = 'ht_size_width'
AND a .meta_value = 165 )
AND ( b .meta_key = 'ht_size_ratio'
AND b .meta_value = 70 )
AND c .meta_key = 'ht_size_diameter'
GROUP BY c .meta_value
ORDER BY c .meta_value ASC";
$result= $wpdb->get_results( $sql );

Update: every query is getting 100% cpu usage

I've fixed this by deleting orphaned terms. Orphans can cause poor SQL performance, so you can install some plugin to clean it out for you. Below is a list of plugins that you can use. Hope this helps.
http://www.wpoptimus.com/611/wordpress-plugins-cleanup-optimize-database-improve-performance
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With