ArticleslgStudy

mathematics

Relational calculus

Relational calculus is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Relational calculus rather than just read about it. In short: The relational calculus consists of two calculi, the tuple relational calculus and the domain relational calculus, that is part of the relational model for databases and provide a declarative way to specify database queries. The raison d'être of relational calculus is the formalization of query optimization, which is finding more efficient manners to execute the same query in a database.

Key takeaways

  • Relational calculus belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Relational calculus to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Relational calculus from memory before moving on to harder problems.

Reference excerpt

The relational calculus consists of two calculi, the tuple relational calculus and the domain relational calculus, that is part of the relational model for databases and provide a declarative way to specify database queries. The raison d'être of relational calculus is the formalization of query optimization, which is finding more efficient manners to execute the same query in a database. The relational calculus is similar to the relational algebra, which is also part of the relational model: While the relational calculus is meant as a declarative language that prescribes no execution order on the subexpressions of a relational calculus expression, the relational algebra is meant as an imperative language: the sub-expressions of a relational algebraic expression are meant to be executed from left-to-right and inside-out following their nesting. Per Codd's theorem, the relational algebra and the domain-independent relational calculus are logically equivalent.

Example A relational algebra expression might prescribe the following steps to retrieve the phone numbers and names of book stores that supply Some Sample Book:

Join book stores and titles over the BookstoreID. Restrict the result of that join to tuples for the book Some Sample Book. Project the result of that restriction over StoreName and StorePhone. A relational calculus expression would formulate this query in the following descriptive or declarative manner:

Get StoreName and StorePhone for book stores such that there exists a title BK with the same BookstoreID value and with a BookTitle value of Some Sample Book.

Mathematical properties

The relational algebra and the domain-independent relational calculus are logically equivalent: for any algebraic expression, there is an equivalent expression in the calculus, and vice versa. This result is known as Codd's theorem. Let the relations be: Bookstores(B)with attributes (BookstoreID, StoreName, StorePhone,…)Titles(T)with attributes (BookstoreID, BookTitle,…) 1) Relational algebra expression The query can be written as: π StoreName, StorePhone (σBookTitle=′Some Sample Book (B⋈B.BookstoreID=T.BookstoreID T)) A more explicit equivalent form is: π StoreName, StorePhone (B⋈ B.BookstoreID=T.BookstoreID σ BookTitle=′Some Sample Book′ (T)) The second form is often preferred because it pushes the selection down before the join. 2) Relational calculus expression In tuple relational calculus, the same query is: {⟨b.StoreName, b.StorePhone⟩∣Bookstores(b) ∧ ∃t(Titles(t)∧b.BookstoreID=t.BookstoreID∧t.BookTitle=′Some Sample Book′)} This says: return the store name and phone number of every bookstore b for which there exists a title tuple t with matching BookstoreID and the book title equal to "Some Sample Book". 3) Mathematical properties that prove the equivalence The proof rests on the standard equivalence between join, selection, projection, and existential quantification. Property A: Join + selection corresponds to conjunction with equality B⋈ B.BookstoreID=T.BookstoreID T means exactly the set of pairs (b,t) such that: B(b)∧T(t)∧b.BookstoreID=t.BookstoreID Then applying selection: σ T.BookTitle=′Some Sample Book′ (⋅) adds: t.BookTitle=′Some Sample Book′ So the algebraic expression becomes the set of all joined pairs satisfying: B(b)∧T(t)∧b.BookstoreID=t.BookstoreID∧t.BookTitle=′Some Sample Book′ Property B: Projection corresponds to existential quantification Projection over (StoreName,StorePhone) removes the title tuple and any other unneeded attributes. In logic, removing attributes corresponds to existentially quantifying them away: π StoreName,StorePhone (⋅)⟺∃t(⋅) So the projected algebra result corresponds to: {⟨b.StoreName,b.StorePhone⟩∣∃t(B(b)∧T(t)∧b.BookstoreID=t.BookstoreID∧t.BookTitle=′ Some Sample Book ′ )} which is exactly the calculus expression. Property C: Selection pushdown is valid Because selection only references T.BookTitle, we can rewrite: σ BookTitle= ′ Some Sample Book ′

(B⋈T)≡B⋈σ BookTitle= ′ Some Sample Book ′

(T) This is the relational algebra selection-pushdown law. It preserves meaning and often improves efficiency. 4) Final equivalence statement Thus the relational algebra query and the relational calculus query are equivalent because: π StoreName,StorePhone

(σ BookTitle= ′ Some Sample Book ′

(B⋈T)) denotes the same set as {⟨b.StoreName, b.StorePhone⟩∣B(b)∧∃t(T(t)∧b.BookstoreID=t.BookstoreID∧t.BookTitle= ′ Some Sample Book ′ )} This equivalence is the formal proof that the procedural algebra expression and the declarative calculus expression describe the same query.

Purpose The raison d'être of the relational calculus is the formalization of query optimization. Query optimization consists in determining from a query the most efficient manner (or manners) to execute it. Query optimization can be formalized as translating a relational calculus expression delivering an answer A into efficient relational algebraic expressions delivering the same answer A.

See also Calculus of relations

References Date, Christopher J. (2004). An Introduction to Database Systems (8th ed.). Addison Wesley. ISBN 0-321-19784-4.

Worked examples

Example 1 — a first encounter with Relational calculus

Start with the simplest possible case. Write down what Relational calculus claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Relational calculus before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Relational calculus ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Relational calculus

In research
Relational calculus appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Relational calculus in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Relational calculus is common in secondary-school and first-year university syllabi. It links to neighbouring topics Database management systems, Database stubs, Logical calculi, so understanding it makes those chapters shorter.
In everyday life
Look for Relational calculus outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Relational calculus in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Relational calculus means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Relational calculus out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Relational calculus in simple terms?

The relational calculus consists of two calculi, the tuple relational calculus and the domain relational calculus, that is part of the relational model for databases and provide a declarative way to specify database queries. The raison d'être of relational calculus is the formalization of query opt…

Why does Relational calculus matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Relational calculus?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Relational calculus.

Tags

  • Database management systems
  • Database stubs
  • Logical calculi
  • Relational model

Keep exploring