diff --git a/core/vdbe/builder.rs b/core/vdbe/builder.rs index c3bff8423..ba8f1d200 100644 --- a/core/vdbe/builder.rs +++ b/core/vdbe/builder.rs @@ -7,6 +7,7 @@ use tracing::{instrument, Level}; use turso_parser::ast::{self, TableInternalId}; use crate::{ + index_method::IndexMethodAttachment, numeric::Numeric, parameters::Parameters, schema::{BTreeTable, Index, PseudoCursorType, Schema, Table}, @@ -134,6 +135,7 @@ pub struct ProgramBuilder { pub enum CursorType { BTreeTable(Arc), BTreeIndex(Arc), + IndexMethod(Arc), Pseudo(PseudoCursorType), Sorter, VirtualTable(Arc), @@ -332,6 +334,20 @@ impl ProgramBuilder { } } + /// allocate proper cursor for the given index (either [CursorType::BTreeIndex] or [CursorType::IndexMethod]) + pub fn alloc_cursor_index( + &mut self, + key: Option, + index: &Arc, + ) -> crate::Result { + let module = index.index_method.as_ref(); + if module.is_some_and(|m| !m.definition().backing_btree) { + let module = module.unwrap().clone(); + return Ok(self._alloc_cursor_id(key, CursorType::IndexMethod(module))); + } + Ok(self._alloc_cursor_id(key, CursorType::BTreeIndex(index.clone()))) + } + pub fn alloc_cursor_id(&mut self, cursor_type: CursorType) -> usize { self._alloc_cursor_id(None, cursor_type) }