title: SQL Query: Need to speed up this query that diffs against two databases
body: <p>I have a query that works, but it's taking forever. It basically returns all the rows in table T (with a join condition) in database D not in table T2 (also with a join condition) in database D2:</p>
  
  <pre><code>select f.* from D.frames f
  join D.items i on i.id=f.item_id
  where f.item_id not in (
      select f2.item_id
      from D2.frames f2
      join D2.items i2 on i2.id=f2.item_id
      where i2.primary_type='xxx'
  )
  </code></pre>
  
  <p>Any help with speeding up this query is very much appreciated.</p>