↑↓ select ↵ open ⌫ change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Wiki / Plan Nodes / Bitmap

Bitmap Index Scan

BitmapIndexScan

Scans an index and produces a bitmap of matching tuple locations.

Reading PostgreSQL 18.6.

Description

Scans an index and produces a bitmap of matching tuple locations.

Core node tag
T_BitmapIndexScan
Structured EXPLAIN Node Type
Bitmap Index Scan
Inputs
An index
Output
Tuple-location bitmap, not a tuple stream
Executor initializer
ExecInitBitmapIndexScan
Memory mechanism
bitmap-lossification

EXPLAIN names and attributes

Structured formats use the Node Type above. Text-format spellings can also include operation, strategy, join type, scan direction or aggregation-stage attributes.

Text names recorded by this source: Bitmap Index Scan.

Parallel-aware and parallel-safe are different plan properties. A node running inside a parallel worker is not necessarily a parallel-aware node.

Memory and temporary storage

The node allocates a tuple-location bitmap using a work_mem-derived budget. A bitmap can retain page-level lossy entries instead of every tuple location; heap rechecks then remain necessary.

Parallel execution and instrumentation

The source callbacks below can coordinate execution or collect worker instrumentation. Their presence is not a blanket claim that this node supports a shared parallel scan or shared state.

Callbacks in this build: ExecBitmapIndexScanEstimate, ExecBitmapIndexScanInitializeDSM, ExecBitmapIndexScanInitializeWorker, ExecBitmapIndexScanRetrieveInstrumentation.

Same-version manual discussion

Index Scan nodes (as well as Bitmap Index Scan and Index-Only Scan nodes) show an “ Index Searches ” line that reports the total number of searches across all node executions/ loops :

Here we see a Bitmap Index Scan node that needed 4 separate index searches. The scan had to search the index from the tenk1_thous_tenthous index root page once per integer value from the predicate's IN construct. However, the number of index searches often won't have such a simple correspondence to the query predicate:

Examples from this manual build

Example copied from the PostgreSQL 18.6 manual; it was not executed for this collection.

Now, let's make the condition more restrictive:

EXPLAIN SELECT * FROM tenk1 WHERE unique1 < 100;

                                  QUERY PLAN
------------------------------------------------------------------------------
 Bitmap Heap Scan on tenk1  (cost=5.06..224.98 rows=100 width=244)
   Recheck Cond: (unique1 < 100)
   ->  Bitmap Index Scan on tenk1_unique1  (cost=0.00..5.04 rows=100 width=0)
         Index Cond: (unique1 < 100)

Example copied from the PostgreSQL 18.6 manual; it was not executed for this collection.

Now let's add another condition to the WHERE clause:

EXPLAIN SELECT * FROM tenk1 WHERE unique1 < 100 AND stringu1 = 'xxx';

                                  QUERY PLAN
------------------------------------------------------------------------------
 Bitmap Heap Scan on tenk1  (cost=5.04..225.20 rows=1 width=244)
   Recheck Cond: (unique1 < 100)
   Filter: (stringu1 = 'xxx'::name)
   ->  Bitmap Index Scan on tenk1_unique1  (cost=0.00..5.04 rows=100 width=0)
         Index Cond: (unique1 < 100)

Executor implementation notes

nodeBitmapIndexscan.c Routines to support bitmapped index scans of relations

If we have runtime keys and they've not already been set up, do it now. Array keys are also treated as runtime keys; note that if ExecReScan returns with biss_RuntimeKeysReady still false, then there is an empty array key so we should do nothing.

Prepare the result bitmap. Normally we just create a new one to pass back; however, our parent node is allowed to store a pre-made one into node->biss_result, in which case we just OR our tuple IDs into the existing bitmap. (This saves needing explicit UNION steps.)

Recalculates the values of any scan keys whose value depends on information known at runtime, then rescans the indexed relation.

Reset the runtime-key context so we don't leak memory as each outer tuple is scanned. Note this assumes that we will recalculate *all* runtime keys on each call.

EXPLAIN identity in core source

case T_BitmapIndexScan:
			pname = sname = "Bitmap Index Scan";
			break;

EXPLAIN labels in this source build

Text-format labelStructured node identity
Bitmap Index ScanBitmap Index Scan

Related entries

Documentation and source

Source build
Version
18.6
Build
PostgreSQL 18.6 source archive
Source fingerprint
555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f

Compare versions

PostgreSQL 17 → 18: changed.

--- PostgreSQL 17
+++ PostgreSQL 18
@@ -2,7 +2,12 @@
   "initializer": "ExecInitBitmapIndexScan",
   "memory_mechanism": "bitmap-lossification",
   "node_tag": "T_BitmapIndexScan",
-  "parallel_callbacks": [],
+  "parallel_callbacks": [
+    "ExecBitmapIndexScanEstimate",
+    "ExecBitmapIndexScanInitializeDSM",
+    "ExecBitmapIndexScanInitializeWorker",
+    "ExecBitmapIndexScanRetrieveInstrumentation"
+  ],
   "partial_modes": [],
   "strategies": [],
   "text_names": [

Compares recorded interfaces and attributes. Source fingerprints and build metadata are excluded; an absent sample is not proof of the introduction or removal release.

Related entries

Export JSON · Back to Plan Nodes · Recorded in PostgreSQL 10 through 20; the first sample is not necessarily its introduction.