From 08be906bb126dde96bb4d2526928ea38755982ba Mon Sep 17 00:00:00 2001 From: meteorgan Date: Fri, 4 Jul 2025 17:54:48 +0800 Subject: [PATCH] return early if index is not found in op_idx_delete --- core/vdbe/execute.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/core/vdbe/execute.rs b/core/vdbe/execute.rs index 9e77a9afd..ca8678a63 100644 --- a/core/vdbe/execute.rs +++ b/core/vdbe/execute.rs @@ -4378,7 +4378,7 @@ pub fn op_idx_delete( ); match &state.op_idx_delete_state { Some(OpIdxDeleteState::Seeking(record)) => { - { + let found = { let mut cursor = state.get_cursor(*cursor_id); let cursor = cursor.as_btree_mut(); let found = return_if_io!( @@ -4390,6 +4390,21 @@ pub fn op_idx_delete( cursor.root_page(), record ); + found + }; + + if !found { + // If P5 is not zero, then raise an SQLITE_CORRUPT_INDEX error if no matching index entry is found + // Also, do not raise this (self-correcting and non-critical) error if in writable_schema mode. + if *raise_error_if_no_matching_entry { + return Err(LimboError::Corrupt(format!( + "IdxDelete: no matching index entry found for record {:?}", + record + ))); + } + state.pc += 1; + state.op_idx_delete_state = None; + return Ok(InsnFunctionStepResult::Step); } state.op_idx_delete_state = Some(OpIdxDeleteState::Verifying); } @@ -4399,9 +4414,7 @@ pub fn op_idx_delete( let cursor = cursor.as_btree_mut(); return_if_io!(cursor.rowid()) }; - - // If P5 is not zero, then raise an SQLITE_CORRUPT_INDEX error if no matching index entry is found - // Also, do not raise this (self-correcting and non-critical) error if in writable_schema mode. + if rowid.is_none() && *raise_error_if_no_matching_entry { return Err(LimboError::Corrupt(format!( "IdxDelete: no matching index entry found for record {:?}",