












































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













































Lecture 14: More Relational Algebra
select joins: theta, equi, natural, outer union compatibility, and the set operations for relational algebra intermediate results and attribute renaming
SELECT enumber,fname,lname,dname FROM employee,department WHERE (dname=’Administration’ OR dname=’Finance’) AND dnumber=dno;
So far we have made sense of the SELECT ...FROM ... part of this query.
Each tuple in a relation gives a value to each index, or attribute name.
Each tuple in a relation gives a value to each index, or attribute name. So, expressions like dname=’Administration’ can be evaluated to true or false in the context of a tuple.
Each tuple in a relation gives a value to each index, or attribute name. So, expressions like dname=’Administration’ can be evaluated to true or false in the context of a tuple. Most of the domains we use are totally ordered, so we can also evaluate eg. dname < ’Administration’ or enumber ≥ 100 These atomic expressions can be combined in the obvious way using boolean connectives AND (∧, &), OR (∨) and NOT (¬, ∼)
Each tuple in a relation gives a value to each index, or attribute name. So, expressions like dname=’Administration’ can be evaluated to true or false in the context of a tuple. Most of the domains we use are totally ordered, so we can also evaluate eg. dname < ’Administration’ or enumber ≥ 100 These atomic expressions can be combined in the obvious way using boolean connectives AND (∧, &), OR (∨) and NOT (¬, ∼) Any such condition expression defines a function from the relation to {true, false}.
We use the condition expression to “filter” a relation, keeping only the tuples that evaluate to true.
Here’s the notation and definition:
σcond (R) = {t ∈ R | cond (t) = true}
Conjunction (and) is composition is intersection σc∧c′^ (R) = σc (σc′^ (R)) = σc′^ (σc (R)) = σc (R) ∩ σc′^ (R)
Conjunction (and) is composition is intersection σc∧c′^ (R) = σc (σc′^ (R)) = σc′^ (σc (R)) = σc (R) ∩ σc′^ (R) σc∨c′ (R) = σc (R) ∪ σc′ (R) σ¬c (R) = R − σc (R)
Conjunction (and) is composition is intersection σc∧c′^ (R) = σc (σc′^ (R)) = σc′^ (σc (R)) = σc (R) ∩ σc′^ (R) σc∨c′ (R) = σc (R) ∪ σc′ (R) σ¬c (R) = R − σc (R) |σc (R)| ≤ |R|
Conjunction (and) is composition is intersection σc∧c′^ (R) = σc (σc′^ (R)) = σc′^ (σc (R)) = σc (R) ∩ σc′^ (R) σc∨c′ (R) = σc (R) ∪ σc′ (R) σ¬c (R) = R − σc (R) |σc (R)| ≤ |R|
The left-hand sides might be faster to process, since they pass through the relation just once.
Conjunction (and) is composition is intersection σc∧c′^ (R) = σc (σc′^ (R)) = σc′^ (σc (R)) = σc (R) ∩ σc′^ (R) σc∨c′ (R) = σc (R) ∪ σc′ (R) σ¬c (R) = R − σc (R) |σc (R)| ≤ |R|
The left-hand sides might be faster to process, since they pass through the relation just once.
All depends on the access paths (index, hash) into the relation vs attributes used in query. The algebra gives us options to assess.
Joining two tables using product and selection is so common, we define a new operation for it.
A ⊲⊳a=b B ≡ σa=b(A × B)
Joining two tables using product and selection is so common, we define a new operation for it.
A ⊲⊳a=b B ≡ σa=b(A × B)
Using this, our query becomes
πfname,lname,dname( σdname=′Finance′∨dname=′Administration′ ( employee ⊲⊳dnum=dno department))