Bitmap Index
Bitmap Index
We will use the members table created in the CREATE INDEX tutorial for the demonstration.
The following query finds all female members of the members table:
SELECT
*
FROM
members
WHERE
gender = 'F';
The gender column has two distinct values, F for female and M for male. When a column
has a few distinct values, we say that this column has low cardinality.
Oracle has a special kind of index for these types of columns which is called a bitmap index.
A bitmap index is a special kind of database index which uses bitmaps or bit arrays. In a
bitmap index, Oracle stores a bitmap for each index key. Each index key stores pointers to
multiple rows.
For example, if you create a bitmap index on the gender column of the members table. The
structure of the bitmap index looks like the following picture:
Oracle uses a mapping function to convert each bit in the bitmap to the corresponding rowid
of the members table.
https://www.oracletutorial.com/oracle-index/oracle-bitmap-index/ 1/4
4/26/24, 9:27 PM Understanding Oracle Bitmap Index
For example, to create a bitmap index for the gender column, you use the following
statement:
Now, if you query members by gender, the optimizer will consider using the bitmap index:
SELECT
PLAN_TABLE_OUTPUT
FROM
TABLE(DBMS_XPLAN.DISPLAY());
https://www.oracletutorial.com/oracle-index/oracle-bitmap-index/ 2/4
4/26/24, 9:27 PM Understanding Oracle Bitmap Index
You should use the bitmap index for the columns that have low cardinality. To find the
cardinality of a column, you can use the following query:
So how low you can go with the bitmap index? A good practice is any column that has less
than 100 distinct values.
Maintaining a bitmap index takes a lot of resources, therefore, bitmap indexes are only good
for read-only tables or tables that have infrequently updates. Therefore, you often find
bitmap indexes are extensively used in the data warehouse environment.
Notice that using a bitmap index for a table that has many single-row updates, especially
concurrent single-row updates will cause a deadlock.
https://www.oracletutorial.com/oracle-index/oracle-bitmap-index/ 3/4
4/26/24, 9:27 PM Understanding Oracle Bitmap Index
Open two sessions and repeatedly execute one of the following statements in each session:
In this tutorial, you have learned how to use the Oracle bitmap index to speed up the query.
https://www.oracletutorial.com/oracle-index/oracle-bitmap-index/ 4/4