1. What is a Bitmap Index in Oracle?
A Bitmap Index uses bitmaps
(0s and 1s) to represent the presence of a column value in rows.
Instead of:
Value → ROWID
It stores:
Value → Bitmap (series of 0s and 1s)
Example:
CREATE BITMAP INDEX emp_gender_bm_idx ON employees(gender);
2. How does it work internally?
Example table:
|
ROWID |
gender |
|
1 |
M |
|
2 |
F |
|
3 |
M |
|
4 |
F |
Bitmap index stores:
M → 1 0 1 0
F → 0 1 0 1
Query:
SELECT * FROM employees WHERE gender = 'M';
Oracle reads bitmap for 'M' and fetches rows where bit = 1.
3. When to use a Bitmap Index?
Best for:
- Low-cardinality columns (few distinct values)
- Data warehouse systems
- Analytical queries
- Read-heavy environments
- Columns used in multiple filtering conditions
Examples: gender, status, region, marital_status
4. When NOT to use Bitmap Index?
Avoid in:
- High-DML OLTP systems
- Tables with frequent INSERT/UPDATE/DELETE
- High-concurrency environments
Reason: Locks large portions of index during updates.
5. Low Cardinality
|
Column |
Distinct Values |
Good for Bitmap? |
|
gender |
2 |
Yes |
|
status |
3 |
Yes |
|
emp_id |
1M |
No |
6. Performance improvement
Powerful for multiple conditions:
SELECT * FROM sales
WHERE region = 'WEST'
AND status = 'ACTIVE'
AND gender = 'F';
Oracle performs bitmap AND/OR/XOR operations on bits → very fast.
7. Bitmap Merge Operations
Combines bitmaps using:
- AND
- OR
- XOR
Example: Region = WEST AND Status =
ACTIVE
Oracle retrieves bitmaps and performs bitwise AND → fetch matching rows efficiently.
8. Bitmap vs B-Tree
|
Feature |
Bitmap Index |
B-Tree Index |
|
Best for |
Low cardinality |
High cardinality |
|
DML performance |
Poor |
Good |
|
Concurrency |
Low |
High |
|
AND/OR queries |
Excellent |
Moderate |
|
OLTP |
Not recommended |
Recommended |
|
Data Warehouse |
Recommended |
Sometimes |
9. Why not for OLTP?
- Updates affect many bits → large index locking
- Reduces concurrency, can block other sessions
10. Locking behavior
Bitmap indexes lock entire key range, not single rows → not suitable for high concurrency.
11. Storage
- Very compact for low-cardinality columns
- Smaller than B-Tree
- Compression improves storage efficiency
12. Composite Bitmap Index
CREATE BITMAP INDEX sales_bm_idx ON sales(region, status);
Useful in star-schema designs.
13. Bitmap Join Index
Special bitmap index for data warehouse joins:
CREATE BITMAP INDEX sales_cust_region_bm_idx
ON sales(customers.region)
FROM sales, customers
WHERE sales.customer_id = customers.customer_id;
Improves join performance.
14. DML impact
- INSERT → updates bitmap entries
- UPDATE → may rewrite large portions
- DELETE → clears bits
Heavy DML → fragmentation, locking, performance drop.
15. Advantages
- Excellent for low-cardinality columns
- Efficient multi-column filtering
- Supports complex analytical queries
- Compact storage
- Ideal for data warehouse
16. Disadvantages
- Poor performance with frequent DML
- Lock contention
- Not for OLTP
- Not for high-cardinality columns
17. Real-world example
Query:
SELECT SUM(amount)
FROM sales
WHERE region = 'WEST'
AND status = 'ACTIVE'
AND gender = 'F';
With bitmap indexes on region, status, gender → Oracle performs bitmap AND operations → extremely fast.
18. Performance tuning tips
- Use only in read-heavy systems
- Star-schema dimensions
- Avoid frequently updated tables
- Combine multiple bitmap indexes for analytics
- Monitor locking behavior
19. Common mistakes
- Using in OLTP
- Indexing high-cardinality columns
- Not understanding locking impact
- Mixing heavy DML with bitmap index
20. Interview Tip
“A Bitmap index stores bitmaps representing row existence for each distinct column value. Efficient for low-cardinality columns and complex analytical queries using multiple conditions. Not suitable for high-DML OLTP due to locking and concurrency. Mainly used in data warehouse environments.”