title: How to optimize MySQL "Order By Limit 1" in queries that join multiple tables?
body: <p>So I have a query like this:</p>
  
  <pre><code>SELECT tablea.name, tablea.views from tablea inner 
  join tableb on (tablea.id = tableb.id and tablea.balance &gt; 0) 
  order by tablea.views asc limit 1
  </code></pre>
  
  <p>However, the problem is that when I run it, it runs quite slow (4+ seconds).
  Interestingly, when the 'order by' clause is removed, while keeping the limit 1, it runs in 0.005 seconds (approx). </p>
  
  <p>Even more interestingly: when I don't join it to tableb, i.e.:</p>
  
  <pre><code>SELECT tablea.name, tablea.views from tablea 
  where tablea.balance &gt; 0 
  order by tablea.views asc limit 1
  </code></pre>
  
  <p>The query runs in 0.005 seconds usually.</p>
  
  <p>Notes:</p>
  
  <ul>
  <li>The column views in tablea is indexed</li>
  <li>tablea and tableb have a 1 to 1 relationship in terms of id, and roughly have the same amount of rows.</li>
  </ul>
  
  <p>Why is there such a drastic difference in performance between the first query, the first query when 'order by' is removed, and the second query? </p>
  
  <p>Would there anyway to make the sorting much faster when joining two tables?</p>