Conceptual
Login

Bitmap Index Scan and Bitmap Heap Scan: Collecting Row Locations Before Reading Pages

When a query matches too many rows for a plain index scan but too few for a sequential scan, PostgreSQL uses a bitmap scan: a Bitmap Index Scan first reads the index and builds a map of which pages hold matching rows, then a Bitmap Heap Scan reads those pages once each, in physical order. This is the engine's way of turning many random reads into a smaller, ordered set of reads, and it is also how two indexes can be combined with BitmapAnd or BitmapOr for one query. Seeing this pair in a plan tells you the index helped but the result is in the middle range, not a pinpoint lookup.

Questions this Concept answers

  • Why is a bitmap scan a good fit for a result in the middle range of sizes?