0% found this document useful (0 votes)
30 views4 pages

Bitmap Index

This document discusses Oracle bitmap indexes, which are a special type of index used for columns with low cardinality (few distinct values). It explains what bitmap indexes are, when to use them, and provides an example of creating a bitmap index on the gender column of a members table to speed up queries filtering on gender.

Uploaded by

Anand Rohit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views4 pages

Bitmap Index

This document discusses Oracle bitmap indexes, which are a special type of index used for columns with low cardinality (few distinct values). It explains what bitmap indexes are, when to use them, and provides an example of creating a bitmap index on the gender column of a members table to speed up queries filtering on gender.

Uploaded by

Anand Rohit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

4/26/24, 9:27 PM Understanding Oracle Bitmap Index

Oracle Bitmap Index


Summary: in this tutorial, you will learn how to use the Oracle bitmap index for indexing
columns with low cardinality.

Introduction to Oracle 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:

It has two separate bitmaps, one for each gender.

Oracle uses a mapping function to convert each bit in the bitmap to the corresponding rowid
of the members table.

The syntax for creating a bitmap index is quite simple as follows:

https://www.oracletutorial.com/oracle-index/oracle-bitmap-index/ 1/4
4/26/24, 9:27 PM Understanding Oracle Bitmap Index

CREATE BITMAP INDEX index_name


ON table_name(column1[,column2,...]);

For example, to create a bitmap index for the gender column, you use the following
statement:

CREATE BITMAP INDEX members_gender_i


ON members(gender);

Now, if you query members by gender, the optimizer will consider using the bitmap index:

EXPLAIN PLAN FOR


SELECT
*
FROM
members
WHERE
gender = 'F';

SELECT
PLAN_TABLE_OUTPUT
FROM
TABLE(DBMS_XPLAN.DISPLAY());

The following picture shows the execution plan:

https://www.oracletutorial.com/oracle-index/oracle-bitmap-index/ 2/4
4/26/24, 9:27 PM Understanding Oracle Bitmap Index

When to use Oracle bitmap indexes


Low cardinality columns

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:

SELECT column, COUNT(*)


FROM table_name
GROUP BY column;

So how low you can go with the bitmap index? A good practice is any column that has less
than 100 distinct values.

Infrequently updated or read-only tables

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.

The following statement creates a new table named bitmap_index_demo :

https://www.oracletutorial.com/oracle-index/oracle-bitmap-index/ 3/4
4/26/24, 9:27 PM Understanding Oracle Bitmap Index

CREATE TABLE bitmap_index_demo(


id INT GENERATED BY DEFAULT AS IDENTITY,
active NUMBER NOT NULL,
PRIMARY KEY(id)
);

The following statement creates a bitmap index on the active column:

CREATE BITMAP INDEX bitmap_index_demo_active_i


ON bitmap_index_demo(active);

Open two sessions and repeatedly execute one of the following statements in each session:

INSERT INTO bitmap_index_demo(active)


VALUES(1);

INSERT INTO bitmap_index_demo(active)


VALUES(0);

The following error will occur:

ORA-00060: deadlock detected while waiting for resource

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

You might also like