title: MySQL: High amount of 'Sending data' with query in IN clause
body: <p>I'm performing the following mysql query:</p>
  
  <pre><code>SELECT * FROM foo WHERE foo.ID IN (SELECT bar.ID FROM bar)
  </code></pre>
  
  <p>I've learned that the inner query for <code>bar</code> returns a set/table of ID attributes to the outer query. I thought this happened in one step, since the inner query is completely independent from the outer query (in this case).<br>
  However, it appears that the inner query returns all found IDs one after another, leading to many many <code>Sending data</code> progresses (one for each returned ID). This is highly inefficient. Especially since when I put the results from <code>bar.ID</code> into the <code>IN</code> statement manually (for example, 1, 2, 3, 4, ..., 70, 71), it's MUCH faster, even though the amount of IDs is the same.</p>
  
  <p>Is there no way to tell MySQL that the inner query is independent and should send all found IDs all at once?</p>
  
  <p><strong>EDIT 1:</strong> Here is the explain output given when trying to perform a <code>LEFT OUTER JOIN</code>:
  <img src="https://i.stack.imgur.com/NPicr.png" alt="Output"></p>
  
  <p>The query:</p>
  
  <pre><code>    SELECT * FROM foo 
  LEFT OUTER JOIN bar ON  foo.ID=bar.ID 
  WHERE bar.Value &gt; 1000 
  ORDER BY foo.ID ASC
  </code></pre>