G27
Self-checkedTier 1 9 min readdbms.relational-algebra

Relational algebra

The six basic operators of relational algebra (selection, projection, union, set difference, Cartesian product, rename), the derived operators (intersection, theta join, natural join), set semantics and union compatibility, evaluating expressions step by step on real relations, the bounds on the sizes of results, algebraic laws that always hold, and writing queries in algebra.

Why it exists

Relational algebra is the formal language in which queries are defined: a few operators that take relations and give relations. SQL is translated into it, and the optimiser rewrites it. GATE asks for the meaning of an expression on a given instance, for equivalent expressions, for the number of tuples a result can have, and for writing a query in algebra.

Prerequisites

You need relations as sets of tuples (relational model) and the set operations union, intersection, difference and product.

Precise definitions

All operators return relations, so they can be nested. Relations are sets: duplicates disappear automatically.

operatornotationresult
selectionσp(R)\sigma_{p}(R)the tuples of RR that satisfy the condition pp (comparisons of attributes and constants with =,≠,<,≤,>,≥=, \ne, <, \le, >, \ge, combined with ∧,∨,¬\wedge, \vee, \neg)
projectionπA1,…,Ak(R)\pi_{A_1, \ldots, A_k}(R)the listed attributes of every tuple of RR; duplicate tuples are removed
unionR∪SR \cup Stuples in RR or SS
differenceR−SR - Stuples in RR and not in SS
Cartesian productR×SR \times Severy tuple of RR concatenated with every tuple of SS (attribute names must differ)
renameρS(R)\rho_{S}(R), ρS(B1,…,Bn)(R)\rho_{S(B_1, \ldots, B_n)}(R)RR under a new name or with new attribute names
intersectionR∩S=R−(R−S)R \cap S = R - (R - S)tuples in both
theta joinR⋈θS=σθ(R×S)R \bowtie_{\theta} S = \sigma_{\theta}(R \times S)pairs that satisfy θ\theta
natural joinR⋈SR \bowtie Spairs that agree on all common attributes, with the common attributes kept once

Union compatibility. R∪SR \cup S, R∩SR \cap S and R−SR - S require the same number of attributes with compatible domains (in practice the same attribute list). The result takes the attribute names of the first operand.

The first six operators (σ, π, ∪, −, ×, ρ) are complete for the basic algebra: intersection and joins are derived from them. Selection, projection, union, difference and product are all needed: none can be expressed with the others (textbook statement, quoted; rename only gives names).

How it works

Selection and projection

Selection and projection: start

Computed, not typed
Student
Student4 tuples
sidsnamedept
1AshaCS
2BilalEE
3ChenCS
4DaraME

Step 0

The relation Student has three attributes and four tuples. A relation is a SET of tuples: no order, no duplicates.

0 / 3
computed by script: relational operators are evaluated by scripts/db_lib.py (and cross-checked against SQLite), one step at a time. python3 scripts/gen-db1-traces.py

Selection keeps whole tuples and does not change the attributes; projection keeps all tuples (up to duplicates) but changes the attributes. πdept(Student)\pi_{\text{dept}}(\text{Student}) has three tuples although Student has four, because the two CS students give the same value.

Selection can be cascaded and its conditions commute: σp∧q(R)=σp(σq(R))=σq(σp(R))\sigma_{p \wedge q}(R) = \sigma_p(\sigma_q(R)) = \sigma_q(\sigma_p(R)). Projections cascade only downwards: πA(πA,B(R))=πA(R)\pi_{A}(\pi_{A, B}(R)) = \pi_A(R).

Natural join

The natural join of Student, Enrolled and Course answers "who attends which course":

Natural joins: start

Computed, not typed
Student, Enrolled, Course
Student4 tuples
sidsnamedept
1AshaCS
2BilalEE
3ChenCS
4DaraME
Enrolled5 tuples
sidcidgrade
1C1A
1C2B
2C1B
3C2A
3C3A
Course4 tuples
cidtitlecredits
C1DB4
C2OS3
C3CN3
C4AI3

