Do not count ephemeral table INSERTs as changes

This commit is contained in:
Jussi Saurio
2025-10-14 16:15:20 +03:00
parent 87434b8a72
commit b3be21f472
3 changed files with 13 additions and 2 deletions

View File

@@ -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(),
});
}

View File

@@ -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();

View File

@@ -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)]