tursodatabase/turso · error

unexpected cursor type

Error message

unexpected cursor type

What it means

Inside op_column's resumable state machine, the Rowid state reads the current rowid from the index cursor before seeking the paired table cursor. The panic fires when that cursor is neither Cursor::BTree nor Cursor::IndexMethod at runtime — the bytecode arranged a rowid fetch through a cursor kind that cannot supply one (sorter, pseudo, virtual table). An internal program inconsistency hit mid-execution.

Solutions

  1. Report with SQL and EXPLAIN — the index-cursor slot holds an incompatible kind at runtime
  2. Force a different plan (drop/disable the index or use NOT INDEXED) so the paired-cursor path is not used
  3. Rewrite the index-driven lookup as a join to change the access path
  4. Upgrade
Defensive patterns

Strategy: type-guard

Validate before calling

// before entering the paired index/table column path, verify the index slot kind
if !matches!(
    program.cursor_ref.get(index_cursor_id).map(|(_, t)| t),
    Some(CursorType::BTreeIndex(_)) | Some(CursorType::IndexMethod(..))
) {
    crate::bail_parse_error!("index cursor {index_cursor_id} cannot supply a rowid");
}

Type guard

fn rowid_capable(t: &CursorType) -> bool {
    matches!(t, CursorType::BTreeIndex(_) | CursorType::IndexMethod(..))
}

Prevention

When it happens

Trigger: Column-extraction plans that pair an index cursor with a table cursor (index scan then row lookup) where the index slot actually holds a sorter/pseudo/vtab cursor — typically after cursor renumbering, or when index-method cursors are mis-tagged in the plan.

Common situations: Plan flips between covering-index and table-lookup access paths; custom index-method features; engine upgrades changing index cursor handling.

Related errors


AI-assisted analysis of tursodatabase/turso@8d4a589f8d (2026-08-20). Data as JSON: /api/errors/fbfa2f9393df0871. Report an issue: GitHub.

Appendix: source

Thrown at core/vdbe/execute.rs:2029

            op_column_range_fetch(program, state, *cursor_id, *start_column, *dest, defaults)?;
        if matches!(result, InsnFunctionStepResult::Step) {
            state.pc += 1;
        }
        return Ok(result);
    }
    op_column_deferred(
        program,
        state,
        *cursor_id,
        ColumnFetch::Range {
            start_column: *start_column,
            dest: *dest,
            defaults,
        },
    )
}

/// What a Column-family instruction fetches once the cursor is positioned.
#[derive(Clone, Copy)]
enum ColumnFetch<'a> {
    /// A single column.
    Single {
        column: usize,
        dest: usize,
        default: &'a Option<Value>,
    },
    /// A range of consecutive columns to be copied to consecutive destination registers.
    Range {
        start_column: usize,
        dest: usize,
        defaults: &'a [Option<Value>],
    },
}

impl ColumnFetch<'_> {
    /// Writes NULL to every destination register of this fetch.

View on GitHub (pinned to 8d4a589f8d)