Database Management System: Keys, E-R model, normalization: 1NF to 5NF, aggregate functions, nested sub-queries, views, joined relations, transactions: ACID properties, concurrency control, triggers, stored procedures.
Three-schema architecture
External (many views) → conceptual (1) → internal (1); ext/conceptual mapping = logical independence, conceptual/internal = physical
Degree vs cardinality
Degree = number of attributes (columns); cardinality = number of tuples (rows)
Superkeys, one key of k attributes
2ⁿ⁻ᵏ (n = number of attributes)
Superkeys, two keys K₁, K₂
2ⁿ⁻|K₁| + 2ⁿ⁻|K₂| − 2ⁿ⁻|K₁∪K₂| — e.g. R(A,B,C,D), keys A and B → 8 + 8 − 4 = 12
Minimum tables (E-R)
M:N → 3; 1:N → 2; 1:1 total on both sides → 1; each multivalued attribute +1
Fundamental relational operators
σ π ρ ∪ − × (six); ∩, ⋈, ÷ are derived
Join sizes
|R × S| = |R|·|S|; 0 ≤ |R ⋈ S| ≤ |R|·|S|; non-null FK ⋈ its PK = |R| rows
Division
R ÷ S = πX(R) − πX((πX(R) × S) − R) — 'for all' queries
Armstrong's axioms
Reflexivity, Augmentation, Transitivity (sound and complete); derived: union, decomposition, pseudotransitivity
Candidate-key shortcut
Attributes on no right-hand side are in every key; X is a superkey ⇔ X⁺ = R
2NF / 3NF / BCNF tests
2NF: no partial dependency of a non-prime attribute; 3NF: X → A needs X superkey or A prime; BCNF: X must be a superkey
Lossless binary decomposition
R1 ∩ R2 → R1 or R1 ∩ R2 → R2 in F⁺ (for 4NF: R1 ∩ R2 →→ R1 − R2)
Normal-form chain
1NF ⊃ 2NF ⊃ 3NF ⊃ BCNF ⊃ 4NF ⊃ 5NF ⊃ DKNF; 4NF = BCNF + no non-trivial MVD
SQL logical order
FROM → WHERE → GROUP BY → HAVING → SELECT → DISTINCT → ORDER BY → LIMIT
COUNT and NULLs
COUNT(*) counts rows, COUNT(col) skips NULLs; over 0 rows COUNT = 0, SUM/AVG/MIN/MAX = NULL
ANY / ALL
> ALL = above the maximum; > ANY = above the minimum; IN ≡ = ANY; NOT IN ≡ <> ALL (fails if a NULL is present)
DELETE vs TRUNCATE vs DROP
DELETE: DML, WHERE, can roll back; TRUNCATE: DDL, all rows, fast; DROP: removes the table itself
ACID owners
Atomicity, Durability → recovery manager; Isolation → concurrency control; Consistency → programmer + constraints
Conflicting operations
Same item, different transactions, at least one write; acyclic precedence graph ⇔ conflict serializable
Number of schedules
(n₁ + n₂)! / (n₁!·n₂!) for two transactions; n! serial schedules for n transactions
Wait-die / wound-wait
Wait-die: older waits, younger dies. Wound-wait: older wounds (aborts) younger, younger waits
Timestamp ordering
read(Q) rejected if TS < W-TS(Q); write(Q) rejected if TS < R-TS(Q) or TS < W-TS(Q) (Thomas: ignore the latter)
Isolation levels
RU: dirty, non-repeatable, phantom; RC: non-repeatable, phantom; RR: phantom; SERIALIZABLE: none
Write-ahead logging
Log record on stable storage before the data page; deferred update = REDO only, immediate = UNDO + REDO
Blocking factor and B+ tree order
bfr = ⌊B/R⌋, blocks = ⌈r/bfr⌉; internal node p·P + (p−1)·K ≤ B; leaf q·(K+Pr) + P ≤ B