title: mysql index for < created_at and not in
body: <p>I want to get all rows older than x except those with a certain batch_id</p>
  
  <p>table t:</p>
  
  <pre><code>id, created_at, batch_id
  </code></pre>
  
  <p>query:</p>
  
  <pre><code>SELECT * FROM t 
  WHERE created_at &lt; '2019-01-01' 
  AND batch_id NOT IN (1,2,3)
  </code></pre>
  
  <p>The query is slow even though I have &lt; 1M rows.
  I have indexes on (created_at), (batch_id) and (created_at, batch_id).
  I expected the compound index to make it faster, but the DB decides to use created_at instead.</p>
  
  <p>There are about 100 rows for every batch_id</p>