relational Algebra- operators (Selection(σ),Projection(π),Union(∪),Difference (−),CartesianProduct(×),Join(𝔚), Intersection (∩),Rename (ρ)) | Relational Model and Relational Algebra | 2114112 Database Management System
Relational Algebra
A formal, procedural query language for the relational database model — the mathematical foundation behind SQL.
Relational algebra consists of operations that take one or two relations (tables) as input and produce a new relation as output. Because every operation returns a relation, operators can be nested and combined to build complex queries — exactly like SQL.
Core Operators at a Glance
Selection
Filters rows. Returns tuples that satisfy a Boolean condition. Think horizontal partition.
Projection
Filters columns. Keeps only selected attributes and auto-eliminates duplicates. Think vertical partition.
Rename
Renames elements. Changes a relation's name and/or its attribute names — essential for self-joins.
Union
Combines sets. All tuples from either relation (duplicates removed). Relations must be union-compatible.
Intersection
Finds commonalities. Only tuples appearing in both relations. Union-compatible required.
Difference
Subtracts sets. Tuples in R but not in S. Not commutative: R − S ≠ S − R.
Cartesian Product
Pairs everything. Every tuple of R paired with every tuple of S. Result has n×m rows.
Join
Matches records. Cartesian product + Selection condition. Only meaningful combinations survive.
Full Operator Reference
| Operator | Symbol | Category | Purpose & Description |
|---|---|---|---|
| Selection Unary | σ | Row Filter | Filters rows by a Boolean condition. The output has the same columns as the input but fewer rows. Supports =, <, ≤, >, ≥, ≠ and AND (∧), OR (∨), NOT (¬). |
| Projection Unary | π | Column Filter | Keeps only specified attributes; automatically eliminates duplicate tuples because a relation is a set. |
| Rename Unary | ρ | Metadata | Changes the name of a relation and/or its attributes. Critical for self-joins and managing intermediate results. |
| Union Set | ∪ | Combine | Returns all tuples from R or S or both. Requires union-compatibility (same degree and matching domains). Duplicates eliminated. |
| Intersection Set | ∩ | Common | Returns only tuples that appear in both R and S. Requires union-compatibility. |
| Difference Set | − | Subtract | Returns tuples in R but not in S. Requires union-compatibility. Non-commutative. |
| Cartesian Product Binary | × | Combine All | Pairs every tuple of R with every tuple of S. If R has n rows and m cols, S has x rows and y cols → result has n×x rows and m+y cols. |
| Join Binary | ⋈ | Match | Cartesian product followed by selection on a join condition. Eliminates non-matching tuples. Has multiple variants (Theta, Equijoin, Natural). |
1 — Unary Operations
These operators work on a single relation.
σ Selection (Sigma)
- Purpose: Filters rows based on a specified Boolean condition. Returns a subset of tuples that satisfy the expression.
- Visual metaphor: A horizontal cut through the table — keep some rows, discard others.
- Characteristics: The result has the same number of columns (degree) as the original. Condition can use comparison operators (=, <, ≤, >, ≥, ≠) and logical connectives AND (∧), OR (∨), NOT (¬).
π Projection (Pi)
- Purpose: Selects specific columns (attributes) from a relation and discards the rest.
- Visual metaphor: A vertical cut — keep some columns, drop others.
- Characteristics: Because a relation is mathematically a set, projection automatically eliminates duplicate tuples in its result.
ρ Rename (Rho)
- Purpose: Changes the name of a relation, the names of its attributes, or both.
- Characteristics: Indispensable for self-joins — lets you reference two copies of the same table with different names — and for managing intermediate query results.
2 — Set Theory Operations
∪ Union
- Purpose: Returns all tuples appearing in relation R, relation S, or both.
- Characteristics: Duplicate tuples are automatically eliminated. Commutative: R ∪ S = S ∪ R.
∩ Intersection
- Purpose: Returns only tuples present in both R and S.
- Characteristics: Commutative: R ∩ S = S ∩ R. Can be expressed using Difference: R ∩ S = R − (R − S).
− Difference (Minus)
- Purpose: Returns tuples in R that are not in S.
- Characteristics: Not commutative — R − S ≠ S − R. Useful for "find all X that don't have a Y" queries.
3 — Binary Relational Operations
× Cartesian Product (Cross Product)
- Purpose: Combines every tuple from R with every tuple from S.
- Size: If R has n rows & m cols, and S has x rows & y cols → result has n×x rows and m+y columns.
- Note: Does not require union-compatibility. On its own, generates many meaningless combinations; almost always followed by a Selection to filter meaningful pairs.
⋈ Join
- Purpose: Combines related tuples from two relations based on a matching condition. Tuples that don't satisfy the condition are discarded.
- Formally: A Join = Cartesian Product followed by a Selection condition.
| Variant | Symbol | Description |
|---|---|---|
| Theta Join | ⋈θ | Uses any comparison operator (≤, >, =, ≠, etc.) as the join condition. |
| Equijoin | ⋈= | A Theta Join where the condition uses only equality (=) comparisons. Produces duplicate join-attribute columns. |
| Natural Join | ⋈ or ∗ | Automatically joins on ALL attributes with the same name in both relations and removes redundant duplicate columns from the result. |
Comments
Post a Comment