title: Postgresql IN operator Performance: List vs Subquery
body: <p>For a list of ~700 ids the query performance is over 20x slower than passing a subquery that returns those 700 ids. It should be the opposite.</p>
  
  <p>e.g. (first query takes under 400ms, the later 9600 ms)</p>
  
  <pre><code>select date_trunc('month', day) as month, sum(total)
  from table_x
  where y_id in (select id from table_y where prop = 'xyz') 
  and day between '2015-11-05' and '2016-11-04' 
  group by month
  </code></pre>
  
  <p>is 20x faster on my machine than passing the array directly:</p>
  
  <pre><code>select date_trunc('month', day) as month, sum(total) 
  from table_x
  where y_id in (1625, 1871, ..., 1640, 1643, 13291, 1458, 13304, 1407, 1765) 
  and day between '2015-11-05' and '2016-11-04' 
  group by month 
  </code></pre>
  
  <p>Any idea what could be the problem or how to optimize and obtain the same performance? </p>