Ch4 Algebra
Ch4 Algebra
Algebra
Relational
Algebra
Selection ( ) Selects a subset of rows from
Projection ( ) Deletes unwanted columns from
relation.
relation.
Cross-product (
) Allows us to combine two
relations.
Set-difference ( ) Tuples in reln. 1, but not in
reln. 2.
Union ( ) Tuples in reln. 1 and in reln. 2.
Additional operations:
Intersection, join, division, renaming: Not
essential, but (very!) useful.
Since each operation returns a relation,
operations can be composed! (Algebra is
Database Management Systems 3ed, R. Ramakrishnan and
J. Gehrke
6
sname ratin
Projection g
yuppy 9
Deletes attributes that are lubber 8
not in guppy 5
projection list. rusty 10
Schema of result contains sname (S2)
exactly the fields in the ,rating
projection list, with the same
names that they had in the
(only) input relation.
Projection operator has to age
eliminate duplicates! (Why??) 35.0
Note: real systems 55.5
typically don’t do
duplicate elimination
unless the user explicitly
age (S2)
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 7
si sname rating
Selection d age yuppy 9
28
Selects rows that 58 35.0
satisfy rating (S2)
selection condition. 8
No duplicates in
result! (Why?)
Schema of result
identical to schema
of (only) input sname rating
relation.
yuppy 9
Result relation can
be the input for rusty 10
another relational ( (S2))
algebra operation! sname,rating rating 8
(Operator
Database Management Systems 3ed, R. Ramakrishnan and J. 8
Gehrke
Joins
Condition Join: R c S c (R
S)
Joins
Equi-Join: A special case of condition join
where the condition c contains only
equalities.
S1 sid R1
Result schema similar to cross-product, but
onlysidone sname
copy ofrating
fields for which equality
age bid day
is specified. Natural Join: Equijoin on all
22 dustin 7 45.0 10/10/9
common fields.
Database Management Systems 3ed, R. Ramakrishnan and 12
J. Gehrke
58 rusty 10 101 6
35.0 11/12/9
103 6
Examples of Division
A/B
sno pno pno pno pno
s1 p1 p2 p2 p1
s1 p2 p4 p2
B
s1 p3 p4
s1 p4
1 B2
s2 p1 sno B3
s2 p2 s1
s3 p2 s2 sno
s4 p2 s3 s1 sno
s4 p4 s4 s4 s1
.... / (
. bid bname ' Interlake'
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 20
Summary