From cdaea7f27440535c851c2a18a3eeee263aaff8c5 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Mon, 11 Aug 2025 12:26:11 +0300 Subject: [PATCH] core/vdbe: Make apply_view_deltas() return early if views are disabled Currently, we have a borrow problem because parse_schema_rows() already borrows `schema`, but then `apply_view_deltas` does the same: ``` thread 'main' panicked at core/vdbe/mod.rs:450:49: already mutably borrowed: BorrowError stack backtrace: 0: __rustc::rust_begin_unwind at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:697:5 1: core::panicking::panic_fmt at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/panicking.rs:75:14 2: core::cell::panic_already_mutably_borrowed at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/cell.rs:799:5 3: core::cell::RefCell::borrow at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/cell.rs:987:25 4: turso_core::vdbe::Program::apply_view_deltas at ./core/vdbe/mod.rs:450:26 5: turso_core::vdbe::Program::commit_txn at ./core/vdbe/mod.rs:468:9 6: turso_core::vdbe::execute::op_halt at ./core/vdbe/execute.rs:1954:15 7: turso_core::vdbe::Program::step at ./core/vdbe/mod.rs:430:19 8: turso_core::Statement::step at ./core/lib.rs:1914:23 9: turso_core::util::parse_schema_rows at ./core/util.rs:91:15 10: turso_core::Connection::parse_schema_rows::{{closure}} at ./core/lib.rs:1518:17 11: turso_core::Connection::with_schema_mut at ./core/lib.rs:1625:9 12: turso_core::Connection::parse_schema_rows at ./core/lib.rs:1515:9 ``` However, this is a read transaction and views are not even enabled, let's just make `apply_view_deltas()` return early if there's no processing needed, to skip the schema borrow altogether. --- core/vdbe/mod.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/vdbe/mod.rs b/core/vdbe/mod.rs index a31105c1d..259767031 100644 --- a/core/vdbe/mod.rs +++ b/core/vdbe/mod.rs @@ -444,6 +444,10 @@ impl Program { #[instrument(skip_all, level = Level::DEBUG)] fn apply_view_deltas(&self, rollback: bool) { + if self.connection.view_transaction_states.borrow().is_empty() { + return; + } + let tx_states = self.connection.view_transaction_states.take(); if !rollback {