0% found this document useful (0 votes)
160 views18 pages

Bitmap and Bitmap Join Index

Here are the steps to create a bitmap join index on this query: 1. Create a bitmap index on the GENDER column of the STUDENT table: CREATE BITMAP INDEX gender_idx ON STUDENT(GENDER); 2. Create a bitmap index on the SEMESTER column of the STUDENT table: CREATE BITMAP INDEX semester_idx ON STUDENT(SEMESTER); 3. Create a bitmap join index on GENDER and SEMESTER: CREATE BITMAP JOIN INDEX gender_semester_idx ON STUDENT(GENDER, SEMESTER); This bitmap join index would allow the query to efficiently lookup rows matching
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
160 views18 pages

Bitmap and Bitmap Join Index

Here are the steps to create a bitmap join index on this query: 1. Create a bitmap index on the GENDER column of the STUDENT table: CREATE BITMAP INDEX gender_idx ON STUDENT(GENDER); 2. Create a bitmap index on the SEMESTER column of the STUDENT table: CREATE BITMAP INDEX semester_idx ON STUDENT(SEMESTER); 3. Create a bitmap join index on GENDER and SEMESTER: CREATE BITMAP JOIN INDEX gender_semester_idx ON STUDENT(GENDER, SEMESTER); This bitmap join index would allow the query to efficiently lookup rows matching
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

BITMAP AND BITMAP JOIN

INDEX
What is Bitmap indexing?
Bitmap Indexing is a special type of database indexing that uses bitmaps.
This technique is used for huge databases, when column is of low cardinality
columns and these columns are most frequently used in the query.
Bitmap vs B-tree
• B-tree and Bitmap indexes are internally different but functionally they are same
in retrieving rows faster than a full-table scan.
• Cardinality differences: Bitmap indexes are used on the columns which has lots of
duplicate values(low cardinality) while B-tree indexes are useful when there is less
or no duplicate values (high cardinality).
• Structural difference: B-tree index uses a tree-like structure with index nodes,
where Bitmap index uses a two dimensional array with zeros and ones (bits)
values.
• B-Tree index impose a small penalty when inserting/updating values on the
indexed table while Bitmap are very inefficient when inserting/updating values.
Need of Bitmap indexing
For example, Let us say that a company holds an employee table with entries like
EmpNo, EmpName, Job, New_Emp and salary. Let us assume that the employees
are hired once in the year, therefore the table will be updated very less and will
remain static most of the time. But the columns will be frequently used in queries
to retrieve data like : No. of female/male employees in the company etc
How Bitmap index Work
tblEmployee Emp_no Emp_name JobTitle New_emp Salary
Emp_no 1 Nikunj Analyst Yes 100000
Emp_name 2 Chintan Sales No 15000
JobTitle Person
New_emp 3 Prakruti Clerk No 20000
Salary 4 Martin Manager Yes 2500000

JobTitle Bitmap indices


New_emp Values Bitmap indices Analyst 1 0 0 0
Yes 1 0 0 1 Sales Person 0 1 0 0
No 0 1 1 0 Clerk 0 0 1 0
1st Row 2nd Row 3rd Row 4th Row Manager 0 0 0 1
SQL Example
If we want to find out the details for the Employee who is not new in the
company and is a sales person
SELECT * FROM Employee WHERE New_Emp = "No" and Job = "Salesperson";

Bitmap Index for 0 1 1 0 CREATE BITMAP INDEX


