From e7fa023c26e2354d04288ebe90f9615560bc6f53 Mon Sep 17 00:00:00 2001 From: pedrocarlo Date: Tue, 29 Apr 2025 13:05:08 -0300 Subject: [PATCH] Adding indexes to the update plan --- core/translate/emitter.rs | 19 +++++++++++++++++++ core/vdbe/insn.rs | 11 ++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/core/translate/emitter.rs b/core/translate/emitter.rs index 6557ca169..6b1a040a0 100644 --- a/core/translate/emitter.rs +++ b/core/translate/emitter.rs @@ -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::>(); + for cond in plan .where_clause .iter() diff --git a/core/vdbe/insn.rs b/core/vdbe/insn.rs index 587695d30..b41d48040 100644 --- a/core/vdbe/insn.rs +++ b/core/vdbe/insn.rs @@ -82,7 +82,7 @@ impl IdxInsertFlags { } #[derive(Clone, Copy, Debug)] -pub enum RegisterOrLiteral { +pub enum RegisterOrLiteral { Register(usize), Literal(T), } @@ -93,6 +93,15 @@ impl From for RegisterOrLiteral { } } +impl std::fmt::Display for RegisterOrLiteral { + 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.