{"record":{"id":"74795af3d86c562d","repo":"tursodatabase/turso","slug":"openread-on-pseudo-cursor","errorCode":null,"errorMessage":"OpenRead on pseudo cursor","messagePattern":"OpenRead on pseudo cursor","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/vdbe/execute.rs","lineNumber":1422,"sourceCode":"                Ok(OpenedBTree::Plain(btree_cursor))\n            }\n        };\n\n    match cursor_type {\n        CursorType::MaterializedView(_, view_mutex) => {\n            // This is a materialized view with storage\n            // Create btree cursor for reading the persistent data\n\n            let btree_cursor = BTreeCursor::new_table(\n                pager.clone(),\n                maybe_transform_root_page_to_positive(mv_store.as_ref(), *root_page),\n                num_columns,\n            )\n            .into_boxed();\n            let cursor = maybe_promote_to_mvcc_cursor(btree_cursor, MvccCursorType::Table)?;\n\n            // Get the view name and look up or create its transaction state\n            let view_name = view_mutex.lock().name().to_string();\n            let tx_state = program\n                .connection\n                .view_transaction_states\n                .get_or_create(&view_name);\n\n            // Create materialized view cursor with this view's transaction state\n            let mv_cursor = crate::incremental::cursor::MaterializedViewCursor::new(\n                cursor.into_dyn(),\n                view_mutex.clone(),\n                pager,\n                tx_state,\n            )?;\n\n            cursors\n                .get_mut(*cursor_id)\n                .expect(\"cursor_id should be valid\")\n                .replace(Cursor::new_materialized_view(mv_cursor));\n        }","sourceCodeStart":1404,"sourceCodeEnd":1440,"githubUrl":"https://github.com/tursodatabase/turso/blob/8d4a589f8d13ac184700d2a8f724f27e1995be3b/core/vdbe/execute.rs#L1404-L1440","documentation":"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.","triggerScenarios":"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.","commonSituations":"Queries combining VALUES clauses, co-routine subqueries, or CTE materialization with ordinary table scans; engine versions where cursor allocation was refactored.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// audit a compiled program before first execution: OpenRead must target btree-backed cursors\nfn audit_open_reads(program: &Program) -> Result<()> {\n    for insn in &program.insns {\n        if let Insn::OpenRead { cursor_id, .. } = insn {\n            match program.cursor_ref.get(*cursor_id).map(|(_, t)| t) {\n                Some(CursorType::BTreeTable(_)) | Some(CursorType::BTreeIndex(_))\n                | Some(CursorType::MaterializedView(..)) => {}\n                other => crate::bail_parse_error!(\"OpenRead targets non-btree cursor ({other:?})\"),\n            }\n        }\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["vdbe","executor","cursor-type","pseudo-cursor","panic","runtime"],"backgroundTag":"bytecode-cursor-type-mismatch","analyzedSha":"8d4a589f8d13ac184700d2a8f724f27e1995be3b","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}