“NO” index_New_Emp
AND
ON Employee (New_Emp);
Bitmap Index for 0 1 0 0
“Salesperson”
Result 0 1 0 0
SQL Example
SELECT * FROM Employee WHERE status = ‘married’ AND
region =‘central’ OR region=‘west’;
Exercise
ID Name Gender Mobile DOJ Designation Salary Martial HOD_ID DEPT_ID
Status
100 Mrugendra M 235689 10- Asst. Prof 800000 M 101 10
July-
2006
101 Nikunj M 1234546 11- IT_Prog 700000 M 101 10
Jun-
2008
102 Martin M 2356457 12- Asst. Prof 700000 M 103 20
Aug-
2007
103 Chintan M 987654 20- FI_MGR 650000 S 103 20
Sep-
2012
104 Prakruti F 568742 31- FI_Account 86000 S 102 30
Dec-
2017
Example
ID Gender Martial Male Female Sigle Married Divorced
Status
1 0 1 0 0
1 Male Single 0 1 0 0 1
2 Female Divorced 1 0 0 1 0
3 Male Married 0 1 0 0 1
4 Female Divorced
1 0 0 1 0
5 Male Married
0 1 1 0 0
6 Female Single
0 1 1 0 0
7 Female Single
Let’s understand Locking
DEPT_NO LOW_ROW_ID HIGH_ROW_ID BITMAP
10 AAAABoAAAA AAAAEABoAAAA 01100011100
20 AAAAEABoAAAW AAAAAaDaBAAAA 10110101010
30 AAAANAAvEEABa AAAAHaEaBaGaAAA 11000110011
BITMAP Join Index
• Bitmap index is work on a single table
• Bitmap join index, which is a bitmap index for the join of two or more tables.
• Space efficient way of reducing the volume of data that is to be joined.
• In a data warehousing environment, the join condition is an equi-inner join
between the primary key column or columns of the dimension tables and the
foreign key column or columns in the fact table.
Example
Tran_id Cust_ID Prod_ID Amount Profit Cust_ID Name Gender
1 1 1 100 10 101 Nikunj M
2 2 4 900 100 102 Prakruti F
3 2 2 7900 2000 103 Chintan M
4 1 3 8900 2500 104 Rashi F
5 4 5 5600 1500

Select cust_id, sum(amount) from Transaction t, customer c where


c.cust_id=t.cust_id AND c.gender='M'
Example
Tran_id Cust_ID Prod_ID Amount Profit Cust_ID Name Gennder
1 1 1 100 10 101 Nikunj M
2 2 4 900 100 102 Prakruti F
3 2 2 7900 2000 103 Chintan M
4 1 3 8900 2500 104 Rashi F
5 4 5 5600 1500

TRAN_R MALE FEMALE


CREATE BITMAP INDEX TRAN_CUST_GEND_IDX OW_ID
ON TRANSACTION (customer.gender) FROM 1 1 0
transaction t, customer c WHERE 2 0 1
c.cust_id=t.cust_id 3 0 1
4 1 0
5 1 0
Example
Example
Bitmap Join Index Restrictions
• Parallel DML is currently only supported on the fact table. Parallel DML on one of the
participating dimension tables will mark the index as unusable.
• Only one table can be updated concurrently by different transactions when using the
bitmap join index.
• No table can appear twice in the join.
• You cannot create a bitmap join index on an index-organized table or a temporary table.
• The columns in the index must all be columns of the dimension tables.
• The dimension table join columns must be either primary key columns or have unique
constraints.
• The dimension table column(s) participating the join with the fact table must be either the
primary key column(s) or with the unique constraint.
Bitmap Join Index Restrictions
• Parallel DML is currently only supported on the fact table. Parallel DML on one of the
participating dimension tables will mark the index as unusable.
• Only one table can be updated concurrently by different transactions when using the
bitmap join index.
• No table can appear twice in the join.
• You cannot create a bitmap join index on an index-organized table or a temporary table.
• The columns in the index must all be columns of the dimension tables.
• The dimension table join columns must be either primary key columns or have unique
constraints.
• The dimension table column(s) participating the join with the fact table must be either the
primary key column(s) or with the unique constraint.
Exercise
Student table with ID, NAME, ADDRESS, AGE, GENDER and Semester.

SELECT * FROM STUDENT WHERE GENDER = ‘F’ AND SEMESTER =2;

ID NAME ADDRESS AGE GENDER SEMESTER


1 Nikunj Ahmedabad 22 M 1
2 Chintan Baroda 24 M 1
3 Prakruti Anand 23 F 2
4 Rashi Surat 22 F 4

You might also like