Introduction to Storage 00:00:01 Why the second page read finishes sooner A museum catalog is much larger than memory. An attendant opens page three, checks two other pages and asks for page three again. Follow a database buffer pool to see why those reads can cost different amounts. The pool is empty. Pages 1 to 8 are on disk. Page 3 is not in memory. It is a miss, so it is loaded from disk. Two more misses. The pool now holds three pages. Page 3 is here. No disk is involved, and the page becomes the most recently used. A logical read requests a page. It becomes physical storage I/O only when a usable memory copy is unavailable. Count both to distinguish frequently used data from slow disks. 00:00:49 Commit the log before relaxing about the data page The attendant updates an entry. A modified page in memory is dirty. A recovery log records enough information for the engine's chosen recovery scheme before the database promises a durable commit. A log record is created and the page changes in memory. The star means dirty. The commit record is appended and the log is flushed. Only now does the client hear that it worked. The data page was not written. Page 6 is loaded, changed in memory and logged. The log only grows at its end. The acknowledgement boundary depends on configuration. State whether the promise covers process failure, power loss on this host, or loss of the storage device itself. 00:01:36 A checkpoint shortens the recovery journey Dirty pages need to reach persistent storage eventually. A checkpoint records a recovery boundary and may flush or coordinate page writes depending on the engine. Space pressure also forces a choice about which cached page to evict. Two dirty pages, and a log that is still needed. Pages 3 and 6 are written to their places on disk. In this small recovery model some older log records become eligible to retire. Production engines also account for every other consumer of the log. The pool is full. Page 1 was used longest ago and is clean, so it is simply dropped. Only release log space whose records are no longer needed by recovery, replication, backups or other configured consumers. A checkpoint is progress in a protocol, not permission to discard all history. 00:02:32 Cut power halfway through the evening Separate committed work from an incomplete transaction and separate the contents of memory from the bytes on disk. Now restart the illustrated recovery engine and find the last valid recovery point. Transaction 1 changed page 2 and committed. Transaction 2 changed page 4 and has not committed. Its record was flushed along with the first. The pool is gone. The log and the old pages are still on disk. After the restart both changes are repeated from the log. Transaction 2 has no commit record, so its change to page 4 is taken back. Different engines implement uncommitted work with undo records, version visibility or another recovery design. The common requirement is that recovered visible state respects the promised commit boundary. 00:03:24 A scan can beat an index One visitor wants one catalog entry. Another asks for most of a shelf. Compare the number and pattern of page reads for an index lookup and a sequential scan as the requested result grows. The scan reads page 1. The index reads its root, which says M to Z. The scan is on page 2. The index is at the node T to Z. The index reads page 987 and is done. The scan is on page 4. After 987 reads the scan finds the same row. Access shape, caching and layout determine the cost. The operation with fewer logical comparisons can still make more expensive random reads. Check the actual plan against the workload.