MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / find_same_row_via_pointer_map

Method find_same_row_via_pointer_map

crates/table/src/table.rs:1081–1104  ·  view source on GitHub ↗

Using the [`PointerMap`], searches `target_table` for a row equal to `needle_table[needle_ptr]`. Rows are compared for equality by [`eq_row_in_page`]. Lazily computes the row hash if needed and returns it, or uses the one provided, if any. Used for detecting set-semantic duplicates when inserting into tables without any unique constraints. Does nothing and always returns `None` if `target_tabl

(
        target_table: &Table,
        needle_table: &Table,
        needle_bs: &dyn BlobStore,
        needle_ptr: RowPointer,
        row_hash: Option<RowHash>,
    )

Source from the content-addressed store, hash-verified

1079 /// - `target_table` and `needle_table` must have the same `row_layout`.
1080 /// - `needle_table.is_row_present(needle_ptr)`.
1081 pub unsafe fn find_same_row_via_pointer_map(
1082 target_table: &Table,
1083 needle_table: &Table,
1084 needle_bs: &dyn BlobStore,
1085 needle_ptr: RowPointer,
1086 row_hash: Option<RowHash>,
1087 ) -> (RowHash, Option<RowPointer>) {
1088 let row_hash = row_hash.unwrap_or_else(|| {
1089 // SAFETY: Caller promised that `needle_table.is_row_present(needle_ptr)`.
1090 let row_ref = unsafe { needle_table.get_row_ref_unchecked(needle_bs, needle_ptr) };
1091 row_ref.row_hash()
1092 });
1093
1094 // Scan all the frow pointers with `row_hash` in the `committed_table`.
1095 let row_ptr = target_table.pointers_for(row_hash).iter().copied().find(|&target_ptr| {
1096 // SAFETY:
1097 // - Caller promised that the row layouts were the same.
1098 // - We know `target_ptr` exists, as it was found in a pointer map.
1099 // - Caller promised that `needle_ptr` is valid for `needle_table`.
1100 unsafe { Self::eq_row_in_page(target_table, target_ptr, needle_table, needle_ptr) }
1101 });
1102
1103 (row_hash, row_ptr)
1104 }
1105
1106 /// Returns whether the row `target_ptr` in `target_table`
1107 /// is exactly equal to the row `needle_ptr` in `needle_ptr`.

Callers

nothing calls this directly

Calls 6

eq_row_in_pageFunction · 0.85
get_row_ref_uncheckedMethod · 0.80
row_hashMethod · 0.80
iterMethod · 0.65
findMethod · 0.45
pointers_forMethod · 0.45

Tested by

no test coverage detected