Sub topic 8
Where Bitmap Indexes Work Well
Assume you know basic SELECT and WHERE syntax, can create Oracle tables and indexes, and understand that the optimizer chooses an execution plan. This chapter focuses on choosing bitmap indexes for the right workload.
The bitmap index model
A bitmap index stores a bit for each table row for each indexed value. A bit is set when a row contains that value. The index also keeps enough information to map matching bits back to rows.
For example, a status column might contain only NEW, SHIPPED, and CANCELLED. Oracle can represent each value as a bitmap and combine bitmaps with fast bit operations.
This structure makes bitmap indexes useful when a query combines several conditions. Oracle can perform AND, OR, and other operations on compact bitmaps before visiting the table rows.
Low-cardinality columns
Cardinality is the number of distinct values in a column. A column with only a few possible values has low cardinality. Examples include:
- A status column with five states.
- A flag column containing
YandN. - A gender or age-group column.
- A region column with a small, fixed set of regions.
- A product category column in a reporting warehouse.
Low cardinality does not automatically mean that a bitmap index is correct. The access pattern matters too. Bitmap indexes work best when queries filter on these columns and the table is read much more often than it is changed.
A bitmap index can be especially effective in a data warehouse. Reports often filter on several dimensions at once, such as region, channel, status, and month. Oracle can combine the corresponding bitmap entries and then retrieve the small set of matching rows.
CREATE BITMAP INDEX orders_status_bix
ON orders (status);Bitmap indexes are an Enterprise Edition feature. Check the edition and licensing rules for the Oracle installation before using them.
Read-mostly tables
A read-mostly table receives few changes after data is loaded. Typical examples include:
- Fact tables used by analytical reports.
- Historical data loaded in batches.
- Decision-support tables queried by many users.
- Data marts where dimensions are stable during the reporting period.
A bitmap index can reduce the work needed to answer selective combinations of predicates. However, test with representative data and queries. The optimizer may still choose a full table scan when a large percentage of the table matches.
Concurrent DML and locking
DML means insert, update, and delete operations. Bitmap indexes can create lock contention during concurrent DML because one bitmap piece can describe many rows. Two sessions changing different rows may need to modify the same bitmap structure.
This can cause sessions to wait for each other. The problem is more serious when many users update the indexed table at the same time. Batch loading can reduce the risk, especially when changes are performed in controlled windows.
| Workload | Bitmap index fit |
|---|---|
| Read-mostly warehouse with low-cardinality filters | Good candidate |
| Frequently updated order-entry table | Usually poor candidate |
| High-cardinality unique identifier lookup | Prefer a B-tree |
| Reports combining several low-cardinality dimensions | Often a good candidate |
Choosing safely
Choose a bitmap index when all three conditions are broadly true:
- The indexed column has low or moderate cardinality.
- Queries frequently filter on that column or combine it with other dimensions.
- The table has limited concurrent DML.
Use a B-tree index instead when the table is highly transactional, the column has many distinct values, or users need frequent point lookups.
Exercise
A warehouse table has ten million rows and a channel column with four values. Reports read the table throughout the day, and a nightly batch loads new rows. Is a bitmap index a reasonable candidate, and what must you test?
Show answer
Yes. The low cardinality and read-mostly workload fit a bitmap index. Test report plans, load duration, storage, and any locking or contention during the batch.