<s>
A	O
database	B-Data_Structure
index	I-Data_Structure
is	O
a	O
data	B-General_Concept
structure	I-General_Concept
that	O
improves	O
the	O
speed	O
of	O
data	O
retrieval	O
operations	O
on	O
a	O
database	B-Application
table	I-Application
at	O
the	O
cost	O
of	O
additional	O
writes	O
and	O
storage	O
space	O
to	O
maintain	O
the	O
index	O
data	B-General_Concept
structure	I-General_Concept
.	O
</s>
<s>
Indexes	O
are	O
used	O
to	O
quickly	O
locate	O
data	O
without	O
having	O
to	O
search	O
every	O
row	O
in	O
a	O
database	B-Application
table	I-Application
every	O
time	O
a	O
database	B-Application
table	I-Application
is	O
accessed	O
.	O
</s>
<s>
Indexes	O
can	O
be	O
created	O
using	O
one	O
or	O
more	O
columns	B-Application
of	I-Application
a	I-Application
database	I-Application
table	I-Application
,	O
providing	O
the	O
basis	O
for	O
both	O
rapid	O
random	O
lookups	B-Data_Structure
and	O
efficient	O
access	O
of	O
ordered	O
records	O
.	O
</s>
<s>
Another	O
option	O
sometimes	O
supported	O
is	O
the	O
use	O
of	O
partial	B-Language
indices	I-Language
,	O
where	O
index	O
entries	O
are	O
created	O
only	O
for	O
those	O
records	O
that	O
satisfy	O
some	O
conditional	O
expression	O
.	O
</s>
<s>
A	O
further	O
aspect	O
of	O
flexibility	O
is	O
to	O
permit	O
indexing	O
on	O
user-defined	B-Language
functions	I-Language
,	O
as	O
well	O
as	O
expressions	O
formed	O
from	O
an	O
assortment	O
of	O
built-in	O
functions	O
.	O
</s>
<s>
Most	O
database	O
software	O
includes	O
indexing	O
technology	O
that	O
enables	O
sub-linear	O
time	O
lookup	B-Data_Structure
to	O
improve	O
performance	O
,	O
as	O
linear	B-Algorithm
search	I-Algorithm
is	O
inefficient	O
for	O
large	O
databases	O
.	O
</s>
<s>
Since	O
databases	O
may	O
contain	O
many	O
objects	O
,	O
and	O
since	O
lookup	B-Data_Structure
is	O
a	O
common	O
operation	O
,	O
it	O
is	O
often	O
desirable	O
to	O
improve	O
performance	O
.	O
</s>
<s>
An	O
index	O
is	O
any	O
data	B-General_Concept
structure	I-General_Concept
that	O
improves	O
the	O
performance	O
of	O
lookup	B-Data_Structure
.	O
</s>
<s>
There	O
are	O
many	O
different	O
data	B-General_Concept
structures	I-General_Concept
used	O
for	O
this	O
purpose	O
.	O
</s>
<s>
There	O
are	O
complex	O
design	O
trade-offs	O
involving	O
lookup	B-Data_Structure
performance	O
,	O
index	O
size	O
,	O
and	O
index-update	O
performance	O
.	O
</s>
<s>
Many	O
index	O
designs	O
exhibit	O
logarithmic	O
(O(log(N )	O
)	O
)	O
lookup	B-Data_Structure
performance	O
and	O
in	O
some	O
applications	O
it	O
is	O
possible	O
to	O
achieve	O
flat	O
(O(1 )	O
)	O
performance	O
.	O
</s>
<s>
Indexes	O
are	O
used	O
to	O
police	O
database	O
constraints	O
,	O
such	O
as	O
UNIQUE	O
,	O
EXCLUSION	O
,	O
PRIMARY	B-Application
KEY	I-Application
and	O
FOREIGN	B-Application
KEY	I-Application
.	O
</s>
<s>
Database	O
systems	O
usually	O
implicitly	O
create	O
an	O
index	O
on	O
a	O
set	O
of	O
columns	O
declared	O
PRIMARY	B-Application
KEY	I-Application
,	O
and	O
some	O
are	O
capable	O
of	O
using	O
an	O
already-existing	O
index	O
to	O
police	O
this	O
constraint	O
.	O
</s>
<s>
Many	O
database	O
systems	O
require	O
that	O
both	O
referencing	O
and	O
referenced	O
sets	O
of	O
columns	O
in	O
a	O
FOREIGN	B-Application
KEY	I-Application
constraint	I-Application
are	O
indexed	O
,	O
thus	O
improving	O
performance	O
of	O
inserts	O
,	O
updates	O
and	O
deletes	O
to	O
the	O
tables	O
participating	O
in	O
the	O
constraint	O
.	O
</s>
<s>
The	O
non-clustered	B-Data_Structure
index	I-Data_Structure
tree	O
contains	O
the	O
index	O
keys	O
in	O
sorted	O
order	O
,	O
with	O
the	O
leaf	O
level	O
of	O
the	O
index	O
containing	O
the	O
pointer	O
to	O
the	O
record	O
(	O
page	O
and	O
the	O
row	O
number	O
in	O
the	O
data	O
page	O
in	O
page-organized	O
engines	O
;	O
row	O
offset	O
in	O
file-organized	O
engines	O
)	O
.	O
</s>
<s>
In	O
a	O
non-clustered	B-Data_Structure
index	I-Data_Structure
,	O
</s>
<s>
There	O
can	O
be	O
more	O
than	O
one	O
non-clustered	B-Data_Structure
index	I-Data_Structure
on	O
a	O
database	B-Application
table	I-Application
.	O
</s>
<s>
Clustering	O
alters	O
the	O
data	O
block	B-General_Concept
into	O
a	O
certain	O
distinct	O
order	O
to	O
match	O
the	O
index	O
,	O
resulting	O
in	O
the	O
row	O
data	O
being	O
stored	O
in	O
order	O
.	O
</s>
<s>
Therefore	O
,	O
only	O
one	O
clustered	O
index	O
can	O
be	O
created	O
on	O
a	O
given	O
database	B-Application
table	I-Application
.	O
</s>
<s>
Since	O
the	O
physical	O
records	O
are	O
in	O
this	O
sort	O
order	O
on	O
disk	O
,	O
the	O
next	O
row	O
item	O
in	O
the	O
sequence	O
is	O
immediately	O
before	O
or	O
after	O
the	O
last	O
one	O
,	O
and	O
so	O
fewer	O
data	O
block	B-General_Concept
reads	O
are	O
required	O
.	O
</s>
<s>
Some	O
databases	O
separate	O
the	O
data	O
and	O
index	O
blocks	O
into	O
separate	O
files	O
,	O
others	O
put	O
two	O
completely	O
different	O
data	O
blocks	O
within	O
the	O
same	O
physical	O
file(s )	O
.	O
</s>
<s>
A	O
cluster	O
can	O
be	O
keyed	O
with	O
a	O
B-Tree	B-Architecture
index	O
or	O
a	O
hash	B-Algorithm
table	I-Algorithm
.	O
</s>
<s>
The	O
data	O
block	B-General_Concept
where	O
the	O
table	O
record	O
is	O
stored	O
is	O
defined	O
by	O
the	O
value	O
of	O
the	O
cluster	O
key	O
.	O
</s>
<s>
In	O
the	O
phone	O
book	O
example	O
with	O
a	O
composite	B-Data_Structure
index	I-Data_Structure
created	O
on	O
the	O
columns	O
(	O
city	O
,	O
last_name	O
,	O
first_name	O
)	O
,	O
if	O
we	O
search	O
by	O
giving	O
exact	O
values	O
for	O
all	O
the	O
three	O
fields	O
,	O
search	O
time	O
is	O
minimal	O
—	O
but	O
if	O
we	O
provide	O
the	O
values	O
for	O
city	O
and	O
first_name	O
only	O
,	O
the	O
search	O
uses	O
only	O
the	O
city	O
field	O
to	O
retrieve	O
all	O
matched	O
records	O
.	O
</s>
<s>
Then	O
a	O
sequential	O
lookup	B-Data_Structure
checks	O
the	O
matching	O
with	O
first_name	O
.	O
</s>
<s>
Consider	O
the	O
following	O
SQL	B-Language
statement	O
:	O
.	O
</s>
<s>
With	O
an	O
index	O
the	O
database	O
simply	O
follows	O
the	O
index	O
data	B-General_Concept
structure	I-General_Concept
(	O
typically	O
a	O
B-tree	B-Architecture
)	O
until	O
the	O
Smith	O
entry	O
has	O
been	O
found	O
;	O
this	O
is	O
much	O
less	O
computationally	O
expensive	O
than	O
a	O
full	O
table	O
scan	O
.	O
</s>
<s>
Consider	O
this	O
SQL	B-Language
statement	O
:	O
.	O
</s>
<s>
With	O
a	O
wildcard	B-Algorithm
at	O
the	O
beginning	O
of	O
the	O
search-term	O
,	O
the	O
database	O
software	O
is	O
unable	O
to	O
use	O
the	O
underlying	O
index	O
data	B-General_Concept
structure	I-General_Concept
(	O
in	O
other	O
words	O
,	O
the	O
WHERE-clause	O
is	O
not	O
sargable	B-Application
)	O
.	O
</s>
<s>
This	O
problem	O
can	O
be	O
solved	O
through	O
the	O
addition	O
of	O
another	O
index	O
created	O
on	O
and	O
a	O
SQL	B-Language
query	O
like	O
this	O
:	O
.	O
</s>
<s>
When	O
the	O
wildcard	B-Algorithm
characters	I-Algorithm
are	O
used	O
on	O
both	O
sides	O
of	O
the	O
search	O
word	O
as	O
%	O
wikipedia.org%	O
,	O
the	O
index	O
available	O
on	O
this	O
field	O
is	O
not	O
used	O
.	O
</s>
<s>
Rather	O
only	O
a	O
sequential	B-Algorithm
search	I-Algorithm
is	O
performed	O
,	O
which	O
takes	O
time	O
.	O
</s>
<s>
A	O
bitmap	O
index	O
is	O
a	O
special	O
kind	O
of	O
indexing	O
that	O
stores	O
the	O
bulk	O
of	O
its	O
data	O
as	O
bit	B-Data_Structure
arrays	I-Data_Structure
(	O
bitmaps	O
)	O
and	O
answers	O
most	O
queries	O
by	O
performing	O
bitwise	O
logical	O
operations	O
on	O
these	O
bitmaps	O
.	O
</s>
<s>
A	O
dense	B-Data_Structure
index	I-Data_Structure
in	O
databases	O
is	O
a	O
file	B-Operating_System
with	O
pairs	O
of	O
keys	O
and	O
pointers	O
for	O
every	O
record	O
in	O
the	O
data	O
file	B-Operating_System
.	O
</s>
<s>
Every	O
key	O
in	O
this	O
file	B-Operating_System
is	O
associated	O
with	O
a	O
particular	O
pointer	O
to	O
a	O
record	O
in	O
the	O
sorted	O
data	O
file	B-Operating_System
.	O
</s>
<s>
In	O
clustered	O
indices	O
with	O
duplicate	O
keys	O
,	O
the	O
dense	B-Data_Structure
index	I-Data_Structure
points	O
to	O
the	O
first	O
record	O
with	O
that	O
key	O
.	O
</s>
<s>
A	O
sparse	B-Data_Structure
index	I-Data_Structure
in	O
databases	O
is	O
a	O
file	B-Operating_System
with	O
pairs	O
of	O
keys	O
and	O
pointers	O
for	O
every	O
block	B-General_Concept
in	O
the	O
data	O
file	B-Operating_System
.	O
</s>
<s>
Every	O
key	O
in	O
this	O
file	B-Operating_System
is	O
associated	O
with	O
a	O
particular	O
pointer	O
to	O
the	O
block	B-General_Concept
in	O
the	O
sorted	O
data	O
file	B-Operating_System
.	O
</s>
<s>
In	O
clustered	O
indices	O
with	O
duplicate	O
keys	O
,	O
the	O
sparse	B-Data_Structure
index	I-Data_Structure
points	O
to	O
the	O
lowest	O
search	O
key	O
in	O
each	O
block	B-General_Concept
.	O
</s>
<s>
The	O
primary	O
index	O
contains	O
the	O
key	B-Application
fields	I-Application
of	O
the	O
table	O
and	O
a	O
pointer	O
to	O
the	O
non-key	O
fields	O
of	O
the	O
table	O
.	O
</s>
<s>
It	O
is	O
used	O
to	O
index	O
fields	O
that	O
are	O
neither	O
ordering	O
fields	O
nor	O
key	B-Application
fields	I-Application
(	O
there	O
is	O
no	O
assurance	O
that	O
the	O
file	B-Operating_System
is	O
organized	O
on	O
key	B-Application
field	I-Application
or	O
primary	B-Application
key	I-Application
field	I-Application
)	O
.	O
</s>
<s>
One	O
index	O
entry	O
for	O
every	O
tuple	O
in	O
the	O
data	O
file	B-Operating_System
(	O
dense	B-Data_Structure
index	I-Data_Structure
)	O
contains	O
the	O
value	O
of	O
the	O
indexed	O
attribute	O
and	O
pointer	O
to	O
the	O
block	B-General_Concept
or	O
record	O
.	O
</s>
<s>
Another	O
type	O
of	O
index	O
used	O
in	O
database	O
systems	O
is	O
linear	B-Algorithm
hashing	I-Algorithm
.	O
</s>
<s>
Indices	O
can	O
be	O
implemented	O
using	O
a	O
variety	O
of	O
data	B-General_Concept
structures	I-General_Concept
.	O
</s>
<s>
Popular	O
indices	O
include	O
balanced	B-Data_Structure
trees	I-Data_Structure
,	O
B+	O
trees	O
and	O
hashes	B-Algorithm
.	O
</s>
<s>
In	O
Microsoft	B-Application
SQL	I-Application
Server	I-Application
,	O
the	O
leaf	B-Data_Structure
node	I-Data_Structure
of	O
the	O
clustered	O
index	O
corresponds	O
to	O
the	O
actual	O
data	O
,	O
not	O
simply	O
a	O
pointer	O
to	O
data	O
that	O
resides	O
elsewhere	O
,	O
as	O
is	O
the	O
case	O
with	O
a	O
non-clustered	B-Data_Structure
index	I-Data_Structure
.	O
</s>
<s>
An	O
index	O
is	O
typically	O
being	O
accessed	O
concurrently	O
by	O
several	O
transactions	O
and	O
processes	O
,	O
and	O
thus	O
needs	O
concurrency	B-Operating_System
control	I-Operating_System
.	O
</s>
<s>
While	O
in	O
principle	O
indexes	O
can	O
utilize	O
the	O
common	O
database	O
concurrency	B-Operating_System
control	I-Operating_System
methods	O
,	O
specialized	O
concurrency	B-Operating_System
control	I-Operating_System
methods	O
for	O
indexes	O
exist	O
,	O
which	O
are	O
applied	O
in	O
conjunction	O
with	O
the	O
common	O
methods	O
for	O
a	O
substantial	O
performance	O
gain	O
..	O
</s>
<s>
This	O
can	O
be	O
done	O
in	O
SQL	B-Language
with	O
.	O
</s>
<s>
No	O
standard	O
defines	O
how	O
to	O
create	O
indexes	O
,	O
because	O
the	O
ISO	O
SQL	B-Language
Standard	O
does	O
not	O
cover	O
physical	O
aspects	O
.	O
</s>
