Delete a row by PK value. Returns WAL record to persist. Looks up PK in the index to find the segment + row, then marks the row in the segment's delete bitmap.
(&mut self, pk_value: &Value)
| 167 | /// Looks up PK in the index to find the segment + row, then marks |
| 168 | /// the row in the segment's delete bitmap. |
| 169 | pub fn delete(&mut self, pk_value: &Value) -> Result<MutationResult, ColumnarError> { |
| 170 | let pk_bytes = encode_pk(pk_value); |
| 171 | |
| 172 | let location = self |
| 173 | .pk_index |
| 174 | .get(&pk_bytes) |
| 175 | .copied() |
| 176 | .ok_or(ColumnarError::PrimaryKeyNotFound)?; |
| 177 | |
| 178 | // Generate WAL record BEFORE applying. |
| 179 | let wal = ColumnarWalRecord::DeleteRows { |
| 180 | collection: self.collection.clone(), |
| 181 | segment_id: location.segment_id, |
| 182 | row_indices: vec![location.row_index], |
| 183 | }; |
| 184 | |
| 185 | // Mark in delete bitmap. |
| 186 | let bitmap = self.delete_bitmaps.entry(location.segment_id).or_default(); |
| 187 | bitmap.mark_deleted(location.row_index); |
| 188 | |
| 189 | // Remove from PK index. |
| 190 | self.pk_index.remove(&pk_bytes); |
| 191 | |
| 192 | Ok(MutationResult { |
| 193 | wal_records: vec![wal], |
| 194 | }) |
| 195 | } |
| 196 | |
| 197 | /// Update a row by PK: DELETE old + INSERT new. |
| 198 | /// |