mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-08 01:34:23 +01:00
vdbe: add Insn::IdxRowId
This commit is contained in:
@@ -1836,6 +1836,28 @@ pub fn op_row_id(
|
||||
Ok(InsnFunctionStepResult::Step)
|
||||
}
|
||||
|
||||
pub fn op_idx_row_id(
|
||||
program: &Program,
|
||||
state: &mut ProgramState,
|
||||
insn: &Insn,
|
||||
pager: &Rc<Pager>,
|
||||
mv_store: Option<&Rc<MvStore>>,
|
||||
) -> Result<InsnFunctionStepResult> {
|
||||
let Insn::IdxRowId { cursor_id, dest } = insn else {
|
||||
unreachable!("unexpected Insn {:?}", insn)
|
||||
};
|
||||
let mut cursors = state.cursors.borrow_mut();
|
||||
let cursor = cursors.get_mut(*cursor_id).unwrap().as_mut().unwrap();
|
||||
let cursor = cursor.as_btree_mut();
|
||||
let rowid = cursor.rowid()?;
|
||||
state.registers[*dest] = match rowid {
|
||||
Some(rowid) => Register::OwnedValue(OwnedValue::Integer(rowid as i64)),
|
||||
None => Register::OwnedValue(OwnedValue::Null),
|
||||
};
|
||||
state.pc += 1;
|
||||
Ok(InsnFunctionStepResult::Step)
|
||||
}
|
||||
|
||||
pub fn op_seek_rowid(
|
||||
program: &Program,
|
||||
state: &mut ProgramState,
|
||||
|
||||
@@ -684,6 +684,22 @@ pub fn insn_to_str(
|
||||
.unwrap_or(&format!("cursor {}", cursor_id))
|
||||
),
|
||||
),
|
||||
Insn::IdxRowId { cursor_id, dest } => (
|
||||
"IdxRowId",
|
||||
*cursor_id as i32,
|
||||
*dest as i32,
|
||||
0,
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!(
|
||||
"r[{}]={}.rowid",
|
||||
dest,
|
||||
&program.cursor_ref[*cursor_id]
|
||||
.0
|
||||
.as_ref()
|
||||
.unwrap_or(&format!("cursor {}", cursor_id))
|
||||
),
|
||||
),
|
||||
Insn::SeekRowid {
|
||||
cursor_id,
|
||||
src_reg,
|
||||
|
||||
@@ -438,6 +438,11 @@ pub enum Insn {
|
||||
cursor_id: CursorID,
|
||||
dest: usize,
|
||||
},
|
||||
/// Read the rowid of the current row from an index cursor.
|
||||
IdxRowId {
|
||||
cursor_id: CursorID,
|
||||
dest: usize,
|
||||
},
|
||||
|
||||
/// Seek to a rowid in the cursor. If not found, jump to the given PC. Otherwise, continue to the next instruction.
|
||||
SeekRowid {
|
||||
@@ -856,6 +861,7 @@ impl Insn {
|
||||
Insn::String8 { .. } => execute::op_string8,
|
||||
Insn::Blob { .. } => execute::op_blob,
|
||||
Insn::RowId { .. } => execute::op_row_id,
|
||||
Insn::IdxRowId { .. } => execute::op_idx_row_id,
|
||||
Insn::SeekRowid { .. } => execute::op_seek_rowid,
|
||||
Insn::DeferredSeek { .. } => execute::op_deferred_seek,
|
||||
Insn::SeekGE { .. } => execute::op_seek,
|
||||
|
||||
Reference in New Issue
Block a user