2.4Tuple and domain relational calculus
The idea
Relational calculus says what you want, not how to get it. Tuple calculus uses tuple variables; domain calculus uses attribute variables.
Think of it like this: Ordering from a menu ("a pizza with no mushrooms") versus giving the chef a recipe.
Why it exists
You must read a calculus expression and match it to an algebra query, and know that unsafe expressions are not allowed.
How it works
- { t | P(t) } returns all tuples t that make P true.
- ∃ means "there is a tuple such that"; ∀ means "for every tuple".
- "For all" queries use ∀ or a double negation (division).
- An expression is unsafe if its result can be infinite, e.g. { t | ¬R(t) }.
Worked example: Which operator expresses { t | R(t) ∧ ¬S(t) }?
R − S.
Now play with it
- →Read the table of equivalences row by row.
- →Think of why { t | ¬R(t) } has no finite answer.
| Operation | Relational algebra | Tuple relational calculus | Domain relational calculus |
|---|---|---|---|
| Selection | σ_A=5(R) | { t | R(t) ∧ t.A = 5 } | { <a, b> | R(a, b) ∧ a = 5 } |
| Projection | π_A(R) | { t | ∃r (R(r) ∧ t.A = r.A) } | { <a> | ∃b R(a, b) } |
| Union | R ∪ S | { t | R(t) ∨ S(t) } | { <a, b> | R(a, b) ∨ S(a, b) } |
| Difference | R − S | { t | R(t) ∧ ¬S(t) } | { <a, b> | R(a, b) ∧ ¬S(a, b) } |
| Division R ÷ S | π_A(R) − π_A((π_A(R) × S) − R) | { t | ∀s ∈ S ∃r ∈ R (r.A = t.A ∧ r.B = s.B) } | "for all" = ∀ over the divisor |
Unsafe: { t | ¬R(t) } returns every tuple not in R, an infinite set. Safe calculus is exactly as powerful as relational algebra.
Check yourself
Safe tuple relational calculus and relational algebra
Exam notes (the dense version)
Calculus is declarative: {t | P(t)} (tuple calculus) or {<x1, …, xk> | P} (domain calculus), with ∃ and ∀. Algebra and safe calculus have the same expressive power (Codd). An expression is unsafe if it can produce an infinite result, such as {t | ¬(t ∈ R)}. SQL is mostly based on tuple calculus.
Previous year questions: Relational Algebra & Calculus (12)
PYQs are grouped by topic, so this is the full set for Relational Algebra & Calculus; try the ones that match this subtopic. Open all 12 on the topic page.