title: MySQL subquery really slow... Workaround?
body: <p>I've tested the following seemingly simple query on MySQL 5.0, 5.1, 5.5 and found it to be extremely slow.</p>
  
  <pre><code>select * from entry where session_id in
      (select session_id from entry where created_at &gt; [some timestamp])
  </code></pre>
  
  <p>Multiple entry's can have the same session ID, but different created_at timestamps.
  The query is meant to grab all entry's that have at least one entry from the same session_id whose created_at is greater than the specified timestamp.</p>
  
  <p>I've seen others speak of MySQL subquery performance issues with similar queries, and that MySQL considers the subquery a dependent query and it is doing a full table scan on the outer query.  Suggested workarounds were something like:</p>
  
  <pre><code>select * from entry where session_id in
      (select session_id from
          (select session_id from entry where created_at &gt; [some timestamp])
      as temp)
  </code></pre>
  
  <p>However, this hack doesn't work for me and makes it even slower.</p>
  
  <p>Any ideas on how to rewrite this query?</p>