> **Bitmap Index Scan**
> <table>
> <tr>
> <td width="25%"><img src="assets/ex_bitmapindexscan.png"></td>
> <td>Traverses an index to find matching rows but instead of fetching them immediately, it populates a bitmap in memory marking which pages in the table contain matches. This bitmap can then be combined with others (AND/OR) before the heap is visited.</td>
> </tr>
> </table>
>
> ```sql
> -- Querying a medium-selectivity range
> EXPLAIN (ANALYZE, COSTS, BUFFERS, VERBOSE)
> SELECT * FROM animals WHERE species_id = 1;
> ```
>
> 
>
> <!-- literal-explain-plan
> Captured EXPLAIN provenance for the adjacent reader-facing visual plan.
> Canonical capture metadata lives in scratch/actual_operation_plans.json.
>
> Bitmap Heap Scan on public.animals (cost=27.79..126.78 rows=2000 width=27) (actual time=0.059..0.353 rows=2000 loops=1)
> Output: id, name, species_id, created_at
> Recheck Cond: (animals.species_id = 1)
> Heap Blocks: exact=74
> Buffers: shared hit=77
> -> Bitmap Index Scan on idx_animals_species_id (cost=0.00..27.29 rows=2000 width=0) (actual time=0.045..0.045 rows=2000 loops=1)
> Index Cond: (animals.species_id = 1)
> Buffers: shared hit=3
> Planning:
> Buffers: shared hit=86
> Planning Time: 0.416 ms
> Execution Time: 0.442 ms
> -->
>
>
> <!--
> Raw-capture provenance — separate run.
> SQL, setup, dataset, settings, and scope: artifacts/chapter4_capture_matrix.json.
> Target: PostgreSQL 18.x companion fixture. Cache state: uncontrolled.
> Boundary: pg_wait_tracer backend execution root; client states are included when the chart shows them.
> Fidelity: exact pg_wait_tracer export. Not the adjacent EXPLAIN run; compare state shape, not durations.
> -->
>
> 
>
> <table>
> <tr>
> <td rowspan="2" width="25%"><img src="assets/ex_bmp_index.svg"></td>
> <td><b>Performance</b></td><td>Efficient for medium-selectivity predicates; bitmap combination delays heap access until matching pages are known.</td>
> </tr>
> <tr><td><b>Cost</b></td><td><code>index traversal + bitmap construction + matching heap pages</code></td></tr>
> </table>