CSC265 ยท 2080 ยท 5 marks
Write short notes on: a. Natural join b. Shadow paging
Write short notes on: a. Natural join b. Shadow paging [5]
Quick answer
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).
Short Notes
a. Natural Join
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.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.