Sub topic 7
How a Bitmap Index Stores Data
Prerequisites and the basic model
This chapter assumes you know SELECT, WHERE, table creation, and the idea that Oracle can locate a row through its ROWID. An index is a separate database structure that helps Oracle find table rows without examining every row.
A bitmap index stores a bitmap for each indexed key value. A bitmap is a sequence of bits, where each bit represents a possible row location. A bit set to 1 means that the corresponding row has the key value. A bit set to 0 means that it does not.
For example, suppose status contains three values:
| Row position | Status | `NEW` bitmap | `SHIPPED` bitmap | `CANCELLED` bitmap |
|---|---|---|---|---|
| 1 | NEW | 1 | 0 | 0 |
| 2 | SHIPPED | 0 | 1 | 0 |
| 3 | NEW | 1 | 0 | 0 |
| 4 | CANCELLED | 0 | 0 | 1 |
Oracle stores the bitmap information in an index structure that also connects matching bits to table rows. The table above is a simplified logical view. Oracle can compress bitmap data internally, so the physical representation is more compact than a literal set of uncompressed strings.
Why low cardinality matters
Cardinality is the number of distinct values in a column. A column such as status might have only NEW, SHIPPED, and CANCELLED. It has low cardinality. A column such as email usually has many distinct values and has high cardinality.
Bitmap indexes are effective when a column has relatively few distinct values and queries combine conditions. Oracle can combine bitmaps with fast bitwise operations such as AND and OR.
For example, a query might filter rows where:
status = 'SHIPPED'region = 'WEST'is_priority = 'Y'
Oracle can retrieve a bitmap for each condition and combine them before converting the remaining set bits into table row locations.
Creating a bitmap index
CREATE TABLE orders (
order_id NUMBER PRIMARY KEY,
customer_id NUMBER NOT NULL,
status VARCHAR2(10) NOT NULL,
order_date DATE NOT NULL,
email VARCHAR2(100)
);
CREATE BITMAP INDEX orders_status_bix
ON orders (status);The index has one logical bitmap for each distinct status value. When a row is inserted or its status changes, Oracle must update the relevant bitmap entries.
A bitmap index can represent a NULL value. This differs from a normal B-tree index, which generally does not store an entry when every indexed column is null. This makes bitmap indexes useful for some reporting filters involving missing values.
Logical layout
Storage and workload fit
Bitmap indexes use compact representations when many adjacent rows share the same value or when the bitmap compresses well. Their strength is read performance for analytical queries over large, mostly stable tables.
They are less suitable for transaction tables with frequent, concurrent inserts, updates, and deletes. A change to one row can affect bitmap structures shared by many rows. Concurrent sessions may therefore contend while modifying the same bitmap index. The index type must match the workload, not just the column's cardinality.
Exercise
A column has only three values, but its table receives frequent concurrent updates. Is a bitmap index automatically the best choice?
Show answer
No. Low cardinality favors a bitmap index for reads, but frequent concurrent DML can cause contention. A B-tree index may fit the workload better.