title: MySql JOIN query with OR clause very slow
body: <p>I have the following query:</p>
  
  <pre><code>SELECT a.id, b.from, b.to FROM a INNER JOIN b ON a.id = b.from OR a.id = b.to;
  </code></pre>
  
  <p>which is extremely slow. </p>
  
  <p>If I remove the OR clause and run each query separately then the both queries execute under 1 second.</p>
  
  <pre><code>SELECT a.id, b.from, b.to FROM a INNER JOIN b ON a.id = b.from;
  SELECT a.id, b.from, b.to FROM a INNER JOIN b ON a.id = b.to; 
  </code></pre>
  
  <p>How can I speed up the original query (set up indexes) or redesign the query itself?</p>