Bitmap indexes in DBMS Theory - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
Bitmap indexes help speed up searching in databases by using bits to represent data presence.
We want to understand how the time to search grows as the data size increases.
Analyze the time complexity of using a bitmap index to find rows matching a condition.
-- Assume a bitmap index on a column with distinct values
SELECT ROWID FROM table WHERE bitmap_index & condition_bitmap = condition_bitmap;
This code uses bitwise AND on bitmap indexes to quickly find matching rows.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Bitwise AND on bitmap segments representing rows.
- How many times: Once per bitmap segment, which covers many rows at once.
As the number of rows grows, the bitmap size grows proportionally, so more bits must be processed.
| Input Size (n rows) | Approx. Operations (bitwise checks) |
|---|---|
| 10 | 10 bits processed |
| 100 | 100 bits processed |
| 1000 | 1000 bits processed |
Pattern observation: The work grows linearly with the number of rows because each row corresponds to one bit.
Time Complexity: O(n)
This means the time to search grows directly in proportion to the number of rows in the table.
[X] Wrong: "Bitmap indexes always give constant time search regardless of data size."
[OK] Correct: Even though bit operations are fast, the bitmap size grows with data, so more bits must be checked as data grows.
Understanding how bitmap indexes scale helps you explain database search efficiency clearly and confidently.
What if the bitmap index was compressed? How would that affect the time complexity?
Practice
bitmap indexes in a database?Solution
Step 1: Understand the purpose of bitmap indexes
Bitmap indexes are designed to speed up searches on columns that have a small number of distinct values, like gender or status.Step 2: Compare options with this purpose
Only They speed up queries on columns with few unique values correctly states that bitmap indexes speed up queries on such columns. Other options describe unrelated features.Final Answer:
They speed up queries on columns with few unique values -> Option DQuick Check:
Bitmap indexes = speed up queries on low-cardinality columns [OK]
- Thinking bitmap indexes improve write speed
- Confusing bitmap indexes with data compression
- Assuming bitmap indexes backup data automatically
Solution
Step 1: Recall bitmap index structure
Bitmap indexes use bits (0 or 1) to indicate whether a row contains a specific value in a column.Step 2: Match description to options
An index that uses bits to represent the presence of values correctly describes this bit-based representation. Other options describe different index types.Final Answer:
An index that uses bits to represent the presence of values -> Option CQuick Check:
Bitmap index = bit representation of data presence [OK]
- Confusing bitmap indexes with B-tree indexes
- Thinking bitmap indexes store full data rows
- Assuming bitmap indexes use hashing
Gender with values 'M' or 'F' in a table of 1000 rows. How does a bitmap index represent this data?Solution
Step 1: Understand bitmap index for low-cardinality columns
For each distinct value, a bitmap index creates a bitmap with one bit per row indicating presence (1) or absence (0).Step 2: Apply to 'Gender' column
Since 'Gender' has two values ('M' and 'F'), there will be two bitmaps, each 1000 bits long, one for 'M' and one for 'F'.Final Answer:
Two bitmaps, one for 'M' and one for 'F', each with 1000 bits -> Option AQuick Check:
Bitmap per distinct value = two bitmaps of 1000 bits [OK]
- Thinking bitmap stores actual characters
- Assuming one combined bitmap for all values
- Confusing bitmap with row number storage
Solution
Step 1: Recall bitmap index behavior on updates
Bitmap indexes are not ideal for columns with frequent updates because changing bits can cause locking and slow performance.Step 2: Evaluate options
Bitmap indexes slow down updates and cause locking issues correctly states that bitmap indexes slow down updates and cause locking. Other options are incorrect or misleading.Final Answer:
Bitmap indexes slow down updates and cause locking issues -> Option BQuick Check:
Frequent updates + bitmap index = slow and locking [OK]
- Assuming bitmap indexes speed up updates
- Thinking bitmap indexes handle updates automatically
- Believing bitmap indexes convert updates to inserts
bitmap index is created on a Region column with 5 distinct values. Which scenario best explains why bitmap indexes are preferred here?Solution
Step 1: Identify characteristics suitable for bitmap indexes
Bitmap indexes work best on columns with few unique values and mostly read-only data, like in data warehouses.Step 2: Analyze each option
The column has few unique values and queries often filter by region fits perfectly: few unique values and frequent filtering. Options B, C, and D describe unsuitable scenarios.Final Answer:
The column has few unique values and queries often filter by region -> Option AQuick Check:
Few unique values + read-heavy queries = bitmap index ideal [OK]
- Using bitmap indexes on frequently updated columns
- Applying bitmap indexes to high-cardinality columns
- Confusing bitmap indexes with full-text indexes
