title: MySQL "IN" operator performance on (large?) number of values
body: <p>I have been experimenting with Redis and MongoDB lately and it would seem that there are often cases where you would store an array of <strong>id's</strong> in either MongoDB or Redis. I'll stick with Redis for this question since I am asking about the MySQL <strong>IN</strong> operator.</p>
  
  <p>I was wondering how performant it is to list a large number (300-3000) of <strong>id's</strong> inside the IN operator, which would look something like this:</p>
  
  <pre><code>SELECT id, name, price
  FROM products
  WHERE id IN (1, 2, 3, 4, ...... 3000)
  </code></pre>
  
  <p>Imagine something as simple as a <strong>products</strong> and <strong>categories</strong> table which you might normally JOIN together to get the <strong>products</strong> from a certain <strong>category</strong>. In the example above you can see that under a given category in Redis ( <code>category:4:product_ids</code> ) I return all the product ids from the category with id 4, and place them in the above <code>SELECT</code> query inside the <code>IN</code> operator.</p>
  
  <p>How performant is this?</p>
  
  <p>Is this an "it depends" situation? Or is there a concrete "this is (un)acceptable" or "fast" or "slow" or should I add a <code>LIMIT 25</code>, or doesn't that help?</p>
  
  <pre><code>SELECT id, name, price
  FROM products
  WHERE id IN (1, 2, 3, 4, ...... 3000)
  LIMIT 25
  </code></pre>
  
  <p>Or should I trim the array of product id's returned by Redis to limit it to 25 and only add 25 id's to the query rather than 3000 and <code>LIMIT</code>-ing it to 25 from inside the query? </p>
  
  <pre><code>SELECT id, name, price
  FROM products
  WHERE id IN (1, 2, 3, 4, ...... 25)
  </code></pre>
  
  <p>Any suggestions/feedback is much appreciated!</p>