Reaves.dev

v0.1.0

built using

Phoenix v1.7.12

Relational Algebra And Calculus

Stephen M. Reaves

::

2023-06-16

Notes about Lesson 6 of CS-6400

Summary

Closed Algebra

Closed Algebra := A set of operations where the input operands and output operands are of the same type.

Operators

https://cs.brown.edu/courses/csci1270/website_2020/static/files/cs127_cheatsheet.pdf

RS R \cup S is a union.

RS R \cap S is an intersection.

RS R \setminus S is the set difference.

R×S R \times S is the Cartesian Product.

πA1,A2,,An(R) \pi A_1, A_2, \dots, A_n (R) is the projection (eliminating columns).

σexpression(R) \sigma _\text{expression} (R) is the selection (eliminating rows).

RS R * S or RS R \bowtie S is the natural join.

R÷S R \div S is divide by (universal quantification).

ρ[A1B1,,ANBN] \rho [A_1 B_1, \dots, A_N B_N] is the rename operator.

Selection Example

σexpression(R)=> \sigma _\text{expression} (R) => select all records from set R R that match expression expression .

σCurrentCity=HomeTownHomeTown=’Atlanta’(RegularUser) \sigma CurrentCity = HomeTown \lor HomeTown = \text{'Atlanta'} (RegularUser)

Relational Calculus

{tP(t)} {t | P(t)} := Set of tuples t that satisfy predicate P(t) P(t)

Predicates are built from atoms

Range Expression: tR or R(t) t \in R \text{ or } R(t) denote that t is a tuple of relation R.

Attribute Value: t.A denotes the value of t on attribute A t.A \text{ denotes the value of } t \text{ on attribute } A .

Constants are defined by c

Comparison operators: θ=,,,<,> \theta =, \neq \leq, \geq, <, >

Atoms := tR,r.Aθs.B,r.Aθc t \in R, r.A \theta s.B, r.A \theta c