You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: Handle IVM old record capture when REQUIRE_SEEK flag is set
Panic: "to capture old record accurately, we must be located at the
correct position in the table"
Add SeekThenCapture state to OpInsertSubState to handle the case where
both REQUIRE_SEEK is set AND there are dependent materialized views.
Previously this combination caused a panic because the code assumed
these conditions were mutually exclusive.
The new state first seeks to the correct position, then captures the
old record (if any) for incremental view maintenance before proceeding
with the insert. This fixes INSERT OR REPLACE on tables with dependent
materialized views.
/// If this insert overwrites a record, capture the old record for incremental view maintenance.
6779
+
/// If cursor is already positioned (no REQUIRE_SEEK), capture directly.
6780
+
/// If REQUIRE_SEEK is set, transition to Seek first.
6779
6781
MaybeCaptureRecord,
6780
6782
/// Seek to the correct position if needed.
6781
6783
/// In a table insert, if the caller does not pass InsertFlags::REQUIRE_SEEK, they must ensure that a seek has already happened to the correct location.
6782
6784
/// This typically happens by invoking either Insn::NewRowid or Insn::NotExists, because:
6783
6785
/// 1. op_new_rowid() seeks to the end of the table, which is the correct insertion position.
6784
6786
/// 2. op_not_exists() seeks to the position in the table where the target rowid would be inserted.
6785
6787
Seek,
6788
+
/// Capture the old record at the current cursor position for IVM.
6789
+
/// The cursor must already be positioned (by a prior seek or by NotExists/NewRowid).
6790
+
CaptureRecord,
6786
6791
/// Insert the row into the table.
6787
6792
Insert,
6788
6793
/// Updating last_insert_rowid may return IO, so we need a separate state for it so that we don't
@@ -6812,24 +6817,18 @@ pub fn op_insert(
6812
6817
loop{
6813
6818
match&state.op_insert_state.sub_state{
6814
6819
OpInsertSubState::MaybeCaptureRecord => {
6815
-
let schema = program.connection.schema.read();
6816
-
let dependent_views = schema.get_dependent_materialized_views(table_name);
0 commit comments