Table of contents
1.
Introduction
2.
Bitmap Index Structure
3.
How to use Bitmaps
4.
CREATE BITMAP INDEX
5.
Features of Bitmap Indexing in DBMS
6.
Applications of Bitmap Indexing in DBMS
7.
Advantages of Bitmap Indexing in DBMS
8.
Disadvantages of Bitmap Indexing in DBMS
9.
Frequently Asked Questions
9.1.
What is an index?
9.2.
What is bitmap indexing of OLAP data?
9.3.
What is the difference between the bitmap index and b-tree?
9.4.
What is the use of an index?
10.
Conclusion
Last Updated: Mar 27, 2024
Easy

Bitmap Indexing in DBMS

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Bitmap indexing is a type of database indexing built on a single key. It uses bitmaps. Bitmap indexing is used for large databases in which the cardinality of columns is very low. And those columns are frequently used in the query. It retrieves data quickly for low cardinality columns in massive databases.

Bitmap Indexing in DBMS

Let us understand this by an example.

  • Suppose your college opens after this covid situation. Then college must have to maintain the vaccination detail of every student. 
  • We will have a Student table having columns student_id, students_ name, doses, covid_test. 
  • The doses column will have only three values 0,1, and 2. Similarly, the covid_test column has only two positive or negative values. These data will be maintained only once during students' entry into college. 
  •  But these columns will be frequently used in queries to retrieve data like the number of fully vaccinated students. We must use something fast enough to give quick results. 
  • Any traditional file method is not that quick to respond. So, we will use Bitmap indexing here. 
Student_id Student_name doses covid_test
      1     Rahul   1   negative
      2     Priya   2   negative
      3     Neha   1   positive
      4     Rohan   2   positive
      5     Saksham   0   negative

Also See, Multiple Granularity in DBMS

Must Recommended Topic, Schema in DBMS

Bitmap Index Structure

The Bitmap Index Structure is a data structure used in databases and information retrieval systems for efficient indexing and querying of large datasets. It's primarily used for indexing boolean or categorical data, where each value is associated with a unique identifier or position in the dataset. Bitmap index structure consist of:

  • Bitmap Representation: In a Bitmap Index, each distinct value in the dataset is assigned a unique position, typically represented as a bit in a bitmap. The bitmap is essentially an array of bits, where each bit corresponds to a specific value or attribute in the dataset.
  • Binary Encoding: Each bit in the bitmap represents the presence or absence of a particular value in the dataset. If a value is present, its corresponding bit is set to 1; otherwise, it's set to 0. This binary encoding allows for efficient storage and retrieval of information.
  • Indexing Boolean or Categorical Data: Bitmap indexes are particularly effective for boolean or categorical data, where the number of distinct values is relatively small compared to the size of the dataset. Examples include gender, age groups, product categories, or boolean attributes like "is_active".
  • Bitwise Operations: Bitmap indexes support efficient bitwise operations such as AND, OR, and NOT, which enable fast query processing. For example, to find all records where both condition A and condition B are true, the corresponding bitmaps for A and B can be ANDed together.
  • Space Efficiency: Bitmap indexes are highly space-efficient, especially when dealing with sparse data or datasets with low cardinality. They require minimal storage compared to traditional index structures like B-trees, which can result in significant storage savings for large datasets.
  • Query Performance: Bitmap indexes are optimized for certain types of queries, such as equality, range, and set membership queries. They excel in scenarios where queries involve multiple boolean conditions or where the dataset is updated infrequently.
  • Use Cases: Bitmap indexes find applications in various domains, including data warehousing, business intelligence, data mining, and scientific computing. They are commonly used in OLAP (Online Analytical Processing) systems to accelerate query performance on multidimensional datasets.

How to use Bitmaps

Bit: A bit can have only two values, either 0 or 1. These two values can be used as true or false. In bitmap indexing, bits represent unique values in low cardinality columns.

If doses are the column indexed, there will be five bits in the bitmap index because we have five rows in the Student table. Here Bitmap Index has a value 00001 for no covid doses(only the last student has not taken any dose of vaccine ),10100 for those who have taken only one covid dose,01010 for those who have taken both doses.

doses     Bitmap indices
0       00001
1       10100
2       01010

 

If the covid_test column is indexed, there are two such bitmaps, one for covid_test positive and one for covid_test negative. The bitmap value for positive will be 00110 because students having student_id 3 and 4 are tested positive. Each bit in bitmap indices tells us about a particular row whether a student was tested positive for the covid test or not. Similarly, the value for the negative bitmap is 11001.

covide_test Bitmap Indices
positive  00110
negative 11001.

 

SELECT *  FROM STUDENT 

WHERE covid_test= ‘positive" and doses=2;

 

For the above query, DBMS will search the bitmap index of both the columns and perform logical AND operation and find out the final result:

