From 6a287ae1a98d99a54acca98de4cf70d22eb57dbe Mon Sep 17 00:00:00 2001 From: jussisaurio Date: Mon, 23 Dec 2024 21:31:42 +0200 Subject: [PATCH] add comment about cell_content_area 0 value meaning u16::MAX --- core/storage/btree.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/storage/btree.rs b/core/storage/btree.rs index 3f6822872..413a72744 100644 --- a/core/storage/btree.rs +++ b/core/storage/btree.rs @@ -1405,6 +1405,15 @@ impl BTreeCursor { let usable_space = (db_header.page_size - db_header.reserved_space as u16) as usize; let mut first_byte_in_cell_content = page.cell_content_area(); + // A zero value for the cell content area pointer is interpreted as 65536. + // See https://www.sqlite.org/fileformat.html + // The max page size for a sqlite database is 64kiB i.e. 65536 bytes. + // 65536 is u16::MAX + 1, and since cell content grows from right to left, this means + // the cell content area pointer is at the end of the page, + // i.e. + // 1. the page size is 64kiB + // 2. there are no cells on the page + // 3. there is no reserved space at the end of the page if first_byte_in_cell_content == 0 { first_byte_in_cell_content = u16::MAX; }