From c3f304a67cd0a7f43c536a2ce53599e4acabf7f2 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Fri, 6 Dec 2024 12:48:54 +0100 Subject: [PATCH] address phoebe's review --- crates/core/src/db/datastore/locking_tx_datastore/mut_tx.rs | 3 ++- crates/table/src/btree_index.rs | 4 +++- crates/table/src/btree_index/multimap.rs | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/core/src/db/datastore/locking_tx_datastore/mut_tx.rs b/crates/core/src/db/datastore/locking_tx_datastore/mut_tx.rs index e44cfd13af..54c5c2080a 100644 --- a/crates/core/src/db/datastore/locking_tx_datastore/mut_tx.rs +++ b/crates/core/src/db/datastore/locking_tx_datastore/mut_tx.rs @@ -1261,7 +1261,8 @@ impl MutTxId { } // Pacify the borrow checker. - // SAFETY: `ptr` came from `tx_table.insert` just now without any interleaving calls. + // SAFETY: `tx_row_ptr` came from `tx_table.insert` just now + // without any interleaving `&mut` calls that could invalidate the pointer. let tx_row_ref = unsafe { tx_table.get_row_ref_unchecked(tx_blob_store, tx_row_ptr) }; // (2) The `tx_row_ref` did not violate a unique constraint *within* the `tx_table`, diff --git a/crates/table/src/btree_index.rs b/crates/table/src/btree_index.rs index 2bc00574c8..96e62bf42b 100644 --- a/crates/table/src/btree_index.rs +++ b/crates/table/src/btree_index.rs @@ -202,7 +202,9 @@ impl TypedIndex { /// or may insert a nonsense value into the index. /// Note, however, that it will not invoke undefined behavior. /// - /// Assumes that this is a unique constraint and returns `Ok(Some(existing_row))` if it's violated. + /// Assumes that this is a unique constraint + /// and returns `Ok(Some(existing_row))` if it's violated. + /// The index is not inserted to in that case. fn insert_unique(&mut self, cols: &ColList, row_ref: RowRef<'_>) -> Result, InvalidFieldError> { fn insert_at_type( this: &mut Index, diff --git a/crates/table/src/btree_index/multimap.rs b/crates/table/src/btree_index/multimap.rs index 699311e52c..7e3e289af9 100644 --- a/crates/table/src/btree_index/multimap.rs +++ b/crates/table/src/btree_index/multimap.rs @@ -39,7 +39,8 @@ impl MultiMap { /// Inserts the relation `key -> val` to this multimap. /// - /// Returns back the value if the `key` was already present in the map. + /// If `key` was already present in the map, does not add an association with `val`. + /// Returns the existing associated value instead. pub fn insert_unique(&mut self, key: K, val: V) -> Option<&V> { // TODO(perf, centril): don't use a multimap at all for unique indices. let vals = self.map.entry(key).or_default();