title: Understanding postgres explain w/ bitmap heap/index scans
body: <p>I have a table w/ 4.5 million rows. There is no primary key. The table has a column <code>p_id</code>, type integer. There's an index, <code>idx_mytable_p_id</code> on this column using the <code>btree</code> method. I do:</p>
  
  <pre><code>SELECT * FROM mytable WHERE p_id = 123456;
  </code></pre>
  
  <p>I run an explain on this and see the following output:</p>
  
  <pre><code>Bitmap Heap Scan on mytable  (cost=12.04..1632.35 rows=425 width=321)
    Recheck Cond: (p_id = 543094)
    -&gt;  Bitmap Index Scan on idx_mytable_p_id  (cost=0.00..11.93 rows=425 width=0)
          Index Cond: (p_id = 543094)
  </code></pre>
  
  <p>Questions:</p>
  
  <ul>
  <li>Why is that query doing a heap scan and then a bitmap index scan?</li>
  <li>Why is it examining 425 rows? Why is the width of the operation 321?</li>
  <li>What is the cost of 12.04..1632.35 and 0.00..11.93 telling me?</li>
  </ul>
  
  <p>For the record there are 773 rows with the <code>p_id</code> value of 123456. There are 38 columns on <code>mytable</code>.</p>
  
  <p>Thanks!</p>