sqlite3_ondisk: generalize left-child-pointer reading function to both index/table btrees

This commit is contained in:
Jussi Saurio
2025-07-07 15:51:17 +03:00
parent 6faa07505c
commit c13b2d5d90
2 changed files with 10 additions and 7 deletions

View File

@@ -1362,8 +1362,8 @@ impl BTreeCursor {
let max = max_cell_idx.get();
if min > max {
if let Some(nearest_matching_cell) = nearest_matching_cell.get() {
let left_child_page = contents
.cell_table_interior_read_left_child_page(nearest_matching_cell)?;
let left_child_page =
contents.cell_interior_read_left_child_page(nearest_matching_cell);
self.stack.set_cell_index(nearest_matching_cell as i32);
let mem_page = self.read_page(left_child_page as usize)?;
self.stack.push(mem_page);

View File

@@ -582,21 +582,24 @@ impl PageContent {
Ok(rowid as i64)
}
/// Read the left child page of a table interior cell.
/// Read the left child page of a table interior cell or an index interior cell.
#[inline(always)]
pub fn cell_table_interior_read_left_child_page(&self, idx: usize) -> Result<u32> {
debug_assert!(self.page_type() == PageType::TableInterior);
pub fn cell_interior_read_left_child_page(&self, idx: usize) -> u32 {
debug_assert!(
self.page_type() == PageType::TableInterior
|| self.page_type() == PageType::IndexInterior
);
let buf = self.as_ptr();
const INTERIOR_PAGE_HEADER_SIZE_BYTES: usize = 12;
let cell_pointer_array_start = INTERIOR_PAGE_HEADER_SIZE_BYTES;
let cell_pointer = cell_pointer_array_start + (idx * 2);
let cell_pointer = self.read_u16(cell_pointer) as usize;
Ok(u32::from_be_bytes([
u32::from_be_bytes([
buf[cell_pointer],
buf[cell_pointer + 1],
buf[cell_pointer + 2],
buf[cell_pointer + 3],
]))
])
}
/// Read the rowid of a table leaf cell.