A cell keeps at most 236 bytes of its key and data on the b-tree page. When key + data is longer, the cell ends with the number of the first overflow page, and the rest of the stream continues on a chain of overflow pages.
Layout
The struct OverflowPage in the 2.8.17 source. The page number is in
the file’s byte order.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 4 | u32 | next page | The next overflow page of the chain, or 0 on the last. |
| 4 | 1,020 | bytes | payload | The next 1,020 bytes (OVERFLOW_SIZE) of the key-and-data stream, carrying on where the cell’s 236 bytes, or the previous page, stop. On the last page only the bytes still needed count; the rest means nothing. |
Reading a long payload
- Let P = key size + data size, from the cell header.
- Take the first 236 bytes from the cell, at cell offset 12.
- Read the first overflow page number at cell offset 248.
- From each overflow page take min(1,020, bytes still needed) bytes from offset 4, then go to the page number at offset 0.
- Stop when P bytes have been read. A chain that ends early, or a page number past the end of the file, means the file is damaged.
The key comes first in the stream, so a long index key can itself run onto overflow pages.
Example
A row whose key and data come to 3,000 bytes: 236 bytes stay in the cell, which takes 252 bytes on its page; the other 2,764 bytes go on three overflow pages, 1,020, 1,020 and 724 bytes. The last page’s next page number is 0.