Notation
| Write | Read | Defined in |
|---|
| \(\sel{p}(R)\) | the rows of \(R\) that satisfy \(p\) (selection) | 2F, 2T |
| \(f[R]\), \(\pi_1[R]\) | \(f\) applied to every row (image, projection) | 3F, 4T |
| \(R \times S\) | every row of \(R\) paired with every row of \(S\) (product) | 3F, 4T |
| \(R \cup S\) | the rows in \(R\) or \(S\) (union) | 3F, 2T |
| \(R - S\), \(R \cap S\) | the rows of \(R\) not in \(S\); in both | 4F, 3T |
| \(R \join_{k_1 = k_2} S\) | the pairs whose keys agree (join) | 4F |
| \(\proj{A}(R)\), \(\ren{a}{b}(R)\) | keep the attributes \(A\); rename \(a\) to \(b\) | 5F |
| \(R \join S\), \(R \div S\) | natural join; division | 5F |
| \(\lBrack q \rBrack\) | the answer of the query \(q\) | 5F |
| \(\mathit{table}(l)\) | the table the list \(l\) represents | 1, 6 |
The laws
| Law | Holds when | Proved |
|---|
| 1 | \(\sel{p}(\sel{q}(R)) = \sel{p \wedge q}(R)\) | always | 2T; for lists 5T, 6 |
| 2 | \(\sel{p}(\sel{q}(R)) = \sel{q}(\sel{p}(R))\) | always | 2T |
| 3 | \(\sel{p}(R \cup S) = \sel{p}(R) \cup \sel{p}(S)\) | always | 2T |
| 4 | \(\sel{p}(R - S) = \sel{p}(R) - S\) | always | 3T |
| 5 | \(\sel{p}(R \times S) = \sel{p}(R) \times S\) | \(p\) mentions only \(R\) | 4T; for queries 7 |
| 6 | \(\sel{p}(R \join S) = \sel{p}(R) \join S\) | \(p\) mentions only \(R\) | 7 |
| 7 | \(\proj{A}(\proj{B}(R)) = \proj{A}(R)\) | \(A \subseteq B\) | 7 |
| 8 | \(\proj{A}(R \cup S) = \proj{A}(R) \cup \proj{A}(S)\) | always | 7; images 4T |
| 9 | \(\proj{A}(\sel{p}(R)) = \sel{p}(\proj{A}(R))\) | \(p\) mentions only \(A\) | 7 |
| 10 | \(R \join S = S \join R\) | always | 7 |
| 11 | \((R \join S) \join T = R \join (S \join T)\) | always | 7 |
A side condition is part of the law: without it, the two sides differ, or one of them makes no sense (Exercise 4T.3, Question 7.B).
Traps: these are not laws
| Looks like a law | But | See |
|---|
| \(\proj{A}(R - S) = \proj{A}(R) - \proj{A}(S)\) | false: projection can forget what made two rows differ | Question 7.A |
| \(f[R \cap S] = f[R] \cap f[S]\) | only \(\subseteq\) holds | Question 4T.B |
| \(\pi_1[R \times S] = R\) | only when \(S\) is not empty | Question 4T.A |
| \(R \times S = S \times R\) | false with positional columns; true with names | Question 3F.D |
| \(R - (R - S) = S\) | it is \(R \cap S\) | Question 3T.C |
| \(l \cat l = l\), for lists | true for the tables they represent, not for lists | Question 3F.F |
Every definition, fact and law, level by level
Level 1: Tables, and Your First Proof
Level 2F: Selection, as a Program
Level 3F: Projection, Product and Union, as Programs
Level 4F: Difference and Joins, by Comparing Rows
Level 5F: Named Columns, and a Query Language
Level 2T: Selection and Union, Proved
Level 3T: Difference, Proved: “Not”, and Classical Logic
Level 4T: Product and Projection, Proved: “For All” and “There Exists”
Level 5T: Induction on Lists
Level 6: Lists Represent Tables
Level 7: The Laws, for Every Query