Step 0

Three relations. Student and Enrolled share the attribute sid, Enrolled and Course share cid.

0 / 3
computed by script: relational operators are evaluated by scripts/db_lib.py (and cross-checked against SQLite), one step at a time. python3 scripts/gen-db1-traces.py

πsname,title((Student⋈Enrolled)⋈Course)\pi_{\text{sname}, \text{title}}((\text{Student} \bowtie \text{Enrolled}) \bowtie \text{Course}). Dara (no enrolment) and the course C4 (no student) disappear: the inner join keeps only matching tuples. Natural join is commutative and associative, so the order of the three relations does not change the result (the order matters for cost, see the next page). If RR and SS have no attribute in common, R⋈S=R×SR \bowtie S = R \times S; if they have the same attributes, R⋈S=R∩SR \bowtie S = R \cap S.

Set operations

Union, intersection and difference: start

Computed, not typed
A = π sid (σ dept='CS' (Student)), B = π sid (σ cid='C2' (Enrolled))
A2 tuples
sid
1
3
B2 tuples
sid
1
3

Step 0

Two union-compatible relations (same attributes, same domains): A = students of the CS department, B = students enrolled in C2.

0 / 4
computed by script: relational operators are evaluated by scripts/db_lib.py (and cross-checked against SQLite), one step at a time. python3 scripts/gen-db1-traces.py

With AA = sid of CS students and BB = sid of students enrolled in C2: A∪BA \cup B lists both, A∩BA \cap B the students in both groups, A−BA - B the CS students who are not enrolled in C2. Difference is the only way to express "not": students who took no course is πsid(Student)−πsid(Enrolled)\pi_{\text{sid}}(\text{Student}) - \pi_{\text{sid}}(\text{Enrolled}).

Sizes of results

Let ∣R∣=r|R| = r and ∣S∣=s|S| = s.

expressionnumber of tuples
σp(R)\sigma_p(R)between 00 and rr
πA(R)\pi_A(R)between 11 (if r≥1r \ge 1) and rr (equal to rr if AA contains a key)
R∪SR \cup Sbetween max⁡(r,s)\max(r, s) and r+sr + s
R∩SR \cap Sbetween 00 and min⁡(r,s)\min(r, s)
R−SR - Sbetween max⁡(0,r−s)\max(0, r - s) and rr
R×SR \times Sexactly r⋅sr \cdot s
R⋈SR \bowtie S (common attributes)between 00 and r⋅sr \cdot s
R⋈SR \bowtie S when the common attributes are a key of SS and a non-null foreign key of RRexactly rr

The bounds hold on 500 random instances, and the extreme join sizes are attained: no matching value gives 00; all tuples of RR and SS with one common value give r⋅sr \cdot s (5⋅4=205 \cdot 4 = 20 in the test); a foreign key into a key gives rr (55).

Algebraic laws that hold (and some that do not)

Always true: R∪S=S∪RR \cup S = S \cup R, R∩S=R−(R−S)R \cap S = R - (R - S), (R−S)∪(R∩S)=R(R - S) \cup (R \cap S) = R, R⋈S=S⋈RR \bowtie S = S \bowtie R, σp(R∪S)=σp(R)∪σp(S)\sigma_p(R \cup S) = \sigma_p(R) \cup \sigma_p(S), σp(R−S)=σp(R)−σp(S)\sigma_p(R - S) = \sigma_p(R) - \sigma_p(S), and, if pp uses attributes of RR only, σp(R⋈S)=σp(R)⋈S\sigma_p(R \bowtie S) = \sigma_p(R) \bowtie S.

