Skip to content

Add support for bytes key btree indices#4733

Merged
Centril merged 14 commits intomasterfrom
centril/range-compat-bytes-key
Apr 23, 2026
Merged

Add support for bytes key btree indices#4733
Centril merged 14 commits intomasterfrom
centril/range-compat-bytes-key

Conversation

@Centril
Copy link
Copy Markdown
Contributor

@Centril Centril commented Mar 31, 2026

Description of Changes

Add support for btree indices where the keys are encoded byte strings for e.g., multi-column indices of no-unbounded-types (arrays and strings) that aren't floats.

The main interesting stuff in this PR is in bytes_key.rs which defines RangeCompatBytesKey, a type that is derived from BytesKey, by converting little-endian encoded integers to big-endian. Signed integers are now also supported, but floats are not. table_index/mod.rs also includes a bunch of interesting stuff.

API and ABI breaking changes

Technically this fixes pre-existing bugs in the handling of Excluded ranges for multi-col indices.

Expected complexity level and risk

2?

Testing

  • A proptest order_in_bsatn_is_preserved is now adjusted and enabled to exercise the ordering of RangeCompatBytesKey.
  • A proptest btree_multi_col_range_scans_work is added to check the behavior of range scans on multi-col indices.

Copy link
Copy Markdown
Collaborator

@joshua-spacetime joshua-spacetime left a comment

Choose a reason for hiding this comment

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

I think more testing is needed for this patch.

Comment thread crates/table/src/table_index/mod.rs Outdated
Comment thread crates/table/src/table_index/bytes_key.rs
@Centril Centril force-pushed the centril/range-compat-bytes-key branch from 0367d60 to 58644fe Compare April 8, 2026 17:16
@Centril Centril changed the base branch from master to centril/table-index-iter April 8, 2026 17:16
Base automatically changed from centril/table-index-iter to master April 8, 2026 21:48
@Centril Centril force-pushed the centril/range-compat-bytes-key branch from 58644fe to e649f64 Compare April 9, 2026 12:12
@Centril Centril requested a review from joshua-spacetime April 9, 2026 12:19
Comment thread crates/table/src/table_index/mod.rs Outdated
@Centril Centril force-pushed the centril/range-compat-bytes-key branch from 047db8f to 1db5d12 Compare April 15, 2026 21:48
Ludv1gL added a commit to Ludv1gL/SpacetimeDB that referenced this pull request Apr 20, 2026
…abs#4733

The uniqueness-conversion macro has `HashBytesKey{8,24,56,120}` entries but no btree
counterparts. Adding them needs `RangeCompatBytesKey` (a range-compatible ordering over
bytes keys), which is introduced in clockworklabs#4733. A TODO inside the
btree arm of `define_uniqueness_conversions!` makes the dependency explicit; the
follow-up will also revisit the `HashBytesKey*` closures flagged in the review.

Addresses review comment at table_index/mod.rs:1688.
@Centril Centril added this pull request to the merge queue Apr 23, 2026
Merged via the queue into master with commit e7294bf Apr 23, 2026
31 of 32 checks passed
@Centril Centril deleted the centril/range-compat-bytes-key branch April 23, 2026 08:33
Ludv1gL added a commit to Ludv1gL/SpacetimeDB that referenced this pull request Apr 23, 2026
…abs#4733

The uniqueness-conversion macro has `HashBytesKey{8,24,56,120}` entries but no btree
counterparts. Adding them needs `RangeCompatBytesKey` (a range-compatible ordering over
bytes keys), which is introduced in clockworklabs#4733. A TODO inside the
btree arm of `define_uniqueness_conversions!` makes the dependency explicit; the
follow-up will also revisit the `HashBytesKey*` closures flagged in the review.

Addresses review comment at table_index/mod.rs:1688.
Ludv1gL added a commit to Ludv1gL/SpacetimeDB that referenced this pull request Apr 23, 2026
Thread the index's key type through `TypedIndex::iter_duplicates` and the
`define_uniqueness_conversions!` macro so bytes-keyed variants can round-
trip their keys back to `AlgebraicValue` via `TypedIndexKey`'s existing
`decode_algebraic_value` path.

- Add `BTreeBytesKey{8,16,32,64,128} <=> UniqueBTreeBytesKey*` conversion
  pairs to the macro, now unblocked by upstream clockworklabs#4733 providing
  `RangeCompatBytesKey`.
- Replace the `HashBytesKey{8,24,56,120}` placeholder closures (which
  debug-stringified the raw bytes into `AlgebraicValue::String`) with the
  correct `TypedIndexKey::BytesKey*H(*k).into_algebraic_value(ty)`
  round-trip; reviewer-requested "via `IndexKey` → `AlgebraicValue`"
  shape.
- Drop the `TODO(clockworklabs#4733)` comment and grow all closures to accept the
  `&AlgebraicType` key-type parameter (ignored by scalar variants).
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.

2 participants