From b3be21f472421e581f589ed659f8ddef4ceb365a Mon Sep 17 00:00:00 2001 From: Jussi Saurio Date: Tue, 14 Oct 2025 16:15:20 +0300 Subject: [PATCH] Do not count ephemeral table INSERTs as changes --- core/translate/result_row.rs | 4 +++- core/vdbe/execute.rs | 5 ++++- core/vdbe/insn.rs | 6 ++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/core/translate/result_row.rs b/core/translate/result_row.rs index c087a0abf..2ec60e641 100644 --- a/core/translate/result_row.rs +++ b/core/translate/result_row.rs @@ -133,7 +133,9 @@ pub fn emit_result_row_and_limit( key_reg: result_columns_start_reg + (plan.result_columns.len() - 1), // Rowid reg is the last register record_reg, // since we are not doing an Insn::NewRowid or an Insn::NotExists here, we need to seek to ensure the insertion happens in the correct place. - flag: InsertFlags::new().require_seek(), + flag: InsertFlags::new() + .require_seek() + .is_ephemeral_table_insert(), table_name: table.name.clone(), }); } diff --git a/core/vdbe/execute.rs b/core/vdbe/execute.rs index 82b850ec1..2c4e159d7 100644 --- a/core/vdbe/execute.rs +++ b/core/vdbe/execute.rs @@ -5892,7 +5892,10 @@ pub fn op_insert( let cursor = cursor.as_btree_mut(); cursor.root_page() }; - if root_page != 1 && table_name != "sqlite_sequence" { + if root_page != 1 + && table_name != "sqlite_sequence" + && !flag.has(InsertFlags::EPHEMERAL_TABLE_INSERT) + { state.op_insert_state.sub_state = OpInsertSubState::UpdateLastRowid; } else { let schema = program.connection.schema.read(); diff --git a/core/vdbe/insn.rs b/core/vdbe/insn.rs index a774edad5..bf7bf89b3 100644 --- a/core/vdbe/insn.rs +++ b/core/vdbe/insn.rs @@ -112,6 +112,7 @@ pub struct InsertFlags(pub u8); impl InsertFlags { pub const UPDATE_ROWID_CHANGE: u8 = 0x01; // Flag indicating this is part of an UPDATE statement where the row's rowid is changed pub const REQUIRE_SEEK: u8 = 0x02; // Flag indicating that a seek is required to insert the row + pub const EPHEMERAL_TABLE_INSERT: u8 = 0x04; // Flag indicating that this is an insert into an ephemeral table pub fn new() -> Self { InsertFlags(0) @@ -130,6 +131,11 @@ impl InsertFlags { self.0 |= InsertFlags::UPDATE_ROWID_CHANGE; self } + + pub fn is_ephemeral_table_insert(mut self) -> Self { + self.0 |= InsertFlags::EPHEMERAL_TABLE_INSERT; + self + } } #[derive(Clone, Copy, Debug)]