I’m stuck on Stage #WS9. It looks like I’m reading the same inforamtion from different leaf pages twice.
My understanding is that the root page of the superheroes
table is an interior table page. So I read its children and I add them to the results of the query (if a child is a leaf page) or call my read_interior_page()
recursively (if a child is an interior page).
I’ve tried to print the results that I’m getting from every leaf cell from a child of the root page and one layer below:
for cell in &interior_page.cells {
let pointer = (cell.left_child_page_num * u32::from(self.header.page_size)).into();
let child = Self::get_page(self, pointer, None)?;
match child {
Page::LeafTable(leaf) => {
let mut r = Self::read_leaf_page(&leaf, query, table_info)?;
if !r.is_empty() {
println!("got from leaf table {}: {:?}", &leaf.offset / 4096, r);
}
res.append(&mut r);
}
Page::InteriorTable(interior) => {
for cell in &interior.cells {
let pointer =
(cell.left_child_page_num * u32::from(self.header.page_size)).into();
let child = Self::get_page(self, pointer, None)?;
match child {
Page::LeafTable(leaf) => {
let mut r = Self::read_leaf_page(&leaf, query, table_info)?;
if !r.is_empty() {
println!(
"got from INNER leaf table {}: {:?}",
&leaf.offset / 4096,
r
);
}
res.append(&mut r);
}
Page::InteriorTable(_) => todo!("next layer"),
Page::LeafIndex => (),
Page::InteriorIndex => (),
}
}
}
_ => {
//dbg!("other type");
}
}
}
Here are my logs:
got from leaf table 49: [["350", "Congorilla (New Earth)"]]
got from leaf table 36: [["1131", "Lambien (New Earth)"]]
got from INNER leaf table 75: [["350", "Congorilla (New Earth)"]]
got from INNER leaf table 94: [["1131", "Lambien (New Earth)"]]
got from INNER leaf table 151: [["4533", "Kal-El (DC One Million)"]]
got from INNER leaf table 123: [["5496", "Midas (New Earth)"]]
got from leaf table 271: [["4533", "Kal-El (DC One Million)"]]
got from leaf table 267: [["4765", "Ahura-Mazda (New Earth)"]]
got from leaf table 254: [["5496", "Midas (New Earth)"]]
So it looks like the numbers of the pages are different, but the data stored inside is the same.
This does not seem correct to me, so I would appreciate any tips on how to fix it. Thank you very much!