Adding indexes to the update plan

This commit is contained in:
pedrocarlo
2025-04-29 13:05:08 -03:00
parent 76b29c2909
commit e7fa023c26
2 changed files with 29 additions and 1 deletions

View File

@@ -668,6 +668,25 @@ fn emit_update_insns(
_ => return Ok(()),
};
// dbg!(&plan.indexes);
// THIS IS SAME CODE AS WE HAVE ON INSERT
// allocate cursor id's for each btree index cursor we'll need to populate the indexes
// (idx name, root_page, idx cursor id)
let idx_cursors = plan
.indexes_to_update
.iter()
.map(|idx| {
(
&idx.name,
idx.root_page,
program.alloc_cursor_id(
Some(idx.table_name.clone()),
CursorType::BTreeIndex(idx.clone()),
),
)
})
.collect::<Vec<(&String, usize, usize)>>();
for cond in plan
.where_clause
.iter()

View File

@@ -82,7 +82,7 @@ impl IdxInsertFlags {
}
#[derive(Clone, Copy, Debug)]
pub enum RegisterOrLiteral<T: Copy> {
pub enum RegisterOrLiteral<T: Copy + std::fmt::Display> {
Register(usize),
Literal(T),
}
@@ -93,6 +93,15 @@ impl From<PageIdx> for RegisterOrLiteral<PageIdx> {
}
}
impl<T: Copy + std::fmt::Display> std::fmt::Display for RegisterOrLiteral<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Literal(lit) => lit.fmt(f),
Self::Register(reg) => reg.fmt(f),
}
}
}
#[derive(Description, Debug)]
pub enum Insn {
/// Initialize the program state and jump to the given PC.