Bitmap index for positive is  00110 

Bitmap index for 2 doses is     01010

—------------------------------------------------

The final result for the query    00010

So, the student having student_id 4 will satisfy the above query.

CREATE BITMAP INDEX

Syntax

CREATE BITMAP INDEX Index_Name

 ON Table_Name (Column_Name);

Example

For the above example of the Student table, the bitmap index on column index_doses will be created as follows:  

CREATE BITMAP INDEX index _doses

 ON Student (doses);

The bitmap is already shown in the article.

Recommended Topic - Specialization and Generalization in DBMS and Recursive Relationship in DBMS.

Features of Bitmap Indexing in DBMS

The features of Bitmap Indexing in DBMS are:

  • Space Efficiency: Bitmap indexes are highly space-efficient, particularly for low-cardinality columns with a limited number of distinct values.
  • Fast Query Processing: Bitmap indexing enables fast query processing, especially for boolean or categorical attributes, by utilizing efficient bitwise operations like AND, OR, and NOT.
  • Support for Multi-attribute Queries: Bitmap indexes support multi-attribute queries by allowing bitwise operations across multiple bitmap indexes, facilitating complex query processing.
  • Low Overhead for Updates: Bitmap indexes have low overhead for updates, making them suitable for applications where the dataset is updated infrequently compared to the frequency of queries.
  • Compression Techniques: Bitmap indexes can be further optimized using compression techniques to reduce storage requirements and improve query performance.

Applications of Bitmap Indexing in DBMS

The applications of Bitmap Indexing in DBMS are:

  • Data Warehousing: Bitmap indexing is commonly used in data warehousing environments to accelerate query performance on large multidimensional datasets, particularly in OLAP (Online Analytical Processing) systems.
  • Business Intelligence (BI): Bitmap indexes find applications in BI tools and analytics platforms for fast querying and analysis of large datasets, allowing users to explore data and generate insights efficiently.
  • Decision Support Systems (DSS): Bitmap indexing supports decision support systems by enabling fast retrieval of data subsets based on various criteria, facilitating decision-making processes.
  • Scientific Computing: Bitmap indexing is used in scientific computing applications to index and query large datasets generated by experiments, simulations, and research studies, enabling researchers to analyze and interpret data effectively.
  • Ad-hoc Reporting: Bitmap indexing facilitates ad-hoc reporting in DBMS environments, allowing users to quickly generate reports and analyze data based on different dimensions and attributes.

Advantages of Bitmap Indexing in DBMS

  • It helps in fast retrieving data when low cardinality columns are used for frequent queries.
  • It is efficient when the table has a large number of data.
  • It is more efficient if insertion/ update/ deletion operations are involved in the table.
  • A combination of multiple indexes is possible for the execution of a query.

Disadvantages of Bitmap Indexing in DBMS

  • Bitmap indexing is inappropriate for tables with fewer records, as DBMS forces a full scan over the table for results instead of bitmap indexing.
  • Deadlock can occur when different users perform multiple insertions/ updating/ deletion operations on the database.
  •  If the user enters a new record, we have to modify it all over, which is time-consuming and difficult.
  • We can update only one table by different transactions using the bitmap join index.
  • Bitmap indexing cannot be created using the UNIQUE attribute in the table.

    You can also read about the Multiple Granularity Locking and  Checkpoint in DBMS.

Frequently Asked Questions

What is an index?

The index is a type of data structure. It is used to quickly locate and access the data in a database table. Indexing is used to improve a database's performance by minimizing the number of disk accesses required when a query is processed.

What is bitmap indexing of OLAP data?

Bitmap indexing of OLAP data involves using bitmap indexes to efficiently index and query multidimensional data in Online Analytical Processing (OLAP) systems.

What is the difference between the bitmap index and b-tree?

The fundamental differences between b-tree and bitmap indexes include cardinality differences. The bitmap index is generally for columns to improve a database’s performance having duplicate values (low cardinality). In contrast, b-tree indexes are best for high cardinality columns.

What is the use of an index?

Indexes quickly locate data without searching every row in a database table whenever a database table is accessed. Indexes can be created using one or more columns of a database table. It provides the basis for both rapid random lookups and efficient access to ordered records.

Conclusion

We learned about bitmap indexing and how it is used in large databases to save a lot of time. We learn about the syntax for creating a bitmap index for a specific column in our database. We also learned about the disadvantages and advantages of using bitmaps.

Also Read - Cardinality In DBMS.Data Structures

Visit here to learn more about different topics related to database and management systems. Ninjas don't stop here. Check out the Top 100 SQL Problems to master frequently asked questions in big companies and land your dream job. Also, try  Coding Ninjas Studio to practice a wide range of DSA questions asked in many interviews.

Live masterclass