<s>
In	O
database	B-General_Concept
theory	I-General_Concept
,	O
relational	B-Algorithm
algebra	I-Algorithm
is	O
a	O
theory	O
that	O
uses	O
algebraic	O
structures	O
for	O
modeling	O
data	O
,	O
and	O
defining	O
queries	B-Application
on	O
it	O
with	O
a	O
well	O
founded	O
semantics	B-Application
.	O
</s>
<s>
The	O
main	O
application	O
of	O
relational	B-Algorithm
algebra	I-Algorithm
is	O
to	O
provide	O
a	O
theoretical	O
foundation	O
for	O
relational	B-Application
databases	I-Application
,	O
particularly	O
query	B-Language
languages	I-Language
for	O
such	O
databases	O
,	O
chief	O
among	O
which	O
is	O
SQL	B-Language
.	O
</s>
<s>
Relational	B-Application
databases	I-Application
store	O
tabular	O
data	O
represented	O
as	O
relations	B-Language
.	O
</s>
<s>
Queries	B-Application
over	O
relational	B-Application
databases	I-Application
often	O
likewise	O
return	O
tabular	O
data	O
represented	O
as	O
relations	B-Language
.	O
</s>
<s>
The	O
main	O
purpose	O
of	O
relational	B-Algorithm
algebra	I-Algorithm
is	O
to	O
define	O
operators	O
that	O
transform	O
one	O
or	O
more	O
input	O
relations	B-Language
to	O
an	O
output	O
relation	B-Algorithm
.	O
</s>
<s>
Given	O
that	O
these	O
operators	O
accept	O
relations	B-Language
as	O
input	O
and	O
produce	O
relations	B-Language
as	O
output	O
,	O
they	O
can	O
be	O
combined	O
and	O
used	O
to	O
express	O
potentially	O
complex	O
queries	B-Application
that	O
transform	O
potentially	O
many	O
input	O
relations	B-Language
(	O
whose	O
data	O
are	O
stored	O
in	O
the	O
database	O
)	O
into	O
a	O
single	O
output	O
relation	B-Algorithm
(	O
the	O
query	O
results	O
)	O
.	O
</s>
<s>
Unary	O
operators	O
accept	O
as	O
input	O
a	O
single	O
relation	B-Algorithm
;	O
examples	O
include	O
operators	O
to	O
filter	O
certain	O
attributes	O
(	O
columns	O
)	O
or	O
tuples	B-Application
(	O
rows	O
)	O
from	O
an	O
input	O
relation	B-Algorithm
.	O
</s>
<s>
Binary	O
operators	O
accept	O
as	O
input	O
two	O
relations	B-Language
;	O
such	O
operators	O
combine	O
the	O
two	O
input	O
relations	B-Language
into	O
a	O
single	O
output	O
relation	B-Algorithm
by	O
,	O
for	O
example	O
,	O
taking	O
all	O
tuples	B-Application
found	O
in	O
either	O
relation	B-Algorithm
,	O
removing	O
tuples	B-Application
from	O
the	O
first	O
relation	B-Algorithm
found	O
in	O
the	O
second	O
relation	B-Algorithm
,	O
extending	O
the	O
tuples	B-Application
of	O
the	O
first	O
relation	B-Algorithm
with	O
tuples	B-Application
in	O
the	O
second	O
relation	B-Algorithm
matching	O
certain	O
conditions	O
,	O
and	O
so	O
forth	O
.	O
</s>
<s>
Relational	B-Algorithm
algebra	I-Algorithm
received	O
little	O
attention	O
outside	O
of	O
pure	O
mathematics	O
until	O
the	O
publication	O
of	O
E.F.	O
Codd	O
's	O
relational	B-Architecture
model	I-Architecture
of	I-Architecture
data	I-Architecture
in	O
1970	O
.	O
</s>
<s>
Codd	O
proposed	O
such	O
an	O
algebra	O
as	O
a	O
basis	O
for	O
database	B-Language
query	I-Language
languages	I-Language
.	O
</s>
<s>
Five	O
primitive	O
operators	O
of	O
Codd	O
's	O
algebra	O
are	O
the	O
selection	B-Algorithm
,	O
the	O
projection	B-Algorithm
,	O
the	O
Cartesian	O
product	O
(	O
also	O
called	O
the	O
cross	O
product	O
or	O
cross	O
join	O
)	O
,	O
the	O
set	O
union	O
,	O
and	O
the	O
set	O
difference	O
.	O
</s>
<s>
The	O
relational	B-Algorithm
algebra	I-Algorithm
uses	O
set	O
union	O
,	O
set	O
difference	O
,	O
and	O
Cartesian	O
product	O
from	O
set	O
theory	O
,	O
but	O
adds	O
additional	O
constraints	O
to	O
these	O
operators	O
.	O
</s>
<s>
For	O
set	O
union	O
and	O
set	O
difference	O
,	O
the	O
two	O
relations	B-Language
involved	O
must	O
be	O
union-compatible	O
—	O
that	O
is	O
,	O
the	O
two	O
relations	B-Language
must	O
have	O
the	O
same	O
set	O
of	O
attributes	O
.	O
</s>
<s>
Because	O
set	O
intersection	O
is	O
defined	O
in	O
terms	O
of	O
set	O
union	O
and	O
set	O
difference	O
,	O
the	O
two	O
relations	B-Language
involved	O
in	O
set	O
intersection	O
must	O
also	O
be	O
union-compatible	O
.	O
</s>
<s>
For	O
the	O
Cartesian	O
product	O
to	O
be	O
defined	O
,	O
the	O
two	O
relations	B-Language
involved	O
must	O
have	O
disjoint	O
headers	O
—	O
that	O
is	O
,	O
they	O
must	O
not	O
have	O
a	O
common	O
attribute	O
name	O
.	O
</s>
<s>
In	O
addition	O
,	O
the	O
Cartesian	O
product	O
is	O
defined	O
differently	O
from	O
the	O
one	O
in	O
set	O
theory	O
in	O
the	O
sense	O
that	O
tuples	B-Application
are	O
considered	O
to	O
be	O
"	O
shallow	O
"	O
for	O
the	O
purposes	O
of	O
the	O
operation	O
.	O
</s>
<s>
That	O
is	O
,	O
the	O
Cartesian	O
product	O
of	O
a	O
set	O
of	O
n-tuples	O
with	O
a	O
set	O
of	O
m-tuples	O
yields	O
a	O
set	O
of	O
"	O
flattened	O
"	O
-tuples	O
(	O
whereas	O
basic	O
set	O
theory	O
would	O
have	O
prescribed	O
a	O
set	O
of	O
2-tuples	O
,	O
each	O
containing	O
an	O
n-tuple	O
and	O
an	O
m-tuple	O
)	O
.	O
</s>
<s>
A	O
projection	B-Algorithm
is	O
a	O
unary	O
operation	O
written	O
as	O
where	O
is	O
a	O
set	O
of	O
attribute	O
names	O
.	O
</s>
<s>
The	O
result	O
of	O
such	O
projection	B-Algorithm
is	O
defined	O
as	O
the	O
set	O
that	O
is	O
obtained	O
when	O
all	O
tuples	B-Application
in	O
R	O
are	O
restricted	O
to	O
the	O
set	O
.	O
</s>
<s>
Note	O
:	O
when	O
implemented	O
in	O
SQL	B-Language
standard	O
the	O
"	O
default	O
projection	B-Algorithm
"	O
returns	O
a	O
multiset	B-Language
instead	O
of	O
a	O
set	O
,	O
and	O
the	O
projection	B-Algorithm
to	O
eliminate	O
duplicate	O
data	O
is	O
obtained	O
by	O
the	O
addition	O
of	O
the	O
DISTINCT	O
keyword	O
.	O
</s>
<s>
A	O
generalized	O
selection	B-Algorithm
is	O
a	O
unary	O
operation	O
written	O
as	O
where	O
is	O
a	O
propositional	O
formula	O
that	O
consists	O
of	O
atoms	O
as	O
allowed	O
in	O
the	O
normal	B-Algorithm
selection	I-Algorithm
and	O
the	O
logical	O
operators	O
(	O
and	O
)	O
,	O
(	O
or	O
)	O
and	O
(	O
negation	O
)	O
.	O
</s>
<s>
This	O
selection	B-Algorithm
selects	O
all	O
those	O
tuples	B-Application
in	O
R	O
for	O
which	O
holds	O
.	O
</s>
<s>
To	O
obtain	O
a	O
listing	O
of	O
all	O
friends	O
or	O
business	O
associates	O
in	O
an	O
address	O
book	O
,	O
the	O
selection	B-Algorithm
might	O
be	O
written	O
as	O
.	O
</s>
<s>
The	O
result	O
would	O
be	O
a	O
relation	B-Algorithm
containing	O
every	O
attribute	O
of	O
every	O
unique	O
record	O
where	O
is	O
true	O
or	O
where	O
is	O
true	O
.	O
</s>
<s>
A	O
rename	O
is	O
a	O
unary	O
operation	O
written	O
as	O
where	O
the	O
result	O
is	O
identical	O
to	O
R	O
except	O
that	O
the	O
b	O
attribute	O
in	O
all	O
tuples	B-Application
is	O
renamed	O
to	O
an	O
a	O
attribute	O
.	O
</s>
<s>
This	O
is	O
simply	O
used	O
to	O
rename	O
the	O
attribute	O
of	O
a	O
relation	B-Algorithm
or	O
the	O
relation	B-Algorithm
itself	O
.	O
</s>
<s>
To	O
rename	O
the	O
"	O
isFriend	O
"	O
attribute	O
to	O
"	O
isBusinessContact	O
"	O
in	O
a	O
relation	B-Algorithm
,	O
might	O
be	O
used	O
.	O
</s>
<s>
Natural	O
join	O
( ⋈	O
)	O
is	O
a	O
binary	O
operator	O
that	O
is	O
written	O
as	O
(	O
R	O
⋈	O
S	O
)	O
where	O
R	O
and	O
S	O
are	O
relations	B-Language
.	O
</s>
<s>
The	O
result	O
of	O
the	O
natural	O
join	O
is	O
the	O
set	O
of	O
all	O
combinations	O
of	O
tuples	B-Application
in	O
R	O
and	O
S	O
that	O
are	O
equal	O
on	O
their	O
common	O
attribute	O
names	O
.	O
</s>
<s>
This	O
can	O
also	O
be	O
used	O
to	O
define	O
composition	O
of	O
relations	B-Language
.	O
</s>
<s>
Note	O
that	O
if	O
the	O
same	O
variable	O
appears	O
in	O
each	O
of	O
two	O
predicates	B-Algorithm
that	O
are	O
connected	O
by	O
AND	O
,	O
then	O
that	O
variable	O
stands	O
for	O
the	O
same	O
thing	O
and	O
both	O
appearances	O
must	O
always	O
be	O
substituted	O
by	O
the	O
same	O
value	O
(	O
this	O
is	O
a	O
consequence	O
of	O
the	O
idempotence	O
of	O
the	O
logical	O
AND	O
)	O
.	O
</s>
<s>
In	O
particular	O
,	O
natural	O
join	O
allows	O
the	O
combination	O
of	O
relations	B-Language
that	O
are	O
associated	O
by	O
a	O
foreign	B-Application
key	I-Application
.	O
</s>
<s>
For	O
example	O
,	O
in	O
the	O
above	O
example	O
a	O
foreign	B-Application
key	I-Application
probably	O
holds	O
from	O
Employee.DeptName	O
to	O
Dept.DeptName	O
and	O
then	O
the	O
natural	O
join	O
of	O
Employee	O
and	O
Dept	O
combines	O
all	O
employees	O
with	O
their	O
departments	O
.	O
</s>
<s>
This	O
works	O
because	O
the	O
foreign	B-Application
key	I-Application
holds	O
between	O
attributes	O
with	O
the	O
same	O
name	O
.	O
</s>
<s>
If	O
this	O
is	O
not	O
the	O
case	O
such	O
as	O
in	O
the	O
foreign	B-Application
key	I-Application
from	O
Dept.Manager	O
to	O
Employee.Name	O
then	O
these	O
columns	O
must	O
be	O
renamed	O
before	O
taking	O
the	O
natural	O
join	O
.	O
</s>
<s>
More	O
formally	O
the	O
semantics	B-Application
of	O
the	O
natural	O
join	O
are	O
defined	O
as	O
follows	O
:	O
</s>
<s>
where	O
Fun(t )	O
is	O
a	O
predicate	B-Algorithm
that	O
is	O
true	O
for	O
a	O
relation	B-Algorithm
t	O
(	O
in	O
the	O
mathematical	O
sense	O
)	O
iff	O
t	O
is	O
a	O
function	O
(	O
that	O
is	O
,	O
t	O
does	O
not	O
map	O
any	O
attribute	O
to	O
multiple	O
values	O
)	O
.	O
</s>
<s>
Then	O
we	O
take	O
the	O
Cartesian	O
product	O
and	O
select	O
the	O
tuples	B-Application
that	O
are	O
to	O
be	O
joined	O
:	O
</s>
<s>
Finally	O
we	O
take	O
a	O
projection	B-Algorithm
to	O
get	O
rid	O
of	O
the	O
renamed	O
attributes	O
:	O
</s>
<s>
The	O
θ-join	O
( ⋈θ	O
)	O
on	O
the	O
predicate	B-Algorithm
CarPrice	O
≥	O
BoatPrice	O
produces	O
the	O
flattened	O
pairs	O
of	O
rows	O
which	O
satisfy	O
the	O
predicate	B-Algorithm
.	O
</s>
<s>
In	O
order	O
to	O
combine	O
tuples	B-Application
from	O
two	O
relations	B-Language
where	O
the	O
combination	O
condition	O
is	O
not	O
simply	O
the	O
equality	O
of	O
shared	O
attributes	O
it	O
is	O
convenient	O
to	O
have	O
a	O
more	O
general	O
form	O
of	O
join	O
operator	O
,	O
which	O
is	O
the	O
θ-join	O
(	O
or	O
theta-join	O
)	O
.	O
</s>
<s>
The	O
θ-join	O
is	O
a	O
binary	O
operator	O
that	O
is	O
written	O
as	O
or	O
where	O
a	O
and	O
b	O
are	O
attribute	O
names	O
,	O
θ	O
is	O
a	O
binary	O
relational	O
operator	O
in	O
the	O
set	O
{	O
<, ≤, =, ≠, >	O
,	O
≥}	O
,	O
υ	O
is	O
a	O
value	O
constant	O
,	O
and	O
R	O
and	O
S	O
are	O
relations	B-Language
.	O
</s>
<s>
The	O
result	O
of	O
this	O
operation	O
consists	O
of	O
all	O
combinations	O
of	O
tuples	B-Application
in	O
R	O
and	O
S	O
that	O
satisfy	O
θ	O
.	O
</s>
<s>
Note	O
,	O
however	O
,	O
that	O
a	O
computer	O
language	O
that	O
supports	O
the	O
natural	O
join	O
and	O
selection	B-Algorithm
operators	O
does	O
not	O
need	O
θ-join	O
as	O
well	O
,	O
as	O
this	O
can	O
be	O
achieved	O
by	O
selection	B-Algorithm
from	O
the	O
result	O
of	O
a	O
natural	O
join	O
(	O
which	O
degenerates	O
to	O
Cartesian	O
product	O
when	O
there	O
are	O
no	O
shared	O
attributes	O
)	O
.	O
</s>
<s>
In	O
SQL	B-Language
implementations	O
,	O
joining	O
on	O
a	O
predicate	B-Algorithm
is	O
usually	O
called	O
an	O
inner	O
join	O
,	O
and	O
the	O
on	O
keyword	O
allows	O
one	O
to	O
specify	O
the	O
predicate	B-Algorithm
used	O
to	O
filter	O
the	O
rows	O
.	O
</s>
<s>
The	O
left	O
semijoin	O
is	O
a	O
joining	O
similar	O
to	O
the	O
natural	O
join	O
and	O
written	O
as	O
where	O
and	O
are	O
relations	B-Language
.	O
</s>
<s>
The	O
result	O
is	O
the	O
set	O
of	O
all	O
tuples	B-Application
in	O
for	O
which	O
there	O
is	O
a	O
tuple	B-Application
in	O
that	O
is	O
equal	O
on	O
their	O
common	O
attribute	O
names	O
.	O
</s>
<s>
The	O
antijoin	O
,	O
written	O
as	O
R	O
▷	O
S	O
where	O
R	O
and	O
S	O
are	O
relations	B-Language
,	O
is	O
similar	O
to	O
the	O
semijoin	O
,	O
but	O
the	O
result	O
of	O
an	O
antijoin	O
is	O
only	O
those	O
tuples	B-Application
in	O
R	O
for	O
which	O
there	O
is	O
no	O
tuple	B-Application
in	O
S	O
that	O
is	O
equal	O
on	O
their	O
common	O
attribute	O
names	O
.	O
</s>
<s>
The	O
division	O
is	O
a	O
binary	O
operation	O
that	O
is	O
written	O
as	O
R	O
÷	O
S	O
.	O
Division	O
is	O
not	O
implemented	O
directly	O
in	O
SQL	B-Language
.	O
</s>
<s>
The	O
result	O
consists	O
of	O
the	O
restrictions	O
of	O
tuples	B-Application
in	O
R	O
to	O
the	O
attribute	O
names	O
unique	O
to	O
R	O
,	O
i.e.	O
,	O
in	O
the	O
header	O
of	O
R	O
but	O
not	O
in	O
the	O
header	O
of	O
S	O
,	O
for	O
which	O
it	O
holds	O
that	O
all	O
their	O
combinations	O
with	O
tuples	B-Application
in	O
S	O
are	O
present	O
in	O
R	O
.	O
For	O
an	O
example	O
see	O
the	O
tables	O
Completed	O
,	O
DBProject	O
and	O
their	O
division	O
:	O
</s>
<s>
More	O
formally	O
the	O
semantics	B-Application
of	O
the	O
division	O
is	O
defined	O
as	O
follows:where	O
 { a1 , ... , an } 	O
