Bitmap Index
Bitmap Index
Bitmap Indexing
Bitmap Indices
Bitmap indices are a special type of index designed for
efficient querying on multiple keys
Records in a relation are assumed to be numbered
sequentially from, say, 0
Given a number n it must be easy to retrieve record n
• Particularly easy if records are of fixed size
Applicable on attributes that take on a relatively small
number of distinct values
E.g. gender, country, state, …
E.g. income-level (income broken up into a small number
of levels such as 0-9999, 10000-19999, 20000-50000, 50000-
infinity)
A bitmap is simply an array of bits
Bitmap Indices (Cont.)
In its simplest form a bitmap index on an attribute has a bitmap for
each value of the attribute
Bitmap has as many bits as records
In a bitmap for value v, the bit for a record is 1 if the record has
the value v for the attribute, and is 0 otherwise
Bitmap Indices (Cont.)
Bitmap indices are useful for queries on multiple attributes
not particularly useful for single attribute queries
Queries are answered using bitmap operations
Intersection (and)
Union (or)
Complementation (not)
Each operation takes two bitmaps of the same size and applies
the operation on corresponding bits to get the result bitmap
E.g. 100110 AND 110011 = 100010
100110 OR 110011 = 110111
NOT 100110 = 011001
Males with income level L1: 10010 AND 10100 = 10000
• Can then retrieve required tuples.
• Counting number of matching tuples is even faster
Bitmap Index---Definition
value Bit-vector
30 xxxxxx
40 xxxxxx
50 xxxxxx
1
Example 1.
How the bitmap index forms (continue..)
So, the bit-vector of
value 30 is :
Tuple1 Tuple2 Tuple3 Tuple4 Tuple5 Tuple6
1 1 0 0 0 1
1
Example 1.
How the bitmap index forms
Fill the bit-map index of Field “F” as following:
value Bit-vector
30 110001
40 001010
50 000100
1
Do we need Bitmap-Index?
1
Advantage of Bitmap Index
SELECT title
FROM Movie
WHERE studioName = ‘Disney’ AND
year = 1995;
1
Example 2. (contiue…)
100001
AND 100100
100000
• Answer: tuple #1
1
Bitmap Indices (Cont.)
Bitmap indices generally very small compared with relation
size
E.g. if record is 100 bytes, space for a single bitmap is
1/800 of space used by relation.
• If number of distinct attribute values is 8, bitmap is only 1% of
relation size
Deletion needs to be handled properly
Existence bitmap to note if there is a valid record at a
record location
Needed for complementation
• not(A=v): (NOT bitmap-A-v) AND ExistenceBitmap
Should keep bitmaps for all values, even null value
To correctly handle SQL null semantics for NOT(A=v):
• intersect above result with (NOT bitmap-A-Null)
1
Efficient Implementation of Bitmap Operations
Bitmaps are packed into words; a single word and (a basic
CPU instruction) computes and of 32 or 64 bits at once
E.g. 1-million-bit maps can be and-ed with just 31,250
instruction
Counting number of 1s can be done fast by a trick:
Use each byte to index into a precomputed array of 256
elements each storing the count of 1s in the binary
representation
• Can use pairs of bytes to speed up further at a higher memory
cost
Add up the retrieved counts
Bitmaps can be used instead of Tuple-ID lists at leaf levels of B+-trees,
for values that have a large number of matching records
Worthwhile if > 1/64 of the records have that value, assuming a
tuple-id is 64 bits
Above technique merges benefits of bitmap and B+-tree indices
1
Index Definition in SQL
Create an index
create index <index-name> on <relation-name>
(<attribute-list>)
E.g.: create index b-index on branch(branch_name)
Use create unique index to indirectly specify and enforce
the condition that the search key is a candidate key is a
candidate key.
Not really required if SQL unique integrity constraint is
supported
To drop an index
drop index <index-name>
Most database systems allow specification of type of
index, and clustering.
2