Relational Model & Algebra
Subject: Database Systems
Master Relational Algebra, Relational Calculus (TRC & DRC), Joins, Division, Codd's Theorem, and Expressive Power.
Concept Summary
Key Revision Rules & Formulas
- 🔍 Selection (σ): Unary operator that filters rows based on a condition σ_p(R). Preserves schema, commutative σ_c1(σ_c2(R)) = σ_c2(σ_c1(R)), output cardinality ≤ |R|.
- ✂️ Projection (π): Unary operator that selects specific columns π_{A1,A2}(R). Automatically removes duplicate tuples because relations are mathematical sets. Not commutative.
- ➕ Set Operations (∪, -, ∩, ×): Union (∪), Difference (-), and Intersection (∩) require UNION COMPATIBILITY (same degree and domain-compatible attributes). Cartesian Product (×) combines degree: deg(R)+deg(S), cardinality: |R| * |S|.
- 🏷️ Renaming (ρ): Renames relation or attributes ρ_{X(A1..An)}(R) or ρ_{B ← A}(R). Essential for resolving attribute ambiguity in self-joins.
- 🔗 Joins (⋈, θ-join, Outer Joins): Natural Join (R ⋈ S) equates all common attributes and removes duplicate join columns. Inner/Theta Join is σ_θ(R × S). Outer Joins (⟕, ⟖, ⟗) preserve non-matching tuples padded with NULLs.
- ➗ Division (÷): Represents 'FOR ALL' queries. R(X,Y) ÷ S(Y) yields X values associated with ALL Y values in S. Formula: R ÷ S = π_X(R) - π_X((π_X(R) × S) - R).
- 🧮 Relational Calculus: Declarative (non-procedural). Tuple Relational Calculus (TRC: {t | P(t)}) and Domain Relational Calculus (DRC: {<x1..xn> | P(x1..xn)}). Uses quantifiers ∃ (existential) and ∀ (universal).
- ⚖️ Expressive Power & Codd's Theorem: Relational Algebra and Safe Relational Calculus (TRC/DRC) have EXACTLY EQUIVALENT expressive power. A language equal to RA is 'Relationally Complete'.
- 🛡️ Safe Calculus & Equivalence: A calculus expression is 'Safe' if it produces a finite result containing only values from the domain of the expression. Unsafe example: {t | ¬(t ∈ R)}.
- 🚫 Transitive Closure Limitation: Neither Basic Relational Algebra nor Relational Calculus can compute Transitive Closure (e.g., recursive reachability in ancestor graphs). Requires Extended RA (Datalog / WITH RECURSIVE).
Common Exam Pitfalls
- Mistake: Thinking Projection (π) allows duplicate rows in output. Standard Relational Algebra automatically eliminates duplicate rows.
- Mistake: Performing Union (∪), Intersection (∩), or Difference (-) on relations with different degrees or domain types. They MUST be Union Compatible.
- Mistake: Confusing Natural Join (R ⋈ S) with Cartesian Product (R × S). Natural Join automatically matches common attribute names and removes duplicate column outputs.
- Mistake: Writing unsafe relational calculus expressions like {t | ¬(t ∈ R)} which result in an infinite set of tuples.
- Mistake: Assuming Relational Algebra can evaluate recursive ancestor/descendant queries. Transitive closure requires recursive extensions like Datalog or SQL WITH RECURSIVE.
Sample Practice Questions
Question 1: Relational Algebra is a __________ query language that takes two relations as input and produces another relation as an output of the query.
- Relational
- Structural
- Procedural
- Fundamental
Explanation: This language has fundamental and other operations which are used on relations.
Question 2: Which of the following is a fundamental operation in relational algebra?
- Set intersection
- Natural join
- Assignment
- None of the mentioned
Explanation: The fundamental operations are select, project, union, set difference, Cartesian product, and rename.
Question 3: Which of the following is used to denote the selection operation in relational algebra?
- Pi (Greek)
- Sigma (Greek)
- Lambda (Greek)
- Omega (Greek)
Explanation: The select operation selects tuples that satisfy a given predicate.
Question 4: For select operation the ________ appear in the subscript and the ___________ argument appears in the paranthesis after the sigma.
- Predicates, relation
- Relation, Predicates
- Operation, Predicates
- Relation, Operation
Explanation: None.
Question 5: The ___________ operation, denoted by −, allows us to find tuples that are in one relation but are not in another.
- Union
- Set-difference
- Difference
- Intersection
Explanation: The expression r − s produces a relation containing those tuples in r but not in s.
Question 6: Which is a unary operation:
- Selection operation
- Primitive operation
- Projection operation
- Generalized selection
Explanation: Generalization Selection takes only one argument for operation.
Question 7: Which is a join condition contains an equality operator:
- Equijoins
- Cartesian
- Natural
- Left
Explanation: None.
Question 8: In precedence of set operators, the expression is evaluated from
- Left to left
- Left to right
- Right to left
- From user specification
Explanation: The expression is evaluated from left to right according to the precedence.
Question 9: Which of the following is not outer join?
- Left outer join
- Right outer join
- Full outer join
- All of the mentioned
Explanation: The FULL OUTER JOIN keyword combines the result of both LEFT and RIGHT joins.
Question 10: The assignment operator is denoted by
- ->
- <-
- =
- ==
Explanation: The result of the expression to the right of the ← is assigned to the relation variable on the left of the ←.