tursodatabase/turso · error
OpenRead on pseudo cursor
Error message
OpenRead on pseudo cursor
What it means
At execution time Insn::OpenRead tried to open a cursor slot whose cursor_ref type is CursorType::Pseudo. Pseudo cursors hold one materialized in-memory row (used for VALUES rows and co-routine output) and have no B-tree to open, so OpenRead cannot apply. The bytecode reused a pseudo cursor id as if it were a B-tree cursor — a translation bug, hit inside op_open_read while stepping the program.
Solutions
- Report the SQL — OpenRead may only target BTreeTable/BTreeIndex/MaterializedView cursors; the translator allocated the wrong kind
- Rewrite the VALUES/co-routine construct into a real temp table or plain SELECT to avoid pseudo cursors
- Upgrade to a version with the cursor-allocation fix
Defensive patterns
Strategy: validation
Validate before calling
// audit a compiled program before first execution: OpenRead must target btree-backed cursors
fn audit_open_reads(program: &Program) -> Result<()> {
for insn in &program.insns {
if let Insn::OpenRead { cursor_id, .. } = insn {
match program.cursor_ref.get(*cursor_id).map(|(_, t)| t) {
Some(CursorType::BTreeTable(_)) | Some(CursorType::BTreeIndex(_))
| Some(CursorType::MaterializedView(..)) => {}
other => crate::bail_parse_error!("OpenRead targets non-btree cursor ({other:?})"),
}
}
}
Ok(())
} Prevention
- Run a bytecode audit pass in debug builds that type-checks every cursor-consuming insn against cursor_ref
- Wrap statement execution in catch_unwind at your API boundary so engine panics become per-query errors, not process crashes
- Keep regression tests mixing VALUES/CTE materialization with table scans
When it happens
Trigger: A plan that materializes rows into a pseudo cursor and later emits OpenRead for the same cursor id — typically after cursor renumbering/reallocation changes, or when a co-routine or VALUES-clause pseudo cursor id leaks into an outer open-table sequence.
Common situations: Queries combining VALUES clauses, co-routine subqueries, or CTE materialization with ordinary table scans; engine versions where cursor allocation was refactored.
Related errors
- Next on non-btree/materialized-view cursor
- on unexpected cursor
- OpenRead on sorter cursor
- OpenRead on virtual table cursor, use Insn:VOpen instead
- Rewind on non-btree/materialized-view cursor
AI-assisted analysis of tursodatabase/turso@8d4a589f8d (2026-08-20).
Data as JSON: /api/errors/74795af3d86c562d.
Report an issue: GitHub.
Appendix: source
Thrown at core/vdbe/execute.rs:1422
Ok(OpenedBTree::Plain(btree_cursor))
}
};
match cursor_type {
CursorType::MaterializedView(_, view_mutex) => {
// This is a materialized view with storage
// Create btree cursor for reading the persistent data
let btree_cursor = BTreeCursor::new_table(
pager.clone(),
maybe_transform_root_page_to_positive(mv_store.as_ref(), *root_page),
num_columns,
)
.into_boxed();
let cursor = maybe_promote_to_mvcc_cursor(btree_cursor, MvccCursorType::Table)?;
// Get the view name and look up or create its transaction state
let view_name = view_mutex.lock().name().to_string();
let tx_state = program
.connection
.view_transaction_states
.get_or_create(&view_name);
// Create materialized view cursor with this view's transaction state
let mv_cursor = crate::incremental::cursor::MaterializedViewCursor::new(
cursor.into_dyn(),
view_mutex.clone(),
pager,
tx_state,
)?;
cursors
.get_mut(*cursor_id)
.expect("cursor_id should be valid")
.replace(Cursor::new_materialized_view(mv_cursor));
}View on GitHub (pinned to 8d4a589f8d)