title: Cross Join much faster than Inner Join
body: <p>At work I came across this sort of query:</p>
  
  <pre><code>select distinct psv.pack_id from pack_store_variant psv, pack p 
  where p.id = psv.pack_id and p.store_id = 1 and psv.store_variant_id = 196;
  </code></pre>
  
  <p>Being new to the <code>select from table1, table2</code> I did a bit of searching and found out this does basically a cartesian product of the two tables. I thought that this is unnecessarily creating NxM rows, we can just use a regular join and it should work. So I wrote this query:</p>
  
  <pre><code>SELECT DISTINCT pack_id from (SELECT pack_id, store_id, store_variant_id 
  FROM pack JOIN pack_store_variant ON pack.id = pack_store_variant.pack_id) as comb 
  where comb.store_id = 1 AND comb.store_variant_id = 196;
  </code></pre>
  
  <p>Surprisingly when I did the comparison, the first one was an order of magnitude faster than mine. Does my query suck somehow? Or am I not understanding the difference between cross join/inner join properly?</p>