title: MySQL Query Select using sub-select takes too long
body: <p>I noticed something strange while executing a select from 2 tables:</p>
  
  <pre><code>SELECT * FROM table_1 WHERE id IN (
      SELECT id_element FROM table_2 WHERE column_2=3103);
  </code></pre>
  
  <p>This query took approximatively 242 seconds.</p>
  
  <p>But when I executed the subquery </p>
  
  <pre><code>SELECT id_element FROM table_2 WHERE column_2=3103
  </code></pre>
  
  <p>it took less than 0.002s (and resulted 2 rows).<br>
  Then, when I did </p>
  
  <pre><code>SELECT * FROM table_1 WHERE id IN (/* prev.result */)
  </code></pre>
  
  <p>it was the same: 0.002s.</p>
  
  <p>I was wondering why MySQL is doing the first query like that, taking much more time than the last 2 queries separately? Is it an optimal solution for selecting something based from the results of a sub-query?</p>
  
  <p>Other details: <code>table_1</code> has approx. 9000 rows, and <code>table_2</code> has 90000 rows.</p>
  
  <p>After I added an index on <code>column_2</code> from <code>table_2</code>, the first query took 0.15s.</p>