1.1 Page-Level I/O

Reading a whole page even when only one record is needed may look inefficient. A whole page is read from disk for a single record. But the picture changes once you look at the cost. Most of the cost of one disk I/O request is the time spent waiting for the request to be served, and it is nearly the same whether the amount read is one record or a hundred. When the fixed cost per request is large, it pays to read as much as possible in each request.

A disk is exactly this kind of device. Reading a value from memory takes tens to hundreds of nanoseconds, but one disk request takes tens to hundreds of microseconds on an SSD and several milliseconds on a slow hard disk. That is thousands to hundreds of thousands of times slower than memory. Most of that time is the wait between "sending the request and the first byte arriving", and the extra time to fetch more data after that is relatively small. So databases fix the unit of exchange with the disk as a chunk of fixed size. This is the page. The size varies by database but is usually 8KB or 16KB. If a record is about 100 bytes, a page holds 80 to 160 of them. One disk I/O brings in many records at once.

This approach has many advantages. Records in the same page are usually stored contiguously, so when one of them is needed, the other records in the same page are often needed as well. For example, it is common to read orders placed on the same day one after another. Reading the next record from a page already in memory avoids a second disk I/O for the same page.

NOTE SSDs are much faster than hard disks, but one request still takes hundreds to thousands of times longer than memory. SSDs are also designed to read and write in pages of a certain size, so fetching a chunk of data (a page) at a time is still advantageous. They have only become faster than hard disks, and they remain very slow compared with memory.