> **Bitmap And / Bitmap Or**
> <table>
> <tr>
> <td width="25%"><img src="assets/ex_bitmapandbitmapor.png"></td>
> <td>Combines multiple TID bitmaps using bitwise logic.</td>
> </tr>
> </table>
>
> ```sql
> -- Combining results from two separate indexes
> SET enable_seqscan = off;
>
> EXPLAIN (ANALYZE, COSTS, BUFFERS, VERBOSE)
> SELECT * FROM animals
> WHERE species_id = 1 OR species_id = 5;
> ```
>
> 
>
> <!-- 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=56.37..190.37 rows=3600 width=27) (actual time=0.092..0.508 rows=4000 loops=1)
> Output: id, name, species_id, created_at
> Recheck Cond: ((animals.species_id = 1) OR (animals.species_id = 5))
> Heap Blocks: exact=74
> Buffers: shared hit=80
> -> BitmapOr (cost=56.37..56.37 rows=4000 width=0) (actual time=0.078..0.078 rows=0 loops=1)
> Buffers: shared hit=6
> -> Bitmap Index Scan on idx_animals_species_id (cost=0.00..27.29 rows=2000 width=0) (actual time=0.044..0.044 rows=2000 loops=1)
> Index Cond: (animals.species_id = 1)
> Buffers: shared hit=3
> -> Bitmap Index Scan on idx_animals_species_id (cost=0.00..27.29 rows=2000 width=0) (actual time=0.034..0.034 rows=2000 loops=1)
> Index Cond: (animals.species_id = 5)
> Buffers: shared hit=3
> Planning:
> Buffers: shared hit=84
> Planning Time: 0.364 ms
> Execution Time: 0.655 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_and.svg" style="width: 48%;"><img src="assets/ex_bmp_or.svg" style="width: 48%;"></td>
> <td><b>Performance</b></td><td>Combines index-produced TID bitmaps before visiting the heap, avoiding unnecessary page fetches.</td>
> </tr>
> <tr><td><b>Cost</b></td><td><code>input bitmap costs + bitmap combination + matching heap pages</code></td></tr>
> </table>