<s>
A	O
query	B-Language
plan	I-Language
(	O
or	O
query	B-Language
execution	I-Language
plan	I-Language
)	O
is	O
a	O
sequence	O
of	O
steps	O
used	O
to	O
access	O
data	O
in	O
a	O
SQL	B-Language
relational	B-Application
database	I-Application
management	I-Application
system	I-Application
.	O
</s>
<s>
This	O
is	O
a	O
specific	O
case	O
of	O
the	O
relational	B-Architecture
model	I-Architecture
concept	O
of	O
access	B-Language
plans	I-Language
.	O
</s>
<s>
Since	O
SQL	B-Language
is	O
declarative	B-Language
,	O
there	O
are	O
typically	O
many	O
alternative	O
ways	O
to	O
execute	O
a	O
given	O
query	B-Library
,	O
with	O
widely	O
varying	O
performance	O
.	O
</s>
<s>
When	O
a	O
query	B-Library
is	O
submitted	O
to	O
the	O
database	O
,	O
the	O
query	B-Language
optimizer	I-Language
evaluates	O
some	O
of	O
the	O
different	O
,	O
correct	O
possible	O
plans	O
for	O
executing	O
the	O
query	B-Library
and	O
returns	O
what	O
it	O
considers	O
the	O
best	O
option	O
.	O
</s>
<s>
Because	O
query	B-Language
optimizers	I-Language
are	O
imperfect	O
,	O
database	O
users	O
and	O
administrators	O
sometimes	O
need	O
to	O
manually	O
examine	O
and	O
tune	O
the	O
plans	O
produced	O
by	O
the	O
optimizer	O
to	O
get	O
better	O
performance	O
.	O
</s>
<s>
A	O
given	O
database	O
management	O
system	O
may	O
offer	O
one	O
or	O
more	O
mechanisms	O
for	O
returning	O
the	O
plan	O
for	O
a	O
given	O
query	B-Library
.	O
</s>
<s>
Some	O
packages	O
feature	O
tools	O
which	O
will	O
generate	O
a	O
graphical	O
representation	O
of	O
a	O
query	B-Language
plan	I-Language
.	O
</s>
<s>
Other	O
tools	O
allow	O
a	O
special	O
mode	O
to	O
be	O
set	O
on	O
the	O
connection	O
to	O
cause	O
the	O
DBMS	O
to	O
return	O
a	O
textual	O
description	O
of	O
the	O
query	B-Language
plan	I-Language
.	O
</s>
<s>
Another	O
mechanism	O
for	O
retrieving	O
the	O
query	B-Language
plan	I-Language
involves	O
querying	O
a	O
virtual	O
database	O
table	O
after	O
executing	O
the	O
query	B-Library
to	O
be	O
examined	O
.	O
</s>
<s>
In	O
Oracle	O
,	O
for	O
instance	O
,	O
this	O
can	O
be	O
achieved	O
using	O
the	O
EXPLAIN	B-Language
PLAN	I-Language
statement	O
.	O
</s>
<s>
The	O
Microsoft	B-Application
SQL	I-Application
Server	I-Application
Management	O
Studio	O
tool	O
,	O
which	O
ships	O
with	O
Microsoft	B-Application
SQL	I-Application
Server	I-Application
,	O
for	O
example	O
,	O
shows	O
this	O
graphical	O
plan	O
when	O
executing	O
this	O
two-table	O
join	O
example	O
against	O
an	O
included	O
sample	O
database	O
:	O
</s>
<s>
The	O
UI	O
allows	O
exploration	O
of	O
various	O
attributes	O
of	O
the	O
operators	O
involved	O
in	O
the	O
query	B-Language
plan	I-Language
,	O
including	O
the	O
operator	O
type	O
,	O
the	O
number	O
of	O
rows	O
each	O
operator	O
consumes	O
or	O
produces	O
,	O
and	O
the	O
expected	O
cost	O
of	O
each	O
operator	O
's	O
work	O
.	O
</s>
<s>
thumb|Microsoft	O
SQL	O
Server	O
Management	O
Studio	O
displaying	O
a	O
sample	O
query	B-Language
plan	I-Language
.	O
</s>
<s>
The	O
textual	O
plan	O
given	O
for	O
the	O
same	O
query	B-Library
in	O
the	O
screenshot	O
is	O
shown	O
here	O
:	O
</s>
<s>
It	O
indicates	O
that	O
the	O
query	B-Library
engine	O
will	O
do	O
a	O
scan	O
over	O
the	O
primary	O
key	O
index	O
on	O
the	O
Employee	O
table	O
and	O
a	O
matching	O
seek	O
through	O
the	O
primary	O
key	O
index	O
(	O
the	O
ContactID	O
column	O
)	O
on	O
the	O
Contact	O
table	O
to	O
find	O
matching	O
rows	O
.	O
</s>
<s>
The	O
resulting	O
rows	O
from	O
each	O
side	O
will	O
be	O
shown	O
to	O
a	O
nested	O
loops	O
join	O
operator	O
,	O
sorted	O
,	O
then	O
returned	O
as	O
the	O
result	B-Application
set	I-Application
to	O
the	O
connection	O
.	O
</s>
<s>
In	O
order	O
to	O
tune	O
the	O
query	B-Library
,	O
the	O
user	O
must	O
understand	O
the	O
different	O
operators	O
that	O
the	O
database	O
may	O
use	O
,	O
and	O
which	O
ones	O
might	O
be	O
more	O
efficient	O
than	O
others	O
while	O
still	O
providing	O
semantically	O
correct	O
query	B-Library
results	O
.	O
</s>
<s>
Reviewing	O
the	O
query	B-Language
plan	I-Language
can	O
present	O
opportunities	O
for	O
new	O
indexes	B-Data_Structure
or	O
changes	O
to	O
existing	O
indexes	B-Data_Structure
.	O
</s>
<s>
It	O
can	O
also	O
show	O
that	O
the	O
database	O
is	O
not	O
properly	O
taking	O
advantage	O
of	O
existing	O
indexes	B-Data_Structure
(	O
see	O
query	B-Language
optimizer	I-Language
)	O
.	O
</s>
<s>
A	O
query	B-Language
optimizer	I-Language
will	O
not	O
always	O
choose	O
the	O
most	O
efficient	O
query	B-Language
plan	I-Language
for	O
a	O
given	O
query	B-Library
.	O
</s>
<s>
In	O
some	O
databases	O
the	O
query	B-Language
plan	I-Language
can	O
be	O
reviewed	O
,	O
problems	O
found	O
,	O
and	O
then	O
the	O
query	B-Language
optimizer	I-Language
gives	O
hints	B-Language
on	O
how	O
to	O
improve	O
it	O
.	O
</s>
<s>
In	O
other	O
databases	O
,	O
alternatives	O
to	O
express	O
the	O
same	O
query	B-Library
(	O
other	O
queries	B-Library
that	O
return	O
the	O
same	O
results	O
)	O
can	O
be	O
tried	O
.	O
</s>
<s>
Some	O
query	B-Library
tools	O
can	O
generate	O
embedded	O
hints	B-Language
in	O
the	O
query	B-Library
,	O
for	O
use	O
by	O
the	O
optimizer	O
.	O
</s>
<s>
Some	O
databases	O
-	O
like	O
Oracle	O
-	O
provide	O
a	O
plan	O
table	O
for	O
query	B-Library
tuning	O
.	O
</s>
<s>
and	O
time	O
for	O
executing	O
a	O
query	B-Library
.	O
</s>
<s>
For	O
CBO	O
to	O
be	O
used	O
,	O
all	O
the	O
tables	O
referenced	O
by	O
the	O
query	B-Library
must	O
be	O
analyzed	O
.	O
</s>
<s>
Other	O
tools	O
for	O
query	B-Language
optimization	I-Language
include	O
:	O
</s>
