Database Management System · Unit 5 · 5 hrs
The Relational Algebra and Relational Calculus
Exam-focused notes for The Relational Algebra and Relational Calculus (Database Management System, CSC265): what the TU syllabus asks and how it has actually been tested, with 5 solved past questions from this unit.
The Relational Algebra and Relational Calculus in short
This unit develops relational algebra and relational calculus, the two formal query languages that give the relational model its mathematical foundation and against which every practical language, including SQL, can be checked for correctness.
What this unit covers
- Unary Relational Operations: SELECT and PROJECT
- Relational Algebra Operations from Set Theory
- Binary Relational Operations: JOIN and DIVISION
- Additional Relational Operations
- the Tuple Relational Calculus
- the Domain Relational Calculus
the Tuple Relational Calculus
2080.1 · 5 marks
What is tuple realtion calculus ? Given the following schema, write tuple relational calculus for selecting name and address of employee who are working in a company having Cid=E01. Employee(Eid, Ename, Address, Cid) Company(Cid, CName) [5]
Binary Relational Operations
2080 · 5 marks
Write short notes on: a. Natural join b. Shadow paging [5]
Show solved answerHide answer
Short Notes
a. Natural Join
Natural Join is a binary relational operation that combines two relations based on their common attributes (columns that share the same name and same data type).
Key Characteristics:
- It is denoted by the join symbol (⋈)
- The common attribute(s) must have the same name and same data type in both relations
- It automatically performs an equi-join on all matching attribute names
- It eliminates duplicate attributes from the result, keeping only one copy of the common column(s)
- It effectively combines selection and Cartesian product into a single operation
Example:
If relation R(A, B, C) and relation S(C, D, E) share attribute C:
R ⋈ S produces tuples where R.C = S.C, with C appearing only once
Result schema: (A, B, C, D, E)
Important Note on Lossless Decomposition:
A decomposition {R1, R2, R3} of a relation R is called a lossless decomposition if the natural join of R1, R2, R3 produces exactly the original relation R.
However, if a "fat relation" (one with too many grouped attributes) is split and then rejoined using natural join, it may generate more tuples than the original, making it impossible to recover the original table. This is known as a lossy decomposition.
b. Shadow Paging
Shadow paging is a recovery technique used in database systems to handle transaction failures without using a traditional log.
Basic Concept:
- The database is considered to be made up of a number of fixed-sized disk blocks (say n blocks)
- A directory with n entries is constructed, where the i-th entry points to the i-th database page on disk
- This directory is kept in main memory if it is not too large
How It Works:
| Component | Description |
|---|---|
| Shadow Directory | The original, stable directory pointing to pages before the transaction |
| Current Directory | A working copy that reflects changes made during the transaction |
During Transaction Execution:
- The shadow directory is never modified during transaction execution
- When a write operation is performed on a page:
- A new copy of the modified page is created on a previously unused disk block
- The old copy is NOT overwritten
- For every page updated by the transaction, two versions are maintained:
- Old version referenced by the shadow directory
- New version referenced by the current directory
Recovery:
- On transaction failure: simply discard the current directory and restore the shadow directory. The old pages remain intact.
- On successful commit: the current directory replaces the shadow directory permanently.
Advantage:
Simple recovery with no need for redo/undo logs for the modified pages.
Disadvantage:
Requires extra disk space to maintain two versions of modified pages simultaneously.
2079 · 5 marks
Retrieve the TName, and No_of_priod of teachers who teach in 'ABC' school using Relational Algebra.TEACHER (TID, TName, TAddress, TQualification), SCHOOL (SID, SName, SAddress, SPhone), SCHOOL_TEACHER (SID, TID, No_of_Period) [5]
2078 · 5 marks
Explain the difference between 'Join' and 'Natural Join' of algebraic operations with example. [5]
Make Unit 5 stick
Practice CSC265 with flashcards & quizzes