Relational Algebra, Tuple Calculus & The Division Operator
“Selection, projection, joins, division, and output cardinality bounds.”
1.Why Mathematics Governs SQL
§ 3.1.SQL is a declarative language: you write WHAT data you want, not HOW to retrieve it. To optimize and execute your query, the database query engine translates SQL into Relational Algebra expressions.
Relational Algebra is a procedural query language where queries are composed of algebraic operators applied to relations, producing new relations as results. Because relations are formal mathematical sets of tuples, Relational Algebra provides the mathematical guarantee of closure (the output of any operation is itself a relation), enabling arbitrary nesting and algebraic optimization.
2.Fundamental & Derived Relational Operators
§ 3.2.The 5 Primitive Operators:
1. Selection (σ_p(R)): Filters rows satisfying predicate p. Preserves degree (number of columns); reduces cardinality (number of rows).
2. Projection (π_{A1, A2}(R)): Extracts specified columns and eliminates duplicate rows. Reduces degree; preserves or reduces cardinality.
3. Cartesian Product (R × S): Pairs every tuple of R with every tuple of S. Degree = deg(R) + deg(S); Cardinality = |R| × |S|.
4. Set Union (R ∪ S): Combines tuples from union-compatible relations (same degree and domain-compatible attributes).
5. Set Difference (R - S): Returns tuples present in R but absent in S.
High-Yield Derived Operators:
• Natural Join (R ⋈ S): Cartesian product followed by equality selection on all common attribute names, projecting out duplicate column names.
• Theta Join (R ⋈_θ S): σ_θ(R × S).
• Division Operator (R ÷ S): Answers queries involving the universal quantifier 'FOR ALL' (e.g., 'Find students who enrolled in all courses taught by Dr. Rao').
3. GATE Classic: Join Output Cardinality Bounds
| Case 1B is Primary Key of S and Foreign Key in R | Case 2B is Primary Key of both R and S | Case 3General case: B is not a key in either relation |
Because B is a foreign key in R referencing S, every tuple in R must match exactly one tuple in S (referential integrity). Therefore, every one of the m tuples in R finds exactly one match.
If B is unique in both tables, each value can match at most once. In the best case, all keys match (min(m, n)). In the worst case, the key sets are completely disjoint.
If all m tuples in R have value B='x' and all n tuples in S have value B='x', every tuple in R matches every tuple in S. If the sets of B values are disjoint, zero tuples match.
4. Relational Algebra Concept Verification
Test your mastery of relational operators and join semantics.
Which relational algebra operator is equivalent to the SQL query: 'SELECT DISTINCT A FROM R WHERE A NOT IN (SELECT A FROM S)'?
5. 1-Minute Relational Algebra Revision Anchors
“Selection filters rows; Projection extracts columns; Cartesian Product multiplies cardinalities; Division answers FOR ALL queries.”
- •deg(R × S) = deg(R) + deg(S); card(R × S) = |R| × |S|.
- •Natural Join R(m) ⋈ S(n) with FK = exactly m tuples.
- •General Natural Join R(m) ⋈ S(n) bounds = [0, m × n].
- •Division R(A, B) ÷ S(B) yields tuples in A associated with EVERY tuple in S.
- •Projection removes duplicates in pure relational algebra; SQL SELECT does NOT unless DISTINCT is specified.
- •Natural join on disjoint sets of common attribute values yields an empty relation.
Primary Academic References & Exam Sources
Every concept in Notes From a B.Tech Brain is synthesized from authoritative academic texts, seminal peer-reviewed research, verified exam archives, and renowned university lectures.
Turing Award-winning paper establishing relational algebra operators.
Rigorous treatment of fundamental and derived relational operators.
Curated for clarity, rigorous numerical solving, and semester excellence:
GATE-focused numerical problem-solving with clear worked examples.
Fast conceptual coverage with step-by-step GATE numericals.
Systematic textbook-style explanations ideal for first-time learners.
Deep theoretical rigor on normalization and transaction serializability.