title: How can I get this MySql WordPress query to run faster?
body: <p>I have the following query in WordPress running against some very large tables. Is there a way to reorganize it so it runs faster? Currently it's taking 8 seconds and that's too slow for my use case where I need to call it 600K times. The bit <code>wp_term_taxonomy.term_id = 18</code> is going to be dynamic as in: <code>wp_term_taxonomy.term_id = category_id</code></p>
  
  <pre><code>SELECT  `ID` AS athlete_id, `post_title` AS athlete_name, `post_name` AS athlete_slug,
          body_weight.weight, performance.speed
      FROM  `wp_posts`
      INNER JOIN  
        ( SELECT  `post_id`, `meta_value` AS weight
              FROM  `wp_postmeta`
              WHERE  (`meta_key` = 'athlete_weight')
        ) body_weight ON wp_posts.ID = body_weight.post_id
      INNER JOIN  
        ( SELECT  `post_id`, `meta_value` AS speed
              FROM  `wp_postmeta`
              WHERE  (`meta_key` = 'athlete_speed')
        ) performance ON wp_posts.ID = performance.post_id
      LEFT JOIN  wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
      LEFT JOIN  wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id =
                                           wp_term_taxonomy.term_taxonomy_id)
      LEFT JOIN  wp_terms ON (wp_terms.term_id = wp_term_taxonomy.term_id)
      WHERE  wp_posts.post_status = 'publish'
        AND  wp_posts.post_type = 'athlete'
        AND  ((wp_term_taxonomy.taxonomy = 'athletics_category'
                        AND  wp_term_taxonomy.term_id = 18)
                OR  (wp_terms.term_id is null)
             );
  </code></pre>