「‍」 Lingenic

Relational Algebra

(⤓.md ◇.md); γ ≜ [2026-07-17T120407.600, 2026-07-17T135416.643] ∧ |γ| = 3

Relational Algebra

Origin. Edgar F. Codd introduced the relational model and relational algebra (1970) at IBM. Provided a mathematical foundation for database systems, replacing navigational models (hierarchical, network) with declarative queries. Basis for SQL. Turing Award 1981.

Models. Data as relations (tables). Queries as algebraic operations on relations. A relation is a set of tuples; operations combine relations to produce new relations. The algebra is closed: every operation takes relations in, produces a relation out. Core question: how to express and optimize data retrieval?

Formalism.

Relations: A relation R on attributes A₁, ..., Aₙ is a subset of dom(A₁) × ... × dom(Aₙ). Each row (tuple) assigns values to attributes. Relations are sets: no duplicate rows, order doesn't matter.

Primitive operations:

  • Selection (σ): σ_condition(R) — filter rows satisfying condition σ_{age>30}(Employees) — employees older than 30
  • Projection (π): π_attributes(R) — select columns π_{name,salary}(Employees) — just name and salary
  • Cartesian product (×): R × S — all combinations of rows
  • Union (∪): R ∪ S — rows in R or S (requires same schema)
  • Difference (−): R − S — rows in R but not S
  • Rename (ρ): ρ_{new←old}(R) — rename attributes

Derived operations:

  • Join (⋈): R ⋈_condition S — cross product filtered by condition
  • Natural join (⋈): R ⋈ S — join on common attribute names, no duplicates
  • Intersection (∩): R ∩ S = R − (R − S)
  • Division (÷): R ÷ S — tuples in R matching all tuples in S

Extended operations (for practical SQL):

  • Aggregation: sum, count, avg, min, max
  • Grouping: γ_{group-attrs, agg}(R)
  • Outer joins: preserve unmatched rows with nulls

Symbols.

SymbolUnicodeNameMeaning
σU+03C3SelectionFilter rows
πU+03C0ProjectionSelect columns
×U+00D7Cartesian productAll row combinations
U+222AUnionSet union of rows
U+2212DifferenceSet difference
U+2229IntersectionCommon rows
U+22C8JoinCombine matching rows
ρU+03C1RenameRename attributes
÷U+00F7Division"For all" query pattern
γU+03B3GroupingGroup and aggregate
U+27D5Left outer joinPreserve left rows
U+27D6Right outer joinPreserve right rows
U+27D7Full outer joinPreserve all rows

Metatheory. Relational algebra is equivalent in expressive power to domain relational calculus and tuple relational calculus (Codd's theorem). All are captured by first-order logic over finite structures. Relational algebra is not Turing-complete: cannot express transitive closure (reachability) without recursion. Datalog extends with recursion. Query optimization: algebraic identities enable rewriting queries to equivalent but more efficient forms (push selections down, reorder joins).

Applies to. Database query languages (SQL is based on relational algebra). Query optimization. Data integration. Formal specification of data operations. Theoretical foundations of databases.

Limitations. Cannot express recursive queries (transitive closure, bill of materials) without extensions. No built-in support for nulls, which SQL adds with three-valued logic. Set semantics differs from SQL's bag (multiset) semantics in practice. Real databases have indexes, transactions, constraints — relational algebra is the query core, not the whole system. Schema evolution and data integrity constraints are outside the algebra. Performance depends on physical implementation, not algebraic form.

© 2026 Lingenic LLC