Dynamic cursor ID allocation

With sorter, for example, we need more cursors per program.
This commit is contained in:
Pekka Enberg
2024-03-29 09:26:18 +02:00
parent 454b1047ce
commit a447ea0f49
2 changed files with 10 additions and 2 deletions

View File

@@ -21,7 +21,7 @@ fn translate_select(schema: &Schema, select: Select) -> Result<Program> {
from: Some(from),
..
} => {
let cursor_id = 0;
let cursor_id = program.alloc_cursor_id();
let table_name = match from.select {
Some(select_table) => match *select_table {
sqlite3_parser::ast::SelectTable::Table(name, ..) => name.name,
@@ -47,7 +47,7 @@ fn translate_select(schema: &Schema, select: Select) -> Result<Program> {
None
};
program.emit_insn(Insn::OpenReadAsync {
cursor_id: 0,
cursor_id,
root_page,
});
program.emit_insn(Insn::OpenReadAwait);

View File

@@ -97,6 +97,7 @@ pub enum Insn {
pub struct ProgramBuilder {
next_free_register: usize,
next_free_cursor_id: usize,
insns: Vec<Insn>,
}
@@ -104,6 +105,7 @@ impl ProgramBuilder {
pub fn new() -> Self {
Self {
next_free_register: 0,
next_free_cursor_id: 0,
insns: Vec::new(),
}
}
@@ -118,6 +120,12 @@ impl ProgramBuilder {
self.next_free_register
}
pub fn alloc_cursor_id(&mut self) -> usize {
let cursor = self.next_free_cursor_id;
self.next_free_cursor_id += 1;
cursor
}
pub fn emit_placeholder(&mut self) -> usize {
let offset = self.insns.len();
self.insns.push(Insn::Halt);