<s>
A	O
bitmap	B-Data_Structure
index	I-Data_Structure
is	O
a	O
special	O
kind	O
of	O
database	B-Data_Structure
index	I-Data_Structure
that	O
uses	O
bitmaps	O
.	O
</s>
<s>
Bitmap	B-Data_Structure
indexes	I-Data_Structure
have	O
traditionally	O
been	O
considered	O
to	O
work	O
well	O
for	O
low-cardinality	O
columns	B-Application
,	O
which	O
have	O
a	O
modest	O
number	O
of	O
distinct	O
values	O
,	O
either	O
absolutely	O
,	O
or	O
relative	O
to	O
the	O
number	O
of	O
records	O
that	O
contain	O
the	O
data	O
.	O
</s>
<s>
The	O
extreme	O
case	O
of	O
low	O
cardinality	B-Application
is	O
Boolean	O
data	O
(	O
e.g.	O
,	O
does	O
a	O
resident	O
in	O
a	O
city	O
have	O
internet	O
access	O
?	O
</s>
<s>
Bitmap	B-Data_Structure
indexes	I-Data_Structure
use	O
bit	B-Data_Structure
arrays	I-Data_Structure
(	O
commonly	O
called	O
bitmaps	O
)	O
and	O
answer	O
queries	O
by	O
performing	O
bitwise	O
logical	O
operations	O
on	O
these	O
bitmaps	O
.	O
</s>
<s>
Bitmap	B-Data_Structure
indexes	I-Data_Structure
have	O
a	O
significant	O
space	O
and	O
performance	O
advantage	O
over	O
other	O
structures	O
for	O
query	B-Application
of	O
such	O
data	O
.	O
</s>
<s>
Their	O
drawback	O
is	O
they	O
are	O
less	O
efficient	O
than	O
the	O
traditional	O
B-tree	B-Architecture
indexes	O
for	O
columns	B-Application
whose	O
data	O
is	O
frequently	O
updated	O
:	O
consequently	O
,	O
they	O
are	O
more	O
often	O
employed	O
in	O
read-only	O
systems	O
that	O
are	O
specialized	O
for	O
fast	O
query	B-Application
-	O
e.g.	O
,	O
data	O
warehouses	O
,	O
and	O
generally	O
unsuitable	O
for	O
online	B-General_Concept
transaction	I-General_Concept
processing	I-General_Concept
applications	O
.	O
</s>
<s>
Some	O
researchers	O
argue	O
that	O
bitmap	B-Data_Structure
indexes	I-Data_Structure
are	O
also	O
useful	O
for	O
moderate	O
or	O
even	O
high-cardinality	O
data	O
(	O
e.g.	O
,	O
unique-valued	O
data	O
)	O
which	O
is	O
accessed	O
in	O
a	O
read-only	O
manner	O
,	O
and	O
queries	O
access	O
multiple	O
bitmap-indexed	O
columns	B-Application
using	O
the	O
AND	O
,	O
OR	O
or	O
XOR	B-Application
operators	O
extensively	O
.	O
</s>
<s>
Bitmap	B-Data_Structure
indexes	I-Data_Structure
are	O
also	O
useful	O
in	O
data	O
warehousing	O
applications	O
for	O
joining	O
a	O
large	O
fact	O
table	O
to	O
smaller	O
dimension	O
tables	O
such	O
as	O
those	O
arranged	O
in	O
a	O
star	B-Application
schema	I-Application
.	O
</s>
<s>
Continuing	O
the	O
internet	O
access	O
example	O
,	O
a	O
bitmap	B-Data_Structure
index	I-Data_Structure
may	O
be	O
logically	O
viewed	O
as	O
follows	O
:	O
</s>
<s>
On	O
the	O
left	O
,	O
Identifier	O
refers	O
to	O
the	O
unique	O
number	O
assigned	O
to	O
each	O
resident	O
,	O
HasInternet	O
is	O
the	O
data	O
to	O
be	O
indexed	O
,	O
the	O
content	O
of	O
the	O
bitmap	B-Data_Structure
index	I-Data_Structure
is	O
shown	O
as	O
two	O
columns	B-Application
under	O
the	O
heading	O
bitmaps	O
.	O
</s>
<s>
Each	O
column	O
in	O
the	O
left	O
illustration	O
under	O
the	O
Bitmaps	O
header	O
is	O
a	O
bitmap	B-Data_Structure
in	O
the	O
bitmap	B-Data_Structure
index	I-Data_Structure
.	O
</s>
<s>
It	O
is	O
easy	O
to	O
see	O
that	O
each	O
bit	O
in	O
bitmap	B-Data_Structure
Y	O
shows	O
whether	O
a	O
particular	O
row	O
refers	O
to	O
a	O
person	O
who	O
has	O
internet	O
access	O
.	O
</s>
<s>
This	O
is	O
the	O
simplest	O
form	O
of	O
bitmap	B-Data_Structure
index	I-Data_Structure
.	O
</s>
<s>
Most	O
columns	B-Application
will	O
have	O
more	O
distinct	O
values	O
.	O
</s>
<s>
Variations	O
on	O
the	O
bitmap	B-Data_Structure
index	I-Data_Structure
can	O
effectively	O
index	O
this	O
data	O
as	O
well	O
.	O
</s>
<s>
For	O
those	O
who	O
might	O
be	O
interested	O
in	O
experimenting	O
with	O
some	O
of	O
the	O
ideas	O
mentioned	O
here	O
,	O
many	O
of	O
them	O
are	O
implemented	O
in	O
open	O
source	O
software	O
such	O
as	O
FastBit	O
,	O
the	O
Lemur	O
Bitmap	B-Data_Structure
Index	I-Data_Structure
C++	O
Library	O
,	O
the	O
Roaring	O
Bitmap	B-Data_Structure
Java	O
library	O
and	O
the	O
Apache	B-General_Concept
Hive	I-General_Concept
Data	O
Warehouse	O
system	O
.	O
</s>
<s>
For	O
historical	O
reasons	O
,	O
bitmap	B-Data_Structure
compression	O
and	O
inverted	O
list	O
compression	O
were	O
developed	O
as	O
separate	O
lines	O
of	O
research	O
,	O
and	O
only	O
later	O
were	O
recognized	O
as	O
solving	O
essentially	O
the	O
same	O
problem	O
.	O
</s>
<s>
Software	O
can	O
compress	B-General_Concept
each	O
bitmap	B-Data_Structure
in	O
a	O
bitmap	B-Data_Structure
index	I-Data_Structure
to	O
save	O
space	O
.	O
</s>
<s>
Though	O
there	O
are	O
exceptions	O
such	O
as	O
Roaring	O
bitmaps	O
,	O
Bitmap	B-Data_Structure
compression	B-General_Concept
algorithms	I-General_Concept
typically	O
employ	O
run-length	B-Algorithm
encoding	I-Algorithm
,	O
such	O
as	O
the	O
Byte-aligned	O
Bitmap	B-Data_Structure
Code	O
,	O
the	O
Word-Aligned	O
Hybrid	O
code	O
,	O
the	O
Partitioned	O
Word-Aligned	O
Hybrid	O
(	O
PWAH	O
)	O
compression	O
,	O
the	O
Position	O
List	O
Word	O
Aligned	O
Hybrid	O
,	O
the	O
Compressed	O
Adaptive	O
Index	O
(	O
COMPAX	O
)	O
,	O
Enhanced	O
Word-Aligned	O
Hybrid	O
(	O
EWAH	O
)	O
and	O
the	O
COmpressed	O
'	O
N	O
 '	O
Composable	O
Integer	O
SEt	O
(	O
CONCISE	O
)	O
.	O
</s>
<s>
These	O
compression	O
methods	O
require	O
very	O
little	O
effort	O
to	O
compress	B-General_Concept
and	O
decompress	O
.	O
</s>
<s>
This	O
gives	O
them	O
considerable	O
advantages	O
over	O
generic	O
compression	B-General_Concept
techniques	I-General_Concept
such	O
as	O
LZ77	O
.	O
</s>
<s>
BBC	O
compression	O
and	O
its	O
derivatives	O
are	O
used	O
in	O
a	O
commercial	O
database	B-Application
management	I-Application
system	I-Application
.	O
</s>
<s>
BBC	O
is	O
effective	O
in	O
both	O
reducing	O
index	O
sizes	O
and	O
maintaining	O
query	B-Application
performance	O
.	O
</s>
<s>
BBC	O
encodes	O
the	O
bitmaps	O
in	O
bytes	B-Application
,	O
while	O
WAH	O
encodes	O
in	O
words	O
,	O
better	O
matching	O
current	O
CPUs	B-Device
.	O
</s>
<s>
"	O
On	O
both	O
synthetic	O
data	O
and	O
real	O
application	O
data	O
,	O
the	O
new	O
word	O
aligned	O
schemes	O
use	O
only	O
50%	O
more	O
space	O
,	O
but	O
perform	O
logical	O
operations	O
on	O
compressed	B-General_Concept
data	I-General_Concept
12	O
times	O
faster	O
than	O
BBC.	O
"	O
</s>
<s>
Basic	O
bitmap	B-Data_Structure
indexes	I-Data_Structure
use	O
one	O
bitmap	B-Data_Structure
for	O
each	O
distinct	O
value	O
.	O
</s>
<s>
This	O
reduces	O
the	O
number	O
of	O
bitmaps	O
,	O
further	O
saving	O
space	O
,	O
but	O
to	O
answer	O
any	O
query	B-Application
,	O
most	O
of	O
the	O
bitmaps	O
have	O
to	O
be	O
accessed	O
.	O
</s>
<s>
This	O
makes	O
it	O
potentially	O
not	O
as	O
effective	O
as	O
scanning	O
a	O
vertical	O
projection	O
of	O
the	O
base	O
data	O
,	O
also	O
known	O
as	O
a	O
materialized	B-Application
view	I-Application
or	O
projection	O
index	O
.	O
</s>
<s>
Finding	O
the	O
optimal	O
encoding	O
method	O
that	O
balances	O
(	O
arbitrary	O
)	O
query	B-Application
performance	O
,	O
index	O
size	O
and	O
index	O
maintenance	O
remains	O
a	O
challenge	O
.	O
</s>
<s>
Without	O
considering	O
compression	O
,	O
Chan	O
and	O
Ioannidis	O
analyzed	O
a	O
class	O
of	O
multi-component	O
encoding	O
methods	O
and	O
came	O
to	O
the	O
conclusion	O
that	O
two-component	O
encoding	O
sits	O
at	O
the	O
kink	O
of	O
the	O
performance	O
vs.	O
index	O
size	O
curve	O
and	O
therefore	O
represents	O
the	O
best	O
trade-off	O
between	O
index	O
size	O
and	O
query	B-Application
performance	O
.	O
</s>
<s>
For	O
high-cardinality	O
columns	B-Application
,	O
it	O
is	O
useful	O
to	O
bin	O
the	O
values	O
,	O
where	O
each	O
bin	O
covers	O
multiple	O
values	O
and	O
build	O
the	O
bitmaps	O
to	O
represent	O
the	O
values	O
in	O
each	O
bin	O
.	O
</s>
<s>
In	O
most	O
cases	O
,	O
the	O
time	O
used	O
by	O
the	O
candidate	O
check	O
is	O
significantly	O
longer	O
than	O
the	O
time	O
needed	O
to	O
work	O
with	O
the	O
bitmap	B-Data_Structure
index	I-Data_Structure
.	O
</s>
<s>
They	O
can	O
be	O
very	O
fast	O
for	O
some	O
queries	O
,	O
but	O
much	O
slower	O
if	O
the	O
query	B-Application
does	O
not	O
exactly	O
match	O
a	O
bin	O
.	O
</s>
<s>
The	O
concept	O
of	O
bitmap	B-Data_Structure
index	I-Data_Structure
was	O
first	O
introduced	O
by	O
Professor	O
Israel	O
Spiegler	O
and	O
Rafi	O
Maayan	O
in	O
their	O
research	O
"	O
Storage	O
and	O
Retrieval	O
Considerations	O
of	O
Binary	O
Data	B-Application
Bases	I-Application
"	O
,	O
published	O
in	O
1985	O
.	O
</s>
<s>
The	O
first	O
commercial	O
database	O
product	O
to	O
implement	O
a	O
bitmap	B-Data_Structure
index	I-Data_Structure
was	O
Computer	O
Corporation	O
of	O
America	O
's	O
Model	B-Application
204	I-Application
.	O
</s>
<s>
This	O
implementation	O
is	O
a	O
hybrid	O
between	O
the	O
basic	O
bitmap	B-Data_Structure
index	I-Data_Structure
(	O
without	O
compression	O
)	O
and	O
the	O
list	O
of	O
Row	O
Identifiers	O
(	O
RID-list	O
)	O
.	O
</s>
<s>
When	O
the	O
column	O
cardinality	B-Application
is	O
low	O
,	O
each	O
leaf	O
node	O
of	O
the	O
B-tree	B-Architecture
would	O
contain	O
long	O
list	O
of	O
RIDs	O
.	O
</s>
<s>
Since	O
each	O
bitmap	B-Data_Structure
represents	O
one	O
distinct	O
value	O
,	O
this	O
is	O
the	O
basic	O
bitmap	B-Data_Structure
index	I-Data_Structure
.	O
</s>
<s>
As	O
the	O
column	O
cardinality	B-Application
increases	O
,	O
each	O
bitmap	B-Data_Structure
becomes	O
sparse	O
and	O
it	O
may	O
take	O
more	O
disk	O
space	O
to	O
store	O
the	O
bitmaps	O
than	O
to	O
store	O
the	O
same	O
content	O
as	O
RID-lists	O
.	O
</s>
<s>
One	O
of	O
the	O
strongest	O
reasons	O
for	O
using	O
bitmap	B-Data_Structure
indexes	I-Data_Structure
is	O
that	O
the	O
intermediate	O
results	O
produced	O
from	O
them	O
are	O
also	O
bitmaps	O
and	O
can	O
be	O
efficiently	O
reused	O
in	O
further	O
operations	O
to	O
answer	O
more	O
complex	O
queries	O
.	O
</s>
<s>
Many	O
programming	O
languages	O
support	O
this	O
as	O
a	O
bit	B-Data_Structure
array	I-Data_Structure
data	O
structure	O
.	O
</s>
<s>
For	O
example	O
,	O
Java	O
has	O
the	O
BitSet	B-Data_Structure
class	O
.	O
</s>
<s>
Some	O
database	B-Application
systems	I-Application
that	O
do	O
not	O
offer	O
persistent	O
bitmap	B-Data_Structure
indexes	I-Data_Structure
use	O
bitmaps	O
internally	O
to	O
speed	O
up	O
query	B-Application
processing	I-Application
.	O
</s>
<s>
For	O
example	O
,	O
PostgreSQL	B-Application
versions	O
8.1	O
and	O
later	O
implement	O
a	O
"	O
bitmap	B-Data_Structure
index	I-Data_Structure
scan	O
"	O
optimization	O
to	O
speed	O
up	O
arbitrarily	O
complex	O
logical	O
operations	O
between	O
available	O
indexes	O
on	O
a	O
single	O
table	O
.	O
</s>
<s>
For	O
tables	O
with	O
many	O
columns	B-Application
,	O
the	O
total	O
number	O
of	O
distinct	O
indexes	O
to	O
satisfy	O
all	O
possible	O
queries	O
(	O
with	O
equality	O
filtering	O
conditions	O
on	O
either	O
of	O
the	O
fields	O
)	O
grows	O
very	O
fast	O
,	O
being	O
defined	O
by	O
this	O
formula	O
:	O
</s>
<s>
A	O
bitmap	B-Data_Structure
index	I-Data_Structure
scan	O
combines	O
expressions	O
on	O
different	O
indexes	O
,	O
thus	O
requiring	O
only	O
one	O
index	O
per	O
column	O
to	O
support	O
all	O
possible	O
queries	O
on	O
a	O
table	O
.	O
</s>
<s>
Applying	O
this	O
access	O
strategy	O
to	O
B-tree	B-Architecture
indexes	O
can	O
also	O
combine	O
range	O
queries	O
on	O
multiple	O
columns	B-Application
.	O
</s>
<s>
In	O
this	O
approach	O
,	O
a	O
temporary	O
in-memory	O
bitmap	B-Data_Structure
is	O
created	O
with	O
one	O
bit	O
for	O
each	O
row	O
in	O
the	O
table	O
(	O
1MB	O
can	O
thus	O
store	O
over	O
8	O
million	O
entries	O
)	O
.	O
</s>
<s>
Next	O
,	O
the	O
results	O
from	O
each	O
index	O
are	O
combined	O
into	O
the	O
bitmap	B-Data_Structure
using	O
bitwise	O
operations	O
.	O
</s>
<s>
After	O
all	O
conditions	O
are	O
evaluated	O
,	O
the	O
bitmap	B-Data_Structure
contains	O
a	O
"	O
1	O
"	O
for	O
rows	O
that	O
matched	O
the	O
expression	O
.	O
</s>
<s>
Finally	O
,	O
the	O
bitmap	B-Data_Structure
is	O
traversed	O
and	O
matching	O
rows	O
are	O
retrieved	O
.	O
</s>
<s>
In	O
addition	O
to	O
efficiently	O
combining	O
indexes	O
,	O
this	O
also	O
improves	O
locality	B-General_Concept
of	I-General_Concept
reference	I-General_Concept
of	O
table	O
accesses	O
,	O
because	O
all	O
rows	O
are	O
fetched	O
sequentially	O
from	O
the	O
main	O
table	O
.	O
</s>
<s>
The	O
internal	O
bitmap	B-Data_Structure
is	O
discarded	O
after	O
the	O
query	B-Application
.	O
</s>
<s>
If	O
there	O
are	O
too	O
many	O
rows	O
in	O
the	O
table	O
to	O
use	O
1	O
bit	O
per	O
row	O
,	O
a	O
"	O
lossy	O
"	O
bitmap	B-Data_Structure
is	O
created	O
instead	O
,	O
with	O
a	O
single	O
bit	O
per	O
disk	O
page	O
.	O
</s>
<s>
In	O
this	O
case	O
,	O
the	O
bitmap	B-Data_Structure
is	O
just	O
used	O
to	O
determine	O
which	O
pages	O
to	O
fetch	O
;	O
the	O
filter	O
criteria	O
are	O
then	O
applied	O
to	O
all	O
rows	O
in	O
matching	O
pages	O
.	O
</s>
