Chapter 3

Tuple relational calculus

Calculus states which tuples qualify; algebra specifies operations that produce them. Translate quantified variables into relation aliases and link them through equality predicates before inspecting answer choices.

3.1 Predicates, bindings and translation

Past papers · CS 2014–2026 (23 papers): 2 questions, 4 marks · DA 2024–2026 (3 papers): 1 question, 2 marks

A tuple-calculus query has the form {t∣P(t)}\{t\mid P(t)\}. The output tuple variable tt is free; variables introduced by ∃\exists or ∀\forall are bound within their scopes. Membership u∈ru\in r ranges uu over relation rr. An attribute reference is u[A]u[A] or u.Au.A.

For Maker(mid, city) and Part(pid, mid), the pids made in Pune are:

{t∣∃p∈Part  ∃m∈Maker  (t[pid]=p[pid]∧p[mid]=m[mid]∧m[city]=’Pune’)}.\{t\mid \exists p\in Part\;\exists m\in Maker\; (t[pid]=p[pid]\land p[mid]=m[mid]\land m[city]=\text{'Pune'})\}.

The algebra is projection of pid from the matching join after selecting Pune makers. Omitting the equality on mid makes the query test whether any Pune maker exists, rather than whether the part's own maker is in Pune.

3.2 Safe and domain-independent queries

Past papers · CS 2014–2026 (23 papers): 1 question, 2 marks

A safe calculus expression restricts output values to values occurring in the referenced relations or constants in the query. Merely being finite on one chosen instance is insufficient. A domain-independent query does not change if unused values are added to the ambient domains. Safe relational calculus has the expressive power of basic relational algebra.

{t∣¬(t∈r)}\{t\mid\neg(t\in r)\} is unsafe over an unbounded domain. A condition such as t[A]≠u[A]t[A]\ne u[A] excludes a value but does not positively bind t[A]t[A] to a finite input set. Binding one output attribute does not bind the others. A safe universal query begins with a finite candidate relation, then removes candidates with counterexamples.

Last-minute recall

  • Free variables determine the output; quantified variables are local.
  • A join needs a predicate connecting the relevant aliases.
  • “For all” means “there is no counterexample”.
  • Restrict output candidates even when a universal test is present.
  • Inequality alone does not bind an attribute to the active domain.

Revise offline: the whole Databases and Data Warehousing handbook as one PDF

58 pages · 2.7 MBFree to read online. Sign in to download the PDF.We save the handbook, version and request time in My downloads. Privacy policy

All chapters · Corrections