Not true in general: R−S≠S−RR - S \ne S - R; πA(R−S)≠πA(R)−πA(S)\pi_A(R - S) \ne \pi_A(R) - \pi_A(S); πA(R∩S)≠πA(R)∩πA(S)\pi_A(R \cap S) \ne \pi_A(R) \cap \pi_A(S) (the left side is contained in the right side). Example: R={(1,1),(1,2)}R = \{(1, 1), (1, 2)\}, S={(1,1)}S = \{(1, 1)\}: πa(R−S)={1}\pi_a(R - S) = \{1\} but πa(R)−πa(S)=∅\pi_a(R) - \pi_a(S) = \emptyset.

Writing queries

  • Students who took C1 and C2: πsid(σcid=C1(Enrolled))∩πsid(σcid=C2(Enrolled))\pi_{\text{sid}}(\sigma_{\text{cid}=C1}(\text{Enrolled})) \cap \pi_{\text{sid}}(\sigma_{\text{cid}=C2}(\text{Enrolled})) (an intersection; "or" would be a union or a disjunction in σ).
  • Names of students who took no course: πsname(Student⋈(πsid(Student)−πsid(Enrolled)))\pi_{\text{sname}}(\text{Student} \bowtie (\pi_{\text{sid}}(\text{Student}) - \pi_{\text{sid}}(\text{Enrolled}))).
  • Courses with more than 3 credits: πtitle(σcredits>3(Course))\pi_{\text{title}}(\sigma_{\text{credits}>3}(\text{Course})).
  • "Two different courses" needs rename: πsid(σcid≠cid′(Enrolled⋈ρ(sid,cid′,grade′)(Enrolled)))\pi_{\text{sid}}(\sigma_{\text{cid} \ne \text{cid}'}(\text{Enrolled} \bowtie \rho_{(\text{sid}, \text{cid}', \text{grade}')}(\text{Enrolled}))).

Worked examples

EX 1Evaluate on an instance

Easy

σdept=CS(Student)\sigma_{\text{dept}=\text{CS}}(\text{Student}) has 22 tuples (Asha, Chen); πsname\pi_{\text{sname}} of that gives {Asha, Chen}. πdept(Student)\pi_{\text{dept}}(\text{Student}) has 33 tuples (CS, EE, ME).

EX 2Cardinalities

Easy

∣R∣=20|R| = 20, ∣S∣=30|S| = 30. R×SR \times S: 600600. R∪SR \cup S: between 3030 and 5050. R∩SR \cap S: at most 2020. R−SR - S: between 00 and 2020. A natural join: between 00 and 600600.

EX 3Maximum and minimum of a join

Medium

R(A,B)R(A, B) with ∣R∣=100|R| = 100 and S(B,C)S(B, C) with ∣S∣=50|S| = 50, join on BB. Minimum: 00 (no common BB value). Maximum: 50005000 (all tuples have the same BB). If BB is the key of SS and a foreign key of RR (no NULLs): exactly 100100. If BB is the key of RR only: at most ∣S∣=50|S| = 50.

EX 4Are these equivalent

Medium

σp(R−S)≡σp(R)−σp(S)\sigma_{p}(R - S) \equiv \sigma_p(R) - \sigma_p(S): yes (also σp(R)−S\sigma_p(R) - S). πa(R−S)≡πa(R)−πa(S)\pi_a(R - S) \equiv \pi_a(R) - \pi_a(S): no (witness above). πa(R∪S)≡πa(R)∪πa(S)\pi_a(R \cup S) \equiv \pi_a(R) \cup \pi_a(S): yes. σp(R×S)≡σp(R)×S\sigma_{p}(R \times S) \equiv \sigma_p(R) \times S when pp mentions only attributes of RR: yes.

EX 5Typical questions

GATE level

(a) "Which operators are needed to express 'students who did not take C1'?" difference (or an equivalent with ∖). (b) "How many tuples can R⋈SR \bowtie S have at most?" ∣R∣⋅∣S∣|R| \cdot |S|. (c) "Which of the following are union-compatible?" Same number of attributes with the same domains. (d) "σA=1(σA=2(R))\sigma_{A=1}(\sigma_{A=2}(R)) is:" empty. (e) "πA(σp(R))\pi_A(\sigma_{p}(R)) and σp(πA(R))\sigma_p(\pi_A(R)) are equal when:" pp uses attributes in AA only. (f) "Is selection commutative with projection?" only when the selection's attributes are all kept by the projection.

Cheat box

Cheat box

  • Basic operators: σ\sigma, π\pi, ∪\cup, −-, ×\times, ρ\rho. Derived: ∩\cap, ⋈\bowtie.
  • Relations are sets: projection removes duplicates. Union-compatibility needed for ∪,∩,−\cup, \cap, -.
  • ∣R×S∣=rs|R \times S| = rs; ∣R∪S∣∈[max⁡,r+s]|R \cup S| \in [\max, r + s]; ∣R∩S∣≤min⁡|R \cap S| \le \min; ∣R−S∣∈[max⁡(0,r−s),r]|R - S| \in [\max(0, r - s), r]; join in [0,rs][0, rs]; foreign key into key: rr.
  • σp∧q=σpσq\sigma_{p \wedge q} = \sigma_p \sigma_q, σp(R⋈S)=σp(R)⋈S\sigma_p(R \bowtie S) = \sigma_p(R) \bowtie S for pp on RR; πA(R−S)≠πA(R)−πA(S)\pi_A(R - S) \ne \pi_A(R) - \pi_A(S).
  • "Not" needs difference; "for some" is a join/projection; "for all" is division.

Traps and GATE patterns

Connections

The operators are implemented by SQL (SQL basics); joins in depth, division and the optimisation of expression trees follow (advanced algebra); calculus is the declarative twin of algebra (tuple relational calculus).

PYQs

17 previous year questions from your book. I re-solved each one myself (10 by running or simulating, 7 by reasoning only); the book's key is shown next to my answer. All PYQs

GATE 2026 · Set 1 · MCQ · 2 marksQ1 · page 388 of the book
Consider a relational database schema with two
relations R(P, Q) and S(X, Y)
Let E= {⟨u⟩|∃v∃w⟨u, v⟩∈R∧⟨v, w⟩∈S} be a
tuple relational calculus expression.
Which one of the following relational algebraic
expressions is equivalent to E ?
  • (a)ΠP(R⋈R.P=S.XS)
  • (b)ΠP(S⋈S.X=R.QR)
  • (c)ΠP(R⋈R.P=S.YS)
  • (d)ΠP(S⋈S.Y=R.QR)
GATE 2024 · Set 1 · NAT · 1 markQ3 · page 388 of the book
Consider the following two relations, R(A,B) and
S(A,C):

R
A
B
10
20
20
30
30
40
30
50
50
95

S
A
C
10
90
30
45
40
80
The total number of tuples obtained by evaluating the
following expression
σB<C(R⋈R.A=S.A S) is ___________.
year not read yetQ5 · page 389 of the book
The following relation records the age of 500 employees
of a company, where empNo (indicating the employee
number) is the key :

 empAge(empNo,age)

 Consider the following relational algebra expression
                   Πemp×No(empAge⋈(age>age1) ρempNo1,aye1(empAge))
 What does the above expression generate?
  • (a)Employee numbers of all employees whose age is not the minimum.
  • (b)Employee numbers of all employees whose age is the minimum.
  • (c)Employee numbers of all employees whose age is more than the age of exactly one other employee.
  • (d)Employee numbers of only those employees whose age is the maximum.
GATE 2019 · NAT · 2 marksQ8 · page 389 of the book
Consider the following relations P(X, Y, Z), Q(X, Y, T)
and R(Y, V).

Table : P

X
Y
Z
X1
Y1
Z1
X1
Y1
Z2
X2
Y2
Z2
X2
Y4
Z4

Table : Q

X
Y
T
X2
Y1
2
X1
Y2
5
X1
Y1
6
X3
Y3
1

Table : R
Y
V
Y1
V1
Y3
V2
Y2
V3
Y2
V2

How many tuples will be returned by the following
relational algebra query?
πx(σ(P.Y = R.Y ∧ R.V = V2(P X R))) - πx(σ(Q.Y = R.Y ∧ Q.T > 2(Q X
R)))
GATE 2014 · Set 3 · MCQQ16 · page 391 of the book
What is the optimized version of the relation algebra
expression  πA1(πA2(σF1(σF2(r)))), where A1, A2 are sets of
attributes in r with A1 ⊂ A2 and F1, F2 are Boolean
expressions based on the attributes in r?
  • (a)πA1(σ(F1∧F2)(r))
  • (b)πA1(σ(F1∨F2)(r))
  • (c)πA2(σ(F1∧F2)(r))
  • (d)πA2(σ(F1∨F2)(r))
GATE 2013 · MCQ · 2 marksQ17 · page 391 of the book
Consider the following relation schema

Students(rollno:integer, sname: string)

Courses(courseno:integer,cname: string)

Registration (rollno: integer, courseno: integer, percent:
real)

Which of the following queries are equivalent to this query
in English?

"Find the distinct names of all students who score more
than 90% in the course numbered 107".

(I)  SELECT DISTINCT S.sname

FROM Students as S, Registration as R

WHERE R.rollno = S. rollno AND R.courseno = 107 AND
R.percent> 90

(II) πsname(σcourseno= 107 Λ percent> 90 (Registration ⋈Students))

(III) {T|∃S ε Students, ∃R ε Registration (S.rollno =
R.rollno Λ R.courseno = 107 Λ R.percent> 90 Λ T.sname
= S.sname)}

(IV) {<SN>|∃SR∃RP(<SR,SN>∈Students∧<SR,107,RP>∈
Registration∧ RP>90)}
  • (a)I, II, III and IV
  • (b)I, II and III only
  • (c)I, II and IV only
  • (d)II, III and IV only
GATE 2012 · MCQ · 2 marksQ18 · page 391 of the book
Suppose R1(A, B) and R2(C, D) are two relation schemas.
Let r1 and r2 be the corresponding relation instances. B is a
foreign key that refers to C in R2. If data in r1 and r2 satisfy
referential integrity constraints, which of the following is
ALWAYS TRUE?

DATABASE MANAGEMENT  SYSTEM
  • (a)ΠB(r1) – Πc(r2) = ∅
  • (b)ΠC(r2) – ΠB(r1) = ∅
  • (c)ΠB(r1) = Πc(r2)
  • (d)ΠB(r1) – Πc(r2) ≠ ∅
GATE 2010 · MCQ · 2 marksQ20 · page 392 of the book
The following functional dependencies hold for
relations R(A, B, C) and S(B, D, E):

B -> A , A -> C

The relation R contains 200 tuples and the relation S
contains 100 tuples. What is the maximum number of
tuples possible in the natural join of R and S (R ⋈S) ?
  • (a)100
  • (b)200
  • (c)300
  • (d)2000
GATE 2008 · MCQ · 2 marksQ22 · page 392 of the book
Let R and S be two relations with the following schema:
R(P, Q, R1, R2, R3)
S(P, Q, S1, S2)
where {P, Q} is the key for both schemas. Which of the
following queries are equivalent?

1. ΠP(R⋈S)
II. ΠP(R) ⋈ΠP(S)
III. ΠP(ΠP,Q(R) ∩ΠP,Q(S))
IV. ΠP(ΠP,Q(R) -(ΠP,Q(R) -ΠP,Q(S)))
  • (a)Only I and II
  • (b)Only I and III
  • (c)Only I, II and III
  • (d)Only I, III and IV
GATE 2007 · MCQQ27 · page 393 of the book
Consider a selection of the form σA ≤ 100(r), where r is a
relation with 1000 tuples. Assume that the attribute values
for A among the tuples are uniformly distributed in the
interval [0, 500]. Which one of the following options is
the best estimate of the number of tuples returned by the
given selection query?
  • (a)50
  • (b)100
  • (c)150
  • (d)200
GATE 2007 · MCQ · 2 marksQ28 · page 393 of the book
Consider the following relation schemas :
 b -Schema = (b-name, b -city, assets)
 a-Schema = (a-num, b-name, bal)
 d-Schema = (c-name, a-number)
Let branch, account and depositor be respectively
instances of the above schemas. Assume that
account and depositor relations are much bigger
than the branch relation.
Consider the following query:
Πc-name (σb-city = "Agra" ∧ bal < 0 (branch ⋈
(account ⋈ depositor)
Which one of the following queries is the most
efficient version of the above query?
  • (a). Πc-name (σbal <0(σb-city = "Agra" branch ⋈ account ) ⋈ depositor )
  • (b). Πc-name (σb-city = "Agra" branch ⋈(σbal<0 account ⋈ depositor))
  • (c). Πc-name ((σb-city = "Agra" branch ⋈σb-city = "Agra" ∧ bal < 0 account ) ⋈ depositor )
  • (d). Πc-name (σb-city = "Agra" branch ⋈(σb-city = "Agra" ∧ bal < 0 account ⋈ depositor )) DATABASE MANAGEMENT SYSTEM
GATE 2006 · MCQQ29 · page 394 of the book
Consider the relations r1(P, Q, R) and r2(R, S, T) with
primary keys P and R respectively. The relation r1
contains 2000 tuples and r2 contains 2500 tuples. The
maximum size of the join r1⋈ r2 is :
  • (a)2000
  • (b)2500
  • (c)4500
  • (d)5000
GATE 2005 · MCQ · 1 markQ31 · page 394 of the book
Let r be a relation instance with schema R = (A, B, C,
D). We define
r1 = πA,B,C (r) and r2 = πA,D (r).
Let s = r1 ⋈ r2, where ⋈ denotes natural join. Given
that the decomposition of r into r1 and r2 is lossy,
which one of the following is TRUE?
  • (a)s ⊂ r
  • (b)r ∪ s = r
  • (c)r ⊂ s
  • (d)r ⋈ s = s
GATE 2024 · Set 2 · NAT · 2 marksQ3 · page 400 of the book
The relation schema Person (pid, city) describes
the city of residence for every person uniquely
identified by pid. The following relational
algebra operators are available: selection,
projection, cross product, and rename.
 To find the list of cities where at least 3 persons
reside, using the above operators, the minimum
number of cross product operations that must be
used is:
  • (a)1
  • (b)2
  • (c)3
  • (d)4 DATABASE MANAGEMENT SYSTEM
GATE 2012 · MCQQ20 · page 406 of the book
Consider the following relations A, B and C:

A
ID,
Name,
Age
12
Arun
60
15
Shreya
24
99
Rohit
11

B
ID,
Name,
Age
15
Shreya
24
25
Hari
40
98
Rohit
20
99
Rohit
11

C
ID,
Phone,
Area
10
2200
02
99
2100
01

How many tuples does the result of the following
relational algebra expression contain?
Assume that the schema of A ∪ B is the same as
that of A.
(A ∪ B) ⋈A.ID > 40 ∨ C.ID < 15 C
  • (a)7
  • (b)4
  • (c)5
  • (d)9
GATE 2006 · MCQ · 2 marksQ28 · page 408 of the book
Consider the relation enrolled(student, course) in which
(student, course) is the primary key, and the relation
paid(student, amount), where student is the primary
key. Assume no null values and no foreign keys or
integrity constraints. Assume that amounts 6000, 7000,
8000, 9000 and 10000 were each paid by 20% of the
students. Consider these query plans (Plan 1 on left,
Plan 2 on right) to "list all courses taken by students
who have paid more than x".

A disk seek takes 4ms, disk data transfer bandwidth is
300 MB/s and checking a tuple to see if amount is greater
than x takes 10 micro-seconds. Which of the following
statements is correct?
  • (a)Plan 1 and Plan 2 will not output identical row sets for all databases.
  • (b)A course may be listed more than once in the output of Plan 1 for some databases
  • (c)For x = 5000, Plan 1 executes faster than Plan 2 for all databases.
  • (d)For x = 9000, Plan I executes slower than Plan 2 for all databases.
GATE 2005 · 2 marksQ34 · page 411 of the book
A table 'student' with schema (roll, name, hostel,
marks), and another table 'hobby' with schema (roll,
hobbyname) contains records as shown below:

The following SQL query is executed on the above
tables:

select hostel

from student natural join hobbywhere marks > = 75 and
roll between 2000 and 3000;

Relations S and H with the same schema as those of
these two tables respectively contain the same
information as tuples. A new relation S' is obtained by
the following relational algebra operation:

S' = ∏Hostel ((σ s.roll = H.roll(σmarks > 75 and roll > 2000 and roll <
3000  (S)) X (H))

The difference between the number of rows output by
the SQL statement and the number of tuples in S' is .
  • (a)6
  • (b)4
  • (c)2
  • (d)0

Self-check

Question 1

RR has 1010 tuples and SS has 44. What are the smallest and largest sizes of R∪SR \cup S and of R−SR - S?

Show answer

R∪SR \cup S: 1010 to 1414. R−SR - S: 66 to 1010.

Question 2

Write in algebra: students enrolled in C1 but not in C2.

Show answer

πsid(σcid=C1(Enrolled))−πsid(σcid=C2(Enrolled))\pi_{\text{sid}}(\sigma_{\text{cid}=C1}(\text{Enrolled})) - \pi_{\text{sid}}(\sigma_{\text{cid}=C2}(\text{Enrolled})).

Question 3

Is πA(R∩S)=πA(R)∩πA(S)\pi_A(R \cap S) = \pi_A(R) \cap \pi_A(S)?

Show answer

No: the left side is contained in the right side; e.g. R={(1,1)}R = \{(1, 1)\}, S={(1,2)}S = \{(1, 2)\} with AA the first attribute.

Question 4

What is the natural join of two relations with no common attribute?

Show answer

Their Cartesian product.

Revision card

One-screen revision

  • σ\sigma, π\pi, ∪\cup, −-, ×\times, ρ\rho; ∩\cap, ⋈\bowtie derived; set semantics.
  • Result sizes: product rsrs, union [max⁡,r+s][\max, r+s], difference [max⁡(0,r−s),r][\max(0,r-s), r], join [0,rs][0, rs].
  • Laws: selection cascade, push-down through a join; projection does not distribute over difference or intersection.
  • NULL never matches; "not" is difference.

References

  • ·Silberschatz, Korth, Sudarshan, Database System Concepts (7th edition), Chapter 2, Sections 2.5 and 2.6 (relational algebra)
  • ·Elmasri, Navathe, Fundamentals of Database Systems (7th edition), Chapter 8 (the relational algebra and relational calculus)

Verification

scripts/enum-checks/db_algebra.py: every operator implemented in scripts/db_lib.py (selection, projection, union, intersection, difference, product, natural join, theta join, left/right/full outer join, semijoin, grouping, division) equals the corresponding SQL query executed by SQLite on random relations (300 pairs including NULLs where SQL agrees, 200 more without NULLs); the laws on this page (selection cascade and commutation, projection cascade, union and join commutativity and associativity, intersection as double difference, selection push-down through a join, join as selection over a product, idempotence of the self natural join) hold on 300 random instances; the size bounds of each operator hold on 500 random instances, and the extreme join sizes (0, |R||S| and |R|) were constructed; the animations were recomputed with SQLite. The result of a query is a SET in the algebra (duplicates disappear); SQL's SELECT without DISTINCT would keep them. Textbook chapter references are from memory. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and re-derived against the textbook definitions and the sample database. No defect found. Status raised to self-checked; verified needs a textbook or human check.

last verified: never