∑GATE DA Atlas

The Relational Model and Relational Algebra

Relations, tuples, attributes and domains, schema vs instance, superkeys, candidate, primary and foreign keys, and the relational algebra — selection, projection, set operations, Cartesian product, renaming, joins (theta, equi, natural, outer), intersection and division — with set semantics, result-size bounds, algebraic equivalences and query trees.

Section 510 practice questions

Relations

A relation is a set of tuples (rows) over a fixed list of attributes (columns), each attribute taking values from a domain.

  • Schema: Student(sid, name, dept, cgpa) — the structure. Instance: the current set of tuples.
  • Degree (arity) = number of attributes; cardinality = number of tuples.
  • Relations are sets: no duplicate tuples and no inherent order of rows. (SQL tables are bags — duplicates allowed.)
  • Values are atomic (first normal form).

Keys

KeyDefinition
Superkeya set of attributes whose values uniquely identify each tuple
Candidate keya minimal superkey (no proper subset is a superkey)
Primary keythe candidate key chosen to identify tuples; cannot be NULL
Alternate keya candidate key not chosen as primary
Foreign keyattributes referencing the primary key of another (or the same) relation

A relation with nn attributes has at most 2n−12^n - 1 superkeys. If {A}\{A\} is a candidate key of R(A,B,C)R(A, B, C), every superset of {A}\{A\} is a superkey: 2n−1=42^{n-1} = 4 superkeys.

Relational algebra

A procedural query language: each operator takes relations and returns a relation, so operators compose.

OperatorNotationResult
Selectionσcond(R)\sigma_{\text{cond}}(R)rows satisfying the condition
ProjectionπA1,…,Ak(R)\pi_{A_1,\dots,A_k}(R)chosen columns, duplicates removed
UnionR∪SR \cup Stuples in either (schemas must be union-compatible)
DifferenceR−SR - Stuples in RR not in SS
IntersectionR∩SR \cap Stuples in both
Cartesian productR×SR \times Sall pairs; ∣R∣⋅∣S∣\lvert R\rvert\cdot\lvert S\rvert tuples
RenameρT(B1,… )(R)\rho_{T(B_1,\dots)}(R)same tuples, new names
Theta joinR⋈θS=σθ(R×S)R \bowtie_\theta S = \sigma_\theta(R \times S)pairs satisfying θ\theta
Equi-jointheta join with only equality conditions
Natural joinR⋈SR \bowtie Sequi-join on all common attributes, common columns kept once
Outer joins⟕, ⟖, ⟗join plus unmatched tuples padded with NULL
DivisionR÷SR \div Svalues of RR's other attributes paired with all of SS
Semi-joinR⋉SR \ltimes Stuples of RR that have a match in SS

Size bounds

ExpressionMin tuplesMax tuples
σ(R)\sigma(R)0∣R∣\lvert R\rvert
π(R)\pi(R)1 (if RR non-empty)∣R∣\lvert R\rvert
R∪SR \cup Smax⁡(∣R∣,∣S∣)\max(\lvert R\rvert, \lvert S\rvert)∣R∣+∣S∣\lvert R\rvert + \lvert S\rvert
R∩SR \cap S0min⁡(∣R∣,∣S∣)\min(\lvert R\rvert, \lvert S\rvert)
R−SR - S0∣R∣\lvert R\rvert
R×SR \times S∣R∣⋅∣S∣\lvert R\rvert\cdot\lvert S\rvert∣R∣⋅∣S∣\lvert R\rvert\cdot\lvert S\rvert
R⋈SR \bowtie S0∣R∣⋅∣S∣\lvert R\rvert\cdot\lvert S\rvert
R⋈SR \bowtie S, common attribute is a key of SS0∣R∣\lvert R\rvert
R ⟕ S∣R∣\lvert R\rvert∣R∣⋅∣S∣\lvert R\rvert\cdot\lvert S\rvert

Division, carefully

For R(X,Y)R(X, Y) and S(Y)S(Y), R÷S={x:∀y∈S, (x,y)∈R}R \div S = \{x : \forall y \in S,\ (x, y) \in R\}:

R÷S=πX(R)−πX((πX(R)×S)−R).R \div S = \pi_X(R) - \pi_X\big((\pi_X(R) \times S) - R\big).

Read it as: all candidates, minus those that are missing some required yy.

Equivalences used by query optimisers

  • Cascade and commute selections: σp∧q(R)=σp(σq(R))=σq(σp(R))\sigma_{p\wedge q}(R) = \sigma_p(\sigma_q(R)) = \sigma_q(\sigma_p(R)).
  • Push selections down below joins: σp(R⋈S)=σp(R)⋈S\sigma_p(R \bowtie S) = \sigma_p(R) \bowtie S if pp uses only RR's attributes — filter early, join smaller relations.
  • Push projections down (keeping join attributes).
  • Joins are commutative and associative — join order is the optimiser's main choice.
  • π\pi distributes over ∪\cup but not over −- or ∩\cap.
naive π name σ dept='CSE' ⋈ Student Enrolled optimised: filter first π name ⋈ σ dept='CSE' Student Enrolled
Pushing the selection below the join shrinks the join input.

Quick revision

Practice questions

GATE-style questions: 4 one-mark and 6 two-mark. Wrong MCQs cost ⅓ of their marks in the real exam; MSQ and NAT have no negative marking. Attempt each before opening the solution.

Q1NAT1 mark

Relation RR has 4 tuples and relation SS has 3 tuples. The number of tuples in R×SR \times S is ______.

Q2NAT2 marks

R(A,B)={(1,2),(2,3),(3,2)}R(A, B) = \{(1,2), (2,3), (3,2)\} and S(B,C)={(2,5),(2,6),(4,7)}S(B, C) = \{(2,5), (2,6), (4,7)\}. The number of tuples in the natural join R⋈SR \bowtie S is ______.

Q3MCQ1 mark

R(A,B)={(1,a),(1,b),(2,a)}R(A, B) = \{(1, a), (1, b), (2, a)\}. Under relational algebra (set) semantics, πA(R)\pi_A(R) has

Q4MCQ2 marks

Enrolled(sid,cid)\text{Enrolled}(\textit{sid}, \textit{cid}) and Course(cid)\text{Course}(\textit{cid}) are relations. The query Enrolled÷Course\text{Enrolled} \div \text{Course} returns

Q5NAT2 marks

E(sid,cid)={(s1,c1),(s1,c2),(s2,c1),(s3,c1),(s3,c2),(s3,c3)}E(\textit{sid}, \textit{cid}) = \{(s_1,c_1), (s_1,c_2), (s_2,c_1), (s_3,c_1), (s_3,c_2), (s_3,c_3)\} and C(cid)={c1,c2}C(\textit{cid}) = \{c_1, c_2\}. The number of tuples in E÷CE \div C is ______.

Q6MSQ2 marks

Which equivalences of relational algebra always hold?

One or more options are correct.

Q7NAT2 marks

RR has 10 tuples and SS has 5 tuples, and they share exactly one attribute. The maximum possible number of tuples in R⋈SR \bowtie S is ______.

Q8MCQ1 mark

In R ⟕ S (left outer join), a tuple of RR that matches no tuple of SS

Q9NAT2 marks

In R(A,B)R(A, B), attribute BB is a NOT NULL foreign key referencing the primary key BB of S(B,C)S(B, C). RR has 100 tuples and SS has 20. The number of tuples in R⋈SR \bowtie S is ______.

Q10MCQ1 mark

Which set of operators is relationally complete (can express every relational algebra query)?