title: SQLite NOT IN query is slow
body: <p>I have two tables - <code>Keys</code> and <code>KeysTemp</code>.
  <code>KeysTemp</code> contains temporary data which should be merged with <code>Keys</code> using the <code>Hash</code> field.
  Here is the query:</p>
  
  <pre><code>SELECT
      r.[Id]
  FROM
      [KeysTemp] AS k
  WHERE
      r.[Hash] NOT IN (SELECT [Hash] FROM [Keys] WHERE [SourceId] = 10)
  </code></pre>
  
  <p>I have indexes on both tables for <code>SourceId</code> and <code>Hash</code> fields:</p>
  
  <pre><code>CREATE INDEX [IdxKeysTempSourceIdHash] ON [KeysTemp]
  (
      [SourceId],
      [Hash]
  );
  </code></pre>
  
  <p>The same index for <code>Keys</code> table, but query is still very slow.
  There is 5 rows in temporary table and about 60000 in the main table. Query by hash takes about 27 milliseconds, but querying this 5 rows takes about 3 seconds.</p>
  
  <p>I also tried splitting index, i.e. creating different indexes for <code>SourceId</code> and <code>Hash</code>, but it works the same way. <code>OUTER JOIN</code> works even worse here. How to solve that issue?</p>
  
  <p><strong>UPDATE</strong>
  If I remove <code>WHERE [SourceId] = 10</code> from the query it completes in 30ms, that's great, but I need this condition :)</p>
  
  <p>Thanks</p>