<s>
Query	B-General_Concept
rewriting	I-General_Concept
is	O
a	O
typically	O
automatic	O
transformation	O
that	O
takes	O
a	O
set	O
of	O
database	O
tables	O
,	O
views	B-Language
,	O
and/or	O
queries	B-Language
,	O
usually	O
indices	B-Data_Structure
,	O
often	O
gathered	O
data	O
and	O
query	O
statistics	O
,	O
and	O
other	O
metadata	O
,	O
and	O
yields	O
a	O
set	O
of	O
different	O
queries	B-Language
,	O
which	O
produce	O
the	O
same	O
results	O
but	O
execute	O
with	O
better	O
performance	O
(	O
for	O
example	O
,	O
faster	O
,	O
or	O
with	O
lower	O
memory	O
use	O
)	O
.	O
</s>
<s>
Query	B-General_Concept
rewriting	I-General_Concept
can	O
be	O
based	O
on	O
relational	B-Algorithm
algebra	I-Algorithm
or	O
an	O
extension	O
thereof	O
(	O
e.g.	O
</s>
<s>
multiset	O
relational	B-Algorithm
algebra	I-Algorithm
with	O
sorting	O
,	O
aggregation	O
and	O
three-valued	O
predicates	O
i.e.	O
</s>
<s>
NULLs	O
as	O
in	O
the	O
case	O
of	O
SQL	B-Language
)	O
.	O
</s>
<s>
The	O
equivalence	O
rules	O
of	O
relational	B-Algorithm
algebra	I-Algorithm
are	O
exploited	O
,	O
in	O
other	O
words	O
,	O
different	O
query	B-Language
structures	I-Language
and	O
orderings	O
can	O
be	O
mathematically	O
proven	O
to	O
yield	O
the	O
same	O
result	O
.	O
</s>
<s>
The	O
result	O
of	O
query	B-General_Concept
rewriting	I-General_Concept
may	O
not	O
be	O
at	O
the	O
same	O
abstraction	B-Architecture
level	I-Architecture
or	O
application	B-Application
programming	I-Application
interface	I-Application
(	O
API	B-Application
)	O
as	O
the	O
original	O
set	O
of	O
queries	B-Language
(	O
though	O
often	O
is	O
)	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
input	O
queries	B-Language
may	O
be	O
in	O
relational	B-Algorithm
algebra	I-Algorithm
or	O
SQL	B-Language
,	O
and	O
the	O
rewritten	O
queries	B-Language
may	O
be	O
closer	O
to	O
the	O
physical	O
representation	O
of	O
the	O
data	O
,	O
e.g.	O
</s>
<s>
Query	B-General_Concept
rewriting	I-General_Concept
can	O
also	O
involve	O
materialization	B-Application
of	I-Application
views	I-Application
and	O
other	O
subqueries	O
;	O
operations	O
that	O
may	O
or	O
may	O
not	O
be	O
available	O
to	O
the	O
API	B-Application
user	O
.	O
</s>
<s>
The	O
query	B-General_Concept
rewriting	I-General_Concept
transformation	O
can	O
be	O
creating	O
indices	B-Data_Structure
from	O
which	O
the	O
optimizer	O
can	O
choose	O
(	O
some	O
database	O
systems	O
create	O
their	O
own	O
indexes	O
if	O
deemed	O
useful	O
)	O
,	O
mandating	O
the	O
use	O
of	O
specific	O
indices	B-Data_Structure
,	O
creating	O
materialized	O
and/or	O
denormalized	O
views	B-Language
,	O
or	O
helping	O
a	O
database	O
system	O
gather	O
statistics	O
on	O
the	O
data	O
and	O
query	O
use	O
,	O
as	O
the	O
optimality	O
depends	O
on	O
patterns	O
in	O
data	O
and	O
typical	O
query	O
usage	O
.	O
</s>
<s>
Query	B-General_Concept
rewriting	I-General_Concept
may	O
be	O
rule	O
based	O
or	O
optimizer	O
based	O
.	O
</s>
<s>
Some	O
sources	O
discuss	O
query	B-General_Concept
rewriting	I-General_Concept
as	O
a	O
distinct	O
step	O
prior	O
to	O
optimization	O
,	O
operating	O
at	O
the	O
level	O
of	O
the	O
user	O
accessible	O
algebra	O
API	B-Application
(	O
e.g.	O
</s>
<s>
SQL	B-Language
)	O
.	O
</s>
<s>
There	O
are	O
other	O
,	O
largely	O
unrelated	O
concepts	O
also	O
named	O
similarly	O
,	O
for	O
example	O
,	O
query	B-General_Concept
rewriting	I-General_Concept
by	O
search	B-Application
engines	I-Application
.	O
</s>
