mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-21 09:04:19 +01:00
Dynamic cursor ID allocation
With sorter, for example, we need more cursors per program.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user