is	O
the	O
set	O
of	O
attribute	O
names	O
unique	O
to	O
R	O
and	O
t[a1,...,an]	O
is	O
the	O
restriction	O
of	O
t	O
to	O
this	O
set	O
.	O
</s>
<s>
We	O
assume	O
that	O
a1	O
,...,	O
an	O
are	O
the	O
attribute	O
names	O
unique	O
to	O
R	O
and	O
b1	O
,...,	O
bm	O
are	O
the	O
attribute	O
names	O
of	O
S	O
.	O
In	O
the	O
first	O
step	O
we	O
project	O
R	O
on	O
its	O
unique	O
attribute	O
names	O
and	O
construct	O
all	O
combinations	O
with	O
tuples	B-Application
in	O
S	O
:	O
</s>
<s>
In	O
the	O
prior	O
example	O
,	O
T	O
would	O
represent	O
a	O
table	B-Application
such	O
that	O
every	O
Student	O
(	O
because	O
Student	O
is	O
the	O
unique	O
key	O
/	O
attribute	O
of	O
the	O
Completed	O
table	B-Application
)	O
is	O
combined	O
with	O
every	O
given	O
Task	O
.	O
</s>
<s>
relation	B-Algorithm
:	O
</s>
<s>
EG	O
:	O
Again	O
with	O
projections	B-Algorithm
—	O
T	O
and	O
R	O
need	O
to	O
have	O
identical	O
attribute	O
names/headers	O
.	O
</s>
<s>
all	O
combinations	O
with	O
tuples	B-Application
in	O
S	O
were	O
present	O
in	O
R	O
:	O
</s>
<s>
In	O
practice	O
the	O
classical	O
relational	B-Algorithm
algebra	I-Algorithm
described	O
above	O
is	O
extended	O
with	O
various	O
operations	O
such	O
as	O
outer	O
joins	O
,	O
aggregate	O
functions	O
and	O
even	O
transitive	O
closure	O
.	O
</s>
<s>
Whereas	O
the	O
result	O
of	O
a	O
join	O
(	O
or	O
inner	O
join	O
)	O
consists	O
of	O
tuples	B-Application
formed	O
by	O
combining	O
matching	O
tuples	B-Application
in	O
the	O
two	O
operands	O
,	O
an	O
outer	O
join	O
contains	O
those	O
tuples	B-Application
and	O
additionally	O
some	O
tuples	B-Application
formed	O
by	O
extending	O
an	O
unmatched	O
tuple	B-Application
in	O
one	O
of	O
the	O
operands	O
by	O
"	O
fill	O
"	O
values	O
for	O
each	O
of	O
the	O
attributes	O
of	O
the	O
other	O
operand	O
.	O
</s>
<s>
Outer	O
joins	O
are	O
not	O
considered	O
part	O
of	O
the	O
classical	O
relational	B-Algorithm
algebra	I-Algorithm
discussed	O
so	O
far	O
.	O
</s>
<s>
The	O
operators	O
defined	O
in	O
this	O
section	O
assume	O
the	O
existence	O
of	O
a	O
null	B-Language
value	O
,	O
ω	O
,	O
which	O
we	O
do	O
not	O
define	O
,	O
to	O
be	O
used	O
for	O
the	O
fill	O
values	O
;	O
in	O
practice	O
this	O
corresponds	O
to	O
the	O
NULL	B-Language
in	O
SQL	B-Language
.	O
</s>
<s>
In	O
order	O
to	O
make	O
subsequent	O
selection	B-Algorithm
operations	O
on	O
the	O
resulting	O
table	B-Application
meaningful	O
,	O
a	O
semantic	O
meaning	O
needs	O
to	O
be	O
assigned	O
to	O
nulls	B-Language
;	O
in	O
Codd	O
's	O
approach	O
the	O
propositional	O
logic	O
used	O
by	O
the	O
selection	B-Algorithm
is	O
extended	O
to	O
a	O
three-valued	O
logic	O
,	O
although	O
we	O
elide	O
those	O
details	O
in	O
this	O
article	O
.	O
</s>
<s>
The	O
left	O
outer	O
join	O
is	O
written	O
as	O
R	O
⟕	O
S	O
where	O
R	O
and	O
S	O
are	O
relations	B-Language
.	O
</s>
<s>
The	O
result	O
of	O
the	O
left	O
outer	O
join	O
is	O
the	O
set	O
of	O
all	O
combinations	O
of	O
tuples	B-Application
in	O
R	O
and	O
S	O
that	O
are	O
equal	O
on	O
their	O
common	O
attribute	O
names	O
,	O
in	O
addition	O
(	O
loosely	O
speaking	O
)	O
to	O
tuples	B-Application
in	O
R	O
that	O
have	O
no	O
matching	O
tuples	B-Application
in	O
S	O
.	O
</s>
<s>
In	O
the	O
resulting	O
relation	B-Algorithm
,	O
tuples	B-Application
in	O
S	O
which	O
have	O
no	O
common	O
values	O
in	O
common	O
attribute	O
names	O
with	O
tuples	B-Application
in	O
R	O
take	O
a	O
null	B-Language
value	O
,	O
ω	O
.	O
</s>
<s>
Since	O
there	O
are	O
no	O
tuples	B-Application
in	O
Dept	O
with	O
a	O
DeptName	O
of	O
Finance	O
or	O
Executive	O
,	O
ωs	O
occur	O
in	O
the	O
resulting	O
relation	B-Algorithm
where	O
tuples	B-Application
in	O
Employee	O
have	O
a	O
DeptName	O
of	O
Finance	O
or	O
Executive	O
.	O
</s>
<s>
relation	B-Algorithm
on	O
the	O
attributes	O
that	O
are	O
unique	O
to	O
the	O
relation	B-Algorithm
S	O
(	O
those	O
that	O
are	O
not	O
attributes	O
of	O
R	O
)	O
.	O
</s>
<s>
The	O
right	O
outer	O
join	O
of	O
relations	B-Language
R	O
and	O
S	O
is	O
written	O
as	O
R	O
⟖	O
S	O
.	O
The	O
result	O
of	O
the	O
right	O
outer	O
join	O
is	O
the	O
set	O
of	O
all	O
combinations	O
of	O
tuples	B-Application
in	O
R	O
and	O
S	O
that	O
are	O
equal	O
on	O
their	O
common	O
attribute	O
names	O
,	O
in	O
addition	O
to	O
tuples	B-Application
in	O
S	O
that	O
have	O
no	O
matching	O
tuples	B-Application
in	O
R	O
.	O
</s>
<s>
In	O
the	O
resulting	O
relation	B-Algorithm
,	O
tuples	B-Application
in	O
R	O
which	O
have	O
no	O
common	O
values	O
in	O
common	O
attribute	O
names	O
with	O
tuples	B-Application
in	O
S	O
take	O
a	O
null	B-Language
value	O
,	O
ω	O
.	O
</s>
<s>
Since	O
there	O
are	O
no	O
tuples	B-Application
in	O
Employee	O
with	O
a	O
DeptName	O
of	O
Production	O
,	O
ωs	O
occur	O
in	O
the	O
Name	O
and	O
EmpId	O
attributes	O
of	O
the	O
resulting	O
relation	B-Algorithm
where	O
tuples	B-Application
in	O
Dept	O
had	O
DeptName	O
of	O
Production	O
.	O
</s>
<s>
relation	B-Algorithm
on	O
the	O
attributes	O
that	O
are	O
unique	O
to	O
the	O
relation	B-Algorithm
R	O
(	O
those	O
that	O
are	O
not	O
attributes	O
of	O
S	O
)	O
.	O
</s>
<s>
The	O
full	O
outer	O
join	O
is	O
written	O
as	O
R	O
⟗	O
S	O
where	O
R	O
and	O
S	O
are	O
relations	B-Language
.	O
</s>
<s>
The	O
result	O
of	O
the	O
full	O
outer	O
join	O
is	O
the	O
set	O
of	O
all	O
combinations	O
of	O
tuples	B-Application
in	O
R	O
and	O
S	O
that	O
are	O
equal	O
on	O
their	O
common	O
attribute	O
names	O
,	O
in	O
addition	O
to	O
tuples	B-Application
in	O
S	O
that	O
have	O
no	O
matching	O
tuples	B-Application
in	O
R	O
and	O
tuples	B-Application
in	O
R	O
that	O
have	O
no	O
matching	O
tuples	B-Application
in	O
S	O
in	O
their	O
common	O
attribute	O
names	O
.	O
</s>
<s>
In	O
the	O
resulting	O
relation	B-Algorithm
,	O
tuples	B-Application
in	O
R	O
which	O
have	O
no	O
common	O
values	O
in	O
common	O
attribute	O
names	O
with	O
tuples	B-Application
in	O
S	O
take	O
a	O
null	B-Language
value	O
,	O
ω	O
.	O
Tuples	B-Application
in	O
S	O
which	O
have	O
no	O
common	O
values	O
in	O
common	O
attribute	O
names	O
with	O
tuples	B-Application
in	O
R	O
also	O
take	O
a	O
null	B-Language
value	O
,	O
ω	O
.	O
</s>
<s>
There	O
is	O
nothing	O
in	O
relational	B-Algorithm
algebra	I-Algorithm
introduced	O
so	O
far	O
that	O
would	O
allow	O
computations	O
on	O
the	O
data	O
domains	O
(	O
other	O
than	O
evaluation	O
of	O
propositional	O
expressions	O
involving	O
equality	O
)	O
.	O
</s>
<s>
Practical	O
query	B-Language
languages	I-Language
have	O
such	O
facilities	O
,	O
e.g.	O
</s>
<s>
the	O
SQL	B-Language
SELECT	I-Language
allows	O
arithmetic	O
operations	O
to	O
define	O
new	O
columns	O
in	O
the	O
result	O
,	O
and	O
a	O
similar	O
facility	O
is	O
provided	O
more	O
explicitly	O
by	O
Tutorial	O
D	O
's	O
EXTEND	O
keyword	O
.	O
</s>
<s>
In	O
database	B-General_Concept
theory	I-General_Concept
,	O
this	O
is	O
called	O
extended	B-Algorithm
projection	I-Algorithm
.	O
</s>
<s>
Furthermore	O
,	O
computing	O
various	O
functions	O
on	O
a	O
column	O
,	O
like	O
the	O
summing	O
up	O
of	O
its	O
elements	O
,	O
is	O
also	O
not	O
possible	O
using	O
the	O
relational	B-Algorithm
algebra	I-Algorithm
introduced	O
so	O
far	O
.	O
</s>
<s>
There	O
are	O
five	O
aggregate	O
functions	O
that	O
are	O
included	O
with	O
most	O
relational	B-Application
database	I-Application
systems	O
.	O
</s>
<s>
In	O
relational	B-Algorithm
algebra	I-Algorithm
the	O
aggregation	O
operation	O
over	O
a	O
schema	O
(	O
A1	O
,	O
A2	O
,	O
...	O
An	O
)	O
is	O
written	O
as	O
follows	O
:	O
</s>
<s>
The	O
attributes	O
preceding	O
the	O
g	O
are	O
grouping	O
attributes	O
,	O
which	O
function	O
like	O
a	O
"	O
group	O
by	O
"	O
clause	O
in	O
SQL	B-Language
.	O
</s>
<s>
The	O
operation	O
is	O
applied	O
to	O
an	O
arbitrary	O
relation	B-Algorithm
r	O
.	O
The	O
grouping	O
attributes	O
are	O
optional	O
,	O
and	O
if	O
they	O
are	O
not	O
supplied	O
,	O
the	O
aggregation	O
functions	O
are	O
applied	O
across	O
the	O
entire	O
relation	B-Algorithm
to	O
which	O
the	O
operation	O
is	O
applied	O
.	O
</s>
<s>
Let	O
's	O
assume	O
that	O
we	O
have	O
a	O
table	B-Application
named	O
with	O
three	O
columns	O
,	O
namely	O
and	O
.	O
</s>
<s>
Although	O
relational	B-Algorithm
algebra	I-Algorithm
seems	O
powerful	O
enough	O
for	O
most	O
practical	O
purposes	O
,	O
there	O
are	O
some	O
simple	O
and	O
natural	O
operators	O
on	O
relations	B-Language
that	O
cannot	O
be	O
expressed	O
by	O
relational	B-Algorithm
algebra	I-Algorithm
.	O
</s>
<s>
One	O
of	O
them	O
is	O
the	O
transitive	O
closure	O
of	O
a	O
binary	O
relation	B-Algorithm
.	O
</s>
<s>
Given	O
a	O
domain	O
D	O
,	O
let	O
binary	O
relation	B-Algorithm
R	O
be	O
a	O
subset	O
of	O
D×D	O
.	O
</s>
<s>
It	O
can	O
be	O
proved	O
using	O
the	O
fact	O
that	O
there	O
is	O
no	O
relational	B-Algorithm
algebra	I-Algorithm
expression	O
E(R )	O
taking	O
R	O
as	O
a	O
variable	O
argument	O
that	O
produces	O
R+	O
.	O
</s>
<s>
SQL	B-Language
however	O
officially	O
supports	O
such	O
fixpoint	B-Language
queries	I-Language
since	O
1999	O
,	O
and	O
it	O
had	O
vendor-specific	O
extensions	O
in	O
this	O
direction	O
well	O
before	O
that	O
.	O
</s>
<s>
Relational	B-Application
database	I-Application
management	I-Application
systems	I-Application
often	O
include	O
a	O
query	B-Language
optimizer	I-Language
which	O
attempts	O
to	O
determine	O
the	O
most	O
efficient	O
way	O
to	O
execute	O
a	O
given	O
query	O
.	O
</s>
<s>
Query	B-Language
optimizers	I-Language
enumerate	O
possible	O
query	B-Language
plans	I-Language
,	O
estimate	O
their	O
cost	O
,	O
and	O
pick	O
the	O
plan	O
with	O
the	O
lowest	O
estimated	O
cost	O
.	O
</s>
<s>
If	O
queries	B-Application
are	O
represented	O
by	O
operators	O
from	O
relational	B-Algorithm
algebra	I-Algorithm
,	O
the	O
query	B-Language
optimizer	I-Language
can	O
enumerate	O
possible	O
query	B-Language
plans	I-Language
by	O
rewriting	O
the	O
initial	O
query	O
using	O
the	O
algebraic	O
properties	O
of	O
these	O
operators	O
.	O
</s>
<s>
leaves	O
are	O
relations	B-Language
,	O
</s>
<s>
subtrees	B-Application
are	O
subexpressions	O
.	O
</s>
<s>
The	O
primary	O
goal	O
of	O
the	O
query	B-Language
optimizer	I-Language
is	O
to	O
transform	O
expression	B-Algorithm
trees	I-Algorithm
into	O
equivalent	O
expression	B-Algorithm
trees	I-Algorithm
,	O
where	O
the	O
average	O
size	O
of	O
the	O
relations	B-Language
yielded	O
by	O
subexpressions	O
in	O
the	O
tree	B-Application
is	O
smaller	O
than	O
it	O
was	O
before	O
the	O
optimization	B-Language
.	O
</s>
<s>
The	O
secondary	O
goal	O
is	O
to	O
try	O
to	O
form	O
common	O
subexpressions	O
within	O
a	O
single	O
query	O
,	O
or	O
if	O
there	O
is	O
more	O
than	O
one	O
query	O
being	O
evaluated	O
at	O
the	O
same	O
time	O
,	O
in	O
all	O
of	O
those	O
queries	B-Application
.	O
</s>
<s>
The	O
rationale	O
behind	O
the	O
second	O
goal	O
is	O
that	O
it	O
is	O
enough	O
to	O
compute	O
common	O
subexpressions	O
once	O
,	O
and	O
the	O
results	O
can	O
be	O
used	O
in	O
all	O
queries	B-Application
that	O
contain	O
that	O
subexpression	O
.	O
</s>
<s>
Rules	O
about	O
selection	B-Algorithm
operators	O
play	O
the	O
most	O
important	O
role	O
in	O
query	B-Language
optimization	I-Language
.	O
</s>
<s>
Selection	B-Algorithm
is	O
an	O
operator	O
that	O
very	O
effectively	O
decreases	O
the	O
number	O
of	O
rows	O
in	O
its	O
operand	O
,	O
so	O
if	O
the	O
selections	O
in	O
an	O
expression	B-Algorithm
tree	I-Algorithm
are	O
moved	O
towards	O
the	O
leaves	O
,	O
the	O
internal	O
relations	B-Language
(	O
yielded	O
by	O
subexpressions	O
)	O
will	O
likely	O
shrink	O
.	O
</s>
<s>
Selection	B-Algorithm
is	O
idempotent	O
(	O
multiple	O
applications	O
of	O
the	O
same	O
selection	B-Algorithm
have	O
no	O
additional	O
effect	O
beyond	O
the	O
first	O
one	O
)	O
,	O
and	O
commutative	O
(	O
the	O
order	O
selections	O
are	O
applied	O
in	O
has	O
no	O
effect	O
on	O
the	O
eventual	O
result	O
)	O
.	O
</s>
<s>
A	O
selection	B-Algorithm
whose	O
condition	O
is	O
a	O
conjunction	O
of	O
simpler	O
conditions	O
is	O
equivalent	O
to	O
a	O
sequence	O
of	O
selections	O
with	O
those	O
same	O
individual	O
conditions	O
,	O
and	O
selection	B-Algorithm
whose	O
condition	O
is	O
a	O
disjunction	O
is	O
equivalent	O
to	O
a	O
union	O
of	O
selections	O
.	O
</s>
<s>
If	O
the	O
input	O
relations	B-Language
have	O
N	O
and	O
M	O
rows	O
,	O
the	O
result	O
will	O
contain	O
rows	O
.	O
</s>
<s>
This	O
can	O
be	O
effectively	O
done	O
if	O
the	O
cross	O
product	O
is	O
followed	O
by	O
a	O
selection	B-Algorithm
operator	O
,	O
e.g.	O
</s>
<s>
If	O
the	O
cross	O
product	O
is	O
not	O
followed	O
by	O
a	O
selection	B-Algorithm
operator	O
,	O
we	O
can	O
try	O
to	O
push	O
down	O
a	O
selection	B-Algorithm
from	O
higher	O
levels	O
of	O
the	O
expression	B-Algorithm
tree	I-Algorithm
using	O
the	O
other	O
selection	B-Algorithm
rules	O
.	O
</s>
<s>
In	O
the	O
above	O
case	O
the	O
condition	O
A	O
is	O
broken	O
up	O
in	O
to	O
conditions	O
B	O
,	O
C	O
and	O
D	O
using	O
the	O
split	O
rules	O
about	O
complex	O
selection	B-Algorithm
conditions	O
,	O
so	O
that	O
and	O
B	O
contains	O
attributes	O
only	O
from	O
R	O
,	O
C	O
contains	O
attributes	O
only	O
from	O
P	O
,	O
and	O
D	O
contains	O
the	O
part	O
of	O
A	O
that	O
contains	O
attributes	O
from	O
both	O
R	O
and	O
P	O
.	O
Note	O
,	O
that	O
B	O
,	O
C	O
or	O
D	O
are	O
possibly	O
empty	O
.	O
</s>
<s>
Selection	B-Algorithm
is	O
distributive	O
over	O
the	O
set	O
difference	O
,	O
intersection	O
,	O
and	O
union	O
operators	O
.	O
</s>
<s>
The	O
following	O
three	O
rules	O
are	O
used	O
to	O
push	O
selection	B-Algorithm
below	O
set	O
operations	O
in	O
the	O
expression	B-Algorithm
tree	I-Algorithm
.	O
</s>
<s>
For	O
the	O
set	O
difference	O
and	O
the	O
intersection	O
operators	O
,	O
it	O
is	O
possible	O
to	O
apply	O
the	O
selection	B-Algorithm
operator	O
to	O
just	O
one	O
of	O
the	O
operands	O
following	O
the	O
transformation	O
.	O
</s>
<s>
This	O
can	O
be	O
beneficial	O
where	O
one	O
of	O
the	O
operands	O
is	O
small	O
,	O
and	O
the	O
overhead	O
of	O
evaluating	O
the	O
selection	B-Algorithm
operator	O
outweighs	O
the	O
benefits	O
of	O
using	O
a	O
smaller	O
relation	B-Algorithm
as	O
an	O
operand	O
.	O
</s>
<s>
Selection	B-Algorithm
commutes	O
with	O
projection	B-Algorithm
if	O
and	O
only	O
if	O
the	O
fields	O
referenced	O
in	O
the	O
selection	B-Algorithm
condition	O
are	O
a	O
subset	O
of	O
the	O
fields	O
in	O
the	O
projection	B-Algorithm
.	O
</s>
<s>
Performing	O
selection	B-Algorithm
before	O
projection	B-Algorithm
may	O
be	O
useful	O
if	O
the	O
operand	O
is	O
a	O
cross	O
product	O
or	O
join	O
.	O
</s>
<s>
In	O
other	O
cases	O
,	O
if	O
the	O
selection	B-Algorithm
condition	O
is	O
relatively	O
expensive	O
to	O
compute	O
,	O
moving	O
selection	B-Algorithm
outside	O
the	O
projection	B-Algorithm
may	O
reduce	O
the	O
number	O
of	O
tuples	B-Application
which	O
must	O
be	O
tested	O
(	O
since	O
projection	B-Algorithm
may	O
produce	O
fewer	O
tuples	B-Application
due	O
to	O
the	O
elimination	O
of	O
duplicates	O
resulting	O
from	O
omitted	O
fields	O
)	O
.	O
</s>
<s>
Projection	B-Algorithm
is	O
idempotent	O
,	O
so	O
that	O
a	O
series	O
of	O
(	O
valid	O
)	O
projections	B-Algorithm
is	O
equivalent	O
to	O
the	O
outermost	O
projection	B-Algorithm
.	O
</s>
<s>
Projection	B-Algorithm
is	O
distributive	O
over	O
set	O
union	O
.	O
</s>
<s>
Projection	B-Algorithm
does	O
not	O
distribute	O
over	O
intersection	O
and	O
set	O
difference	O
.	O
</s>
<s>
The	O
first	O
query	B-Language
language	I-Language
to	O
be	O
based	O
on	O
Codd	O
's	O
algebra	O
was	O
Alpha	O
,	O
developed	O
by	O
Dr.	O
Codd	O
himself	O
.	O
</s>
<s>
Subsequently	O
,	O
ISBL	B-Language
was	O
created	O
,	O
and	O
this	O
pioneering	O
work	O
has	O
been	O
acclaimed	O
by	O
many	O
authorities	O
as	O
having	O
shown	O
the	O
way	O
to	O
make	O
Codd	O
's	O
idea	O
into	O
a	O
useful	O
language	O
.	O
</s>
<s>
Business	B-Application
System	I-Application
12	I-Application
was	O
a	O
short-lived	O
industry-strength	O
relational	O
DBMS	O
that	O
followed	O
the	O
ISBL	B-Language
example	O
.	O
</s>
<s>
In	O
1998	O
Chris	O
Date	O
and	O
Hugh	O
Darwen	O
proposed	O
a	O
language	O
called	O
Tutorial	O
D	O
intended	O
for	O
use	O
in	O
teaching	O
relational	B-Application
database	I-Application
theory	O
,	O
and	O
its	O
query	B-Language
language	I-Language
also	O
draws	O
on	O
ISBL	B-Language
's	O
ideas	O
.	O
</s>
<s>
Rel	B-Application
is	O
an	O
implementation	O
of	O
Tutorial	O
D	O
.	O
</s>
<s>
Even	O
the	O
query	B-Language
language	I-Language
of	O
SQL	B-Language
is	O
loosely	O
based	O
on	O
a	O
relational	B-Algorithm
algebra	I-Algorithm
,	O
though	O
the	O
operands	O
in	O
SQL	B-Language
(	O
tables	O
)	O
are	O
not	O
exactly	O
relations	B-Language
and	O
several	O
useful	O
theorems	O
about	O
the	O
relational	B-Algorithm
algebra	I-Algorithm
do	O
not	O
hold	O
in	O
the	O
SQL	B-Language
counterpart	O
(	O
arguably	O
to	O
the	O
detriment	O
of	O
optimisers	O
and/or	O
users	O
)	O
.	O
</s>
<s>
The	O
SQL	B-Application
table	I-Application
model	O
is	O
a	O
bag	O
(	O
multiset	B-Language
)	O
,	O
rather	O
than	O
a	O
set	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
expression	O
is	O
a	O
theorem	O
for	O
relational	B-Algorithm
algebra	I-Algorithm
on	O
sets	O
,	O
but	O
not	O
for	O
relational	B-Algorithm
algebra	I-Algorithm
on	O
bags	O
;	O
for	O
a	O
treatment	O
of	O
relational	B-Algorithm
algebra	I-Algorithm
on	O
bags	O
see	O
chapter	O
5	O
of	O
the	O
"	O
Complete	O
"	O
textbook	O
by	O
Garcia-Molina	O
,	O
Ullman	O
and	O
Widom	O
.	O
</s>
