Skip to content

Conversation

@Centril
Copy link
Contributor

@Centril Centril commented Jan 21, 2026

Description of Changes

This PR:

  • Does some minor readability improvements and organization to indices.
  • Adds Index::merge_from(&mut self, src: Self), which merges src into self. This will be used to speed up merging of transactions.
  • Makes Index::insert to exploit a property for improved performance in itself and in Index::merge_from.
  • Adds a trait invariant stating that no (key, ptr) occurs twice. This was always the case, but now it is a safety invariant and exploited for performance. This then is bubbled up to MutTxId and friends.

API and ABI breaking changes

None

Expected complexity level and risk

4 - This touches both Index::insert, Table, and MutTxId in terms of unsafe.

Testing

  • Debug assertions are added for the unsafety in Index::insert.
  • A new proptest merge_from_is_union is added that comprehensively exercises Index::{insert, merge_from, can_merge} together and for all index kinds and uniqueness.

@Centril Centril force-pushed the centril/index-merge-from branch from f8b2d98 to 923c9fb Compare January 21, 2026 18:45
@Centril Centril force-pushed the centril/index-merge-from branch from 923c9fb to 5b5e4f9 Compare January 21, 2026 18:47
@Centril Centril force-pushed the centril/index-merge-from branch from 4dd9b9b to 3acf683 Compare January 21, 2026 22:14
@Centril Centril requested a review from coolreader18 January 21, 2026 22:14
@Centril Centril force-pushed the centril/index-merge-from branch from 83357bd to 31c0059 Compare January 22, 2026 08:56
@Centril Centril force-pushed the centril/index-merge-from branch from 31c0059 to 1677b36 Compare January 22, 2026 11:13
/// The relation `key -> ptr` must not exist in the index.
/// Note that inserting `key -> ptr_other`,
/// where `ptr != ptr_other`, is legal.
fn insert_maybe_despecialize(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this method not marked unsafe, when it has a Safety section in its docs and you're calling it with an unsafe block?


#[cfg(test)]
fn insert_for_test(&mut self, key: Self::Key, ptr: RowPointer) -> Result<(), RowPointer> {
// SAFETY: proof obligation checked inside the method for debug builds.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does cfg(test) necessarily imply cfg(debug_assertions)?

Comment on lines +136 to +137
// SAFETY: The intersection is empty, so `dst ++ src` is also a set.
dst.append(&mut src);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to potentially upgrade here to a Self::Large if the two sets combined meet some size threshold?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants