liveBook · Manning

Bitmap

As explained in Just Use Postgres!

A bitmap is a compact structure that records table-row or table-page locations selected by an index condition.

A bitmap records table-row or table-page locations matching an index condition so PostgreSQL can retrieve matching data in bulk. section 4.5.2

Bitmap access proceeds in two phases:

  • Bitmap Index Scan finds matching index entries and records their table locations without immediately fetching rows. section 4.5.2
  • Bitmap Heap Scan visits the referenced table rows, reducing repeated table lookups during multi-value searches. section 4.5.2
  • When matches consume more memory, PostgreSQL may record whole table pages instead of individual rows, producing lossy information. section 4.5.2

Retrieving several indexed values

A query using champion_title IN (...) produces a Bitmap Index Scan followed by a Bitmap Heap Scan. The plan reports five rows and four exact heap blocks, showing how matching locations are collected before table access. section 4.5.2

SELECT username, score, level 
FROM game.player_stats 
WHERE champion_title = 'Naval Warlord';

Open the indexed lookup example, then inspect the related execution plan to see bitmap access in runnable SQL. section 4.5.2

How Just Use Postgres! covers it

How deep it goes
Explains two-phase execution and exact versus lossy locations, without developing bitmap storage internals.
Examples
Uses PostgreSQL EXPLAIN plans for hash-index lookups, multi-value IN queries, and GIN-backed full-text searches.
What it assumes
Assumes familiarity with SQL queries, indexes, and PostgreSQL EXPLAIN output.
What you can do after
Diagnose/debug with it by reading Bitmap Index Scan, Bitmap Heap Scan, heap-block, and recheck-plan details.
How it connects
Connects bitmap index scans with bitmap heap scans, hash indexes, GIN indexes, and full-text search.

Also explained in

Compare how 2 books explain bitmap →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Just Use Postgres!. The section links point to the parts of the book it draws on.