# DBMS 2027 Rank-Decider: Relational Division (R ÷ S), SQL Double-NOT-EXISTS & ARIES WAL Recovery
Exam: GATE Computer Science & Information Technology (GATE CS)
Subject: Databases (DBMS)
Canonical URL: https://gateandnet.com/exams/gate-cs/databases/relational-division-aries-wal-recovery-and-isolation

> Primitive operator expansion of Relational Division R(X,Y) ÷ S(Y), De Morgan double-NOT-EXISTS SQL pattern, Steal/No-Force Write-Ahead Logging (Undo vs Redo), and Blind-Write View Serializability.

## 1. Universal Quantification ("For All") in Relational Algebra & SQL

Since SQL has no `FOR ALL` keyword, rewrite $\forall y \in S : (x, y) \in R$ via De Morgan’s law as $\lnot \exists y \in S : (x, y) \notin R$ (**Double `NOT EXISTS`**):

```sql
-- Find Student IDs enrolled in ALL courses offered by 'CS' department
SELECT s.sid FROM Students s
WHERE NOT EXISTS (
    SELECT c.cid FROM Courses c WHERE c.dept = 'CS'
    AND NOT EXISTS (
        SELECT 1 FROM Enrolled e
        WHERE e.sid = s.sid AND e.cid = c.cid
    )
);
```

> [!TRAP]
> **Empty Divisor Edge Case:** In the SQL double-`NOT EXISTS` query above, if the `CS` department offers **$0$ courses** (`S` is empty), the outer `NOT EXISTS` evaluates to `TRUE` for **EVERY student** in `Students`!

## 2. Crash Recovery: Write-Ahead Logging (WAL), Deferred vs Immediate Update

| Recovery Scheme | Buffer Policy | Uncommitted Writes on Disk? | On Crash: Committed Txns | On Crash: Aborted/Active Txns |
| :--- | :--- | :---: | :---: | :---: |
| **Deferred Update** | `NO-STEAL / NO-FORCE` | ❌ Never | **REDO** (need new value) | **NO-UNDO** (simply ignore!) |
| **Immediate Update (ARIES)** | `STEAL / NO-FORCE` | ✅ Possible | **REDO** (forward order) | **UNDO** (**reverse** log order!) |

- **Two Golden WAL Rules:** (1) Before a modified dirty page hits disk, its `<Ti, X, old, new>` Undo log record **must** be flushed to stable storage (**STEAL safety**); (2) Before `Ti` is declared committed to the user, all its log records through `<Ti, COMMIT>` **must** be flushed to stable storage (**NO-FORCE durability**)!
- **View Serializable WITHOUT being Conflict Serializable:** Requires at least one **Blind Write** (writing $X$ without first reading $X$)! If a schedule has **zero blind writes**, View Serializable $\iff$ Conflict Serializable!

## Solved Practice Questions & PYQs

### [GATE CS 2027 Expected | MCQ]
Let $R(A, B)$ have $12$ tuples with $4$ distinct values of $A$, and let $S(B)$ be non-empty with $3$ tuples. What are the **minimum** and **maximum** possible numbers of tuples in the Relational Division $R \div S$?
**Correct Answer:** A
**Solution:** - **Minimum = `0`:** e.g. each of the $4$ $A$-values is paired with $2$ $B$-values from $S$ plus $1$ outside $S$ (none covers all $3$ of $S$).
- **Maximum = `4`:** when $R = \pi_A(R) \times S$ ($4 \times 3 = 12$ tuples!), all $4$ distinct $A$-values qualify!

### [GATE CS 2026–27 Expected MSQ | MSQ]
Which of the following statements regarding **Database Concurrency & Crash Recovery** are **ALWAYS TRUE**?
**Correct Answer:** A,B,D
**Solution:** **A, B, D** are always true! **C is a classic trap**: 2PL guarantees Conflict Serializability, **NOT** deadlock freedom (two transactions can still deadlock upgrading/acquiring locks!).
