Sub topic 7
How a Bitmap Index Stores Data
This chapter assumes you can create tables and B-tree indexes in Oracle and know what a ROWID is. It also assumes you know the optimizer picks an execution plan. Here you will see what a bitmap index holds on disk and how Oracle combines bitmaps to answer a query. The chapters after this one cover when bitmap indexes fit and why concurrent DML hurts them.
From one entry per row to one bitmap per value
A B-tree index stores one entry for every indexed row: the key value plus the ROWID. A bitmap index stores one bitmap for every distinct key value. A bitmap is a string of bits, one bit for each row in the table. A bit set to 1 means "this row has this key value". A bit set to 0 means it does not.
Take eight rows of an orders table with this status column:
| Row position | status |
|---|---|
| 1 | OPEN |
| 2 | SHIPPED |
| 3 | OPEN |
| 4 | CLOSED |
| 5 | SHIPPED |
| 6 | OPEN |
| 7 | OPEN |
| 8 | CLOSED |
A bitmap index on status holds three bitmaps:
| Key value | Bits for rows 1 to 8 |
|---|---|
| OPEN | 1 0 1 0 0 1 1 0 |
| SHIPPED | 0 1 0 0 1 0 0 0 |
| CLOSED | 0 0 0 1 0 0 0 1 |
Each row has a 1 in exactly one of the three bitmaps, because a row has only one status. The index size depends on the number of distinct values and the number of rows. With three values, the index is small. With a million distinct values it would be enormous, which is why bitmap indexes target low-cardinality columns.
How bit positions become ROWIDs
A bit has no address of its own. Oracle needs to turn "the 6th bit" into a physical row. Each bitmap index entry therefore stores four things:
- The key value, such as
OPEN. - A start ROWID.
- An end ROWID.
- The bitmap segment covering the rows between those two ROWIDs.
Oracle derives the ROWID of each set bit from the start ROWID. It does this by counting through the possible row slots in each block of the range. For this to work, Oracle needs to know the maximum number of rows a block can hold, so that every possible slot gets a bit position. That maximum is stored with the table, and a bitmap index forces Oracle to track it. Oracle sets bits for slots that never hold a row, such as unused space in a block. These bits are always 0 and cost very little because of compression.
A large table needs many entries per key value. Each entry covers one range of ROWIDs, and a key's complete bitmap is a series of these entries. They are stored in a B-tree structure keyed on the value and start ROWID, so a lookup still navigates a tree. The leaf entries just contain bitmap segments instead of single ROWIDs.
Compression
The bitmaps are compressed. A long run of zeros takes almost no space. This is why a bitmap on a column with few values is often far smaller than a B-tree index on the same column. It is also why the size grows quickly as cardinality grows, since each bitmap becomes sparser and less compressible.
You do not configure the compression. Oracle applies it automatically, and it decompresses segments as it works with them.
Creating a bitmap index
The following statements assume the orders table from the earlier chapters. They add sample rows that match the table above, create the bitmap index, and check that it exists.
INSERT INTO orders (order_id, customer_id, status, order_date)
VALUES (1, 10, 'OPEN', DATE '2026-01-05');
INSERT INTO orders (order_id, customer_id, status, order_date)
VALUES (2, 11, 'SHIPPED', DATE '2026-01-06');
INSERT INTO orders (order_id, customer_id, status, order_date)
VALUES (3, 12, 'OPEN', DATE '2026-01-07');
INSERT INTO orders (order_id, customer_id, status, order_date)
VALUES (4, 13, 'CLOSED', DATE '2026-01-08');
INSERT INTO orders (order_id, customer_id, status, order_date)
VALUES (5, 14, 'SHIPPED', DATE '2026-01-09');
INSERT INTO orders (order_id, customer_id, status, order_date)
VALUES (6, 15, 'OPEN', DATE '2026-01-10');
INSERT INTO orders (order_id, customer_id, status, order_date)
VALUES (7, 16, 'OPEN', DATE '2026-01-11');
INSERT INTO orders (order_id, customer_id, status, order_date)
VALUES (8, 17, 'CLOSED', DATE '2026-01-12');
COMMIT;
CREATE BITMAP INDEX orders_status_bix ON orders (status);
SELECT index_name, index_type, uniqueness
FROM user_indexes
WHERE table_name = 'ORDERS';The INDEX_TYPE column shows BITMAP for the new index. Because of how the rows map to bits, a bitmap index can never be unique. Bitmap indexes are a feature of Oracle Database Enterprise Edition, so this statement fails on other editions.
You can also build a composite bitmap index with several columns, for example (status, region). A single-column bitmap on each column is usually more flexible, because Oracle can combine them as needed. This is covered below.
Combining bitmaps
Bitmaps are cheap to combine because the operations are plain bit logic. Using the bitmaps above, the condition status IN ('OPEN', 'SHIPPED') is the bitwise OR of two bitmaps:
| Bitmap | Bits for rows 1 to 8 |
|---|---|
| OPEN | 1 0 1 0 0 1 1 0 |
| SHIPPED | 0 1 0 0 1 0 0 0 |
| OPEN OR SHIPPED | 1 1 1 0 1 1 1 0 |
Rows 1, 2, 3, 5, 6, and 7 qualify. Oracle converts those set bits to ROWIDs and reads only those rows. If a second bitmap index existed on another column, say region, a condition on both columns would AND the two bitmaps. Oracle can also use a MINUS operation for NOT and <> style conditions. No row is touched until the bitmap work is done.
This is the main strength of the structure. Several weak filters, each matching a large share of the table, can be combined into one selective result without reading the table.
What the plan shows
When the optimizer uses a bitmap index, the plan contains operations with BITMAP in their names. You can check this with EXPLAIN PLAN, as in the earlier chapter.
EXPLAIN PLAN FOR
SELECT order_id
FROM orders
WHERE status IN ('OPEN', 'SHIPPED');
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);On a table this small, the optimizer will often choose a full table scan, because reading eight rows is cheaper than any index work. On a larger table with representative statistics you can expect to see some of these operations:
| Plan operation | Meaning |
|---|---|
| BITMAP INDEX SINGLE VALUE | Reads the bitmap for one key value. |
| BITMAP INDEX RANGE SCAN | Reads the bitmaps for a range of key values. |
| BITMAP AND | Combines bitmaps where both conditions must be true. |
| BITMAP OR | Combines bitmaps where either condition can be true. |
| BITMAP MINUS | Removes the rows of one bitmap from another. |
| BITMAP CONVERSION TO ROWIDS | Turns set bits into ROWIDs for table access. |
| BITMAP CONVERSION COUNT | Counts set bits without reading the table. |
BITMAP CONVERSION COUNT is worth noting. A query such as SELECT COUNT(*) FROM orders WHERE status = 'OPEN' can be answered by counting 1 bits in one bitmap. The table is never read.
NULL values
A B-tree index does not store an entry when every indexed column is NULL, so WHERE col IS NULL cannot normally use it. A bitmap index does store NULLs. Oracle keeps a bitmap for the NULL key like any other value, so IS NULL and IS NOT NULL conditions can use a bitmap index. This is a real advantage on columns where the NULL test is a common filter.
Limits that follow from the structure
The design has several consequences that you should keep in mind before using it.
- A bitmap index cannot be unique. One bitmap holds many rows by design.
- High cardinality inflates the index. Many distinct values mean many mostly-empty bitmaps, and compression helps less.
- Updating one row touches a whole bitmap segment. A segment covers many rows, so changing one row's key value can affect the neighbors that share the segment. The next chapters cover the locking effects of this.
- Range predicates on bitmaps are less natural. Oracle can use a bitmap range scan, but a B-tree is usually better for large ranges on ordered data.
Summary of the model
- A bitmap index keeps one compressed bitmap per distinct key value.
- Each bit stands for a row slot, and the start and end ROWIDs of an entry tell Oracle how to map bits back to rows.
- Bitmaps for different conditions are combined with AND, OR, and MINUS before any table row is read.
- Plans show this work as
BITMAPoperations, finishing withBITMAP CONVERSION TO ROWIDSor a count. - NULLs are indexed, uniqueness is not possible, and the index is available only in Enterprise Edition.
Exercise
A table has 8 rows. Its bitmap for status = 'OPEN' is 1 0 1 0 0 1 1 0, and its bitmap for status = 'CLOSED' is 0 0 0 1 0 0 0 1. Which rows match status = 'OPEN' OR status = 'CLOSED', and which plan operation combines the two bitmaps?
Show answer
The OR of the two bitmaps is 1 0 1 1 0 1 1 1, so rows 1, 3, 4, 6, 7, and 8 match. The plan operation that combines them is BITMAP OR, followed by BITMAP CONVERSION TO ROWIDS to fetch the rows.
Exercise
Why can SELECT COUNT(*) FROM orders WHERE status = 'OPEN' be answered without reading the orders table when a bitmap index on status exists?
Show answer
The bitmap for 'OPEN' already marks every matching row with a 1 bit. Oracle can count the set bits in that bitmap, shown in the plan as BITMAP CONVERSION COUNT, so it never needs to visit the table blocks.