title: Postgres choosing BTREE instead of BRIN index
body: <p>I'm running Postgres 9.5 and am playing around with BRIN indexes.  I have a fact table with about 150 million rows and I'm trying to get PG to use a BRIN index.  My query is:</p>
  
  <pre><code>select sum(transaction_amt), 
         sum (total_amt) 
  from fact_transaction 
  where transaction_date_key between 20170101 and 20170201 
  </code></pre>
  
  <p>I created both a BTREE index and a BRIN index (default pages_per_range value of 128) on column transaction_date_key (the above query is referring to January to February 2017).  I would have thought that PG would choose to use the BRIN index however it goes with the BTREE index.  Here is the explain plan:</p>
  
  <p><a href="https://explain.depesz.com/s/uPI" rel="noreferrer">https://explain.depesz.com/s/uPI</a></p>
  
  <p>I then deleted the BTREE index, did a vacuum / analyze on the the table, and re-ran the query and it <em>did</em> choose the BRIN index however the run time was considerably longer:</p>
  
  <p><a href="https://explain.depesz.com/s/5VXi" rel="noreferrer">https://explain.depesz.com/s/5VXi</a></p>
  
  <p>In fact my tests were all faster when using the BTREE index rather than the BRIN index.  I thought it was supposed to be the opposite?</p>
  
  <p>I'd prefer to use the BRIN index because of its smaller size however I can't seem to get PG to use it.  </p>
  
  <p>Note: I loaded the data, starting from January 2017 through to June 2017 (defined via transaction_date_key) as I read that physical table ordering makes a difference when using BRIN indexes.  </p>
  
  <p>Does anyone know why PG is choosing to use the BTREE index and why BRIN is so much slower in my case?</p>