What the hell is PostgreSQL’s Bitmap Heap Scan

Paul Yeo
2 min readMay 10, 2021

If you’ve ever seen something like this and wondered what the hell this means you’re in luck.

An SQL index lookup requires (1) the tree traversal (2) following the linked list node chain (3) fetching the table data. In step (1) a query will traverse a B-tree to quickly find the page that holds the row(s). The rows themselves are nodes in a doubly linked list and the database will perform step (2) to find all entries that match the key. And lastly the database will use the row IDs found to get the records themselves.

Bitmap Index Scan means the database is performing the tree traversal and following the leaf node chain to find all matching entries. Once the database finds the matching entries, it will then sort the rows according to the physical storage location of the rows in the heap table and fetch the rows from the table. That last part is the Bitmap Heap Scan.

The cost means that Postgres expects it will “cost” 24.36 to retrieve 1080 rows this Index Scan will return and the width is the estimated size in bytes of the returned rows. The Bitmap Index Scan’s width is 0 here because we only need the address to the records and not return the values themselves.

--

--