14
BITMAP INDEXES BITMAP INDEXES Sai Priya Rama Gopal Sai Priya Rama Gopal SJSU ID : 007506408 SJSU ID : 007506408 Class ID: 125 Class ID: 125

BITMAP INDEXES Sai Priya Rama Gopal SJSU ID : 007506408 Class ID: 125

Embed Size (px)

Citation preview

BITMAP INDEXESBITMAP INDEXESSai Priya Rama GopalSai Priya Rama Gopal

SJSU ID : 007506408SJSU ID : 007506408Class ID: 125Class ID: 125

IntroductionIntroduction

• A bitmap index is a special kind of index that A bitmap index is a special kind of index that stores the bulk of its data as bit arrays stores the bulk of its data as bit arrays (commonly called "bitmaps").(commonly called "bitmaps").

• It answers most queries by performing bitwise It answers most queries by performing bitwise logical operations on these bitmaps. logical operations on these bitmaps.

• The bitmap index is designed for cases where The bitmap index is designed for cases where number of distinct values is low, in other number of distinct values is low, in other words, the values repeat very frequently.words, the values repeat very frequently.

ExampleExample

• Suppose a file consists Suppose a file consists of records with two of records with two fields, F and G, of type fields, F and G, of type integer and string, integer and string, respectively. The respectively. The current file has six current file has six records, numbered 1 records, numbered 1 through 6, with the through 6, with the following values in following values in order:order:

No F G

1 30 FOO

2 30 BAR

3 40 BAZ

4 50 FOO

5 40 BAR

6 30 BAZ

Example (contd…)Example (contd…)

• A bitmap index for the A bitmap index for the first field, F, would have first field, F, would have three bit-vectors, each three bit-vectors, each of length 6 as shown in of length 6 as shown in the table.the table.

• In each case, the 1's In each case, the 1's indicate in which indicate in which records the records the corresponding string corresponding string appears.appears.

• Table 2Table 2

Value Vector

30 110001

40 001010

50 000100

Example (contd…)Example (contd…)

• A bitmap index for the A bitmap index for the first field, G, would have first field, G, would have three bit-vectors, each three bit-vectors, each of length 6 as shown in of length 6 as shown in the table.the table.

• In each case, the 1's In each case, the 1's indicate in which indicate in which records the records the corresponding string corresponding string appears.appears.

• Table 3Table 3Value Vector

FOO 100100

BAR 010010

BAZ 001001

Motivation for Bitmap IndexesMotivation for Bitmap Indexes

• Bitmap indexes can help Bitmap indexes can help answer range queries.answer range queries.

• Example:Example:• Given is the data of a Given is the data of a

jewelry stores. The jewelry stores. The attributes considered attributes considered are age and salary.are age and salary.

• Table 4Table 4No Age Salary

1 25 60

2 45 60

3 50 75

4 50 100

5 50 120

6 70 110

7 85 140

8 30 260

9 25 400

10 45 350

11 50 275

12 60 260

Motivation (contd…)Motivation (contd…)

• A bitmap index for the A bitmap index for the first field Age, would first field Age, would have seven bit-vectors, have seven bit-vectors, each of length 12 as each of length 12 as shown in the table.shown in the table.

• In each case, the 1's In each case, the 1's indicate in which indicate in which records the records the corresponding string corresponding string appears.appears.

• Table 5Table 5Value Vector

25 100000001000

30 000000010000

45 010000000100

50 001110000010

60 000000000001

70 000001000000

85 000000100000

Motivation (contd…)Motivation (contd…)

• A bitmap index for the A bitmap index for the second field Salary, second field Salary, would have ten bit-would have ten bit-vectors, each of length vectors, each of length 12 as shown in the table.12 as shown in the table.

• In each case, the 1's In each case, the 1's indicate in which records indicate in which records the corresponding string the corresponding string appears.appears.

• Table 5Value Vector

60 110000000000

75 001000000000

100 000100000000

110 000001000000

120 000010000000

140 000000100000

260 000000010001

275 000000000010

350 000000000100

400 000000001000

Motivation (contd…)Motivation (contd…)• Suppose we want to find the jewelry buyers with Suppose we want to find the jewelry buyers with

an age in the range 45-55 and a salary in the an age in the range 45-55 and a salary in the range 100-200.range 100-200.

• We first find the bit-vectors for the age values in We first find the bit-vectors for the age values in this range; in this example there are only two: this range; in this example there are only two: 010000000100 and 001110000010, for 45 and 010000000100 and 001110000010, for 45 and 50, respectively. If we take their bitwise OR, we 50, respectively. If we take their bitwise OR, we have a new bit-vector with 1 in position i if and have a new bit-vector with 1 in position i if and only if the ionly if the ithth record has an age in the desired record has an age in the desired range. range.

• This bit-vector is 011110000110.This bit-vector is 011110000110.

Motivation (contd…)Motivation (contd…)

• Next, we find the bit-vectors for the salaries Next, we find the bit-vectors for the salaries between 100 and 200 thousand.between 100 and 200 thousand.

• There are four, corresponding to salaries 100, There are four, corresponding to salaries 100, 110, 120, and 140; their bitwise OR is 110, 120, and 140; their bitwise OR is 000111100000000111100000.

Motivation (contd…)Motivation (contd…)

• The last step is to take the bitwise AND of the The last step is to take the bitwise AND of the two bit-vectors we calculated by OR. two bit-vectors we calculated by OR.

• That is:That is:011110000110011110000110

ANDAND 000111100000000111100000----------------------------------------------------------------------

000110000000000110000000

Motivation (contd…)Motivation (contd…)

• We thus find that only the fourth and fifth We thus find that only the fourth and fifth records, which are (50,100) and (50,120), are records, which are (50,100) and (50,120), are in the desired range.in the desired range.

Issues for Bitmap IndexesIssues for Bitmap Indexes

• Managing Bitmap indexesManaging Bitmap indexes• Memory requirement.Memory requirement.

Managing Bitmap indexesManaging Bitmap indexes

• Finding Bit-VectorsFinding Bit-Vectors• Finding RecordsFinding Records• Handling modifications to the data file.Handling modifications to the data file.– Record numbers must remain fixed once assigned.Record numbers must remain fixed once assigned.– Changes to the data file require the bitmap index Changes to the data file require the bitmap index

to change as well.to change as well.