title: Mysql query optimisation - 50k+ Rows
body: <p>I'm querying 50k+ rows with this query and it is taking 1.2759 seconds. What do you think is the best way to optimise it. The data updates every second or so but I could cache it for say 20 seconds. I've been looking into memcached for this, but is there a way to optimize this query? There is already indexes on most of the columns.</p>
  
  <pre><code>SELECT `p`.`id` as performance_id, `p`.`performers`, `t`.`name` as track_name, `p`.`location`, `p`.`es_id`
  FROM (`performances` p)
  JOIN `users` u ON `p`.`user_id` = `u`.`id`
  JOIN `tracks` t ON `p`.`track` = `t`.`id`
  WHERE (p.status = 1 OR (p.status != 2 &amp;&amp; p.flagged &lt; 3))
  AND `p`.`prop` IN ('1', '2', '3', '4', '5', '6', '8', '11', '13') 
  AND `p`.`track` IN ('5', '15', '2', '3', '8', '6', '12', '4', '1') 
  AND `p`.`type` IN ('1', '0', '2') 
  ORDER BY `p`.`created` desc
  LIMIT 12 
  </code></pre>
  
  <p><strong>Update:</strong> So here is the output from my EXPLAIN plan.</p>
  
  <pre><code>+----+-------------+-------+--------+----------------------------------------+---------+---------+----------------------------------+-------+-----------------------------+
  | id | select_type | table | type   | possible_keys                          | key     | key_len | ref                              | rows  | Extra                       |
  +----+-------------+-------+--------+----------------------------------------+---------+---------+----------------------------------+-------+-----------------------------+
  |  1 | SIMPLE      | p     | range  | user_id,track,prop,flagged,status,type | status  | 2       | NULL                             | 27440 | Using where; Using filesort |
  |  1 | SIMPLE      | u     | eq_ref | PRIMARY,id                             | PRIMARY | 3       | staging.p.user_id                |     1 | Using index                 |
  |  1 | SIMPLE      | t     | eq_ref | PRIMARY                                | PRIMARY | 4       | staging.p.track                  |     1 | Using where                 |
  +----+-------------+-------+--------+----------------------------------------+---------+---------+----------------------------------+-------+-----------------------------+
  3 rows in set (0.00 sec)
  </code></pre>