Chapter 1. Records and Pages

A database appears to handle data one record (row) at a time, but the unit it moves between disk and memory is not the record but the page (block). A page is a fixed-size chunk that holds several records together. Different records sit in the same page while stored, and even when only one record is needed, the database must load the whole page containing it into memory before it can find the record.

The components covered in this chapter are as follows.

  • Record (row): One item of data stored in a table.
  • Page (block): A fixed-size storage unit that holds several records, and the unit in which disk and memory exchange data.
  • Disk: Where a table's pages are stored permanently.
  • Buffer pool: The memory area that keeps pages read from disk.
  • Disk I/O: The operation of reading a page from disk or writing a page to disk.

Figure. The path a page takes between the query, the buffer pool, and the disk

flowchart LR
  Q["Query<br/>Look up one customer's phone number"]
  BP["Buffer pool (memory)<br/>Keeps pages that were read"]
  D["Disk<br/>Stores the table's pages"]
  Q -->|"① Request the page holding the record"| BP
  BP -->|"② Disk I/O if the page is absent"| D
  D -->|"③ Read the whole page and load it"| BP
  BP -->|"④ Find one record in the page and return it"| Q

The query on the left wants to read one customer's phone number from the customer table. The query wants a single record, but the request reaches the buffer pool as a request for the page that holds the record (①). If the page is not in the buffer pool, a disk I/O occurs (②), and what is read from disk is the entire page, not a single row, which is loaded into the buffer pool (③). Finally, the database finds that customer's record in the page now in memory and returns it to the query (④).

In short, even when you want to read one customer's phone number from the customer table, the database does not fetch just that one row from disk. It loads the whole page containing the record into memory and finds that customer's data inside it. This chapter looks in turn at why the database moves in units of pages, what a page looks like inside, and how the buffer pool, which keeps the pages that were read, works.