Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust SDK: Actual client-side indices for unique constraints #1909

Merged
merged 14 commits into from
Nov 29, 2024

Conversation

gefjon
Copy link
Contributor

@gefjon gefjon commented Oct 25, 2024

Description of Changes

Based on #1900 , which in turn is based on #1897 .

Updates unique constraint .find methods on clients to be backed by actual indices, rather than O(n) full scans. Specifically, unique indices on clients are HashMaps, whereas on the server they are BTreeMaps. This is because:

  • It was easier given that I haven't implemented client-side non-unique indices yet.
  • We artifically restrict filter methods to a small set of known types, all of which are both Ord and Hash, so there's not much difference.
  • HashMap is marginally more efficient, I guess?

Associated changes:

  • Codegen now includes a mechanism for registering each table in the ClientCache during DbConnectionBuilder::build, where previously they were lazily added the first time a row was inserted into them. This is necessary so that the codegen can install unique indices up front.
  • The codegen actually discriminates on filterable types now, and does not emit indices or access methods for unique columns of non-filterable types.

API and ABI breaking changes

Rust SDK codegen changes and will require re-running spacetime generate. Unique filter methods on columns of non-filterable types which were erroneously generated prior to now are no longer generated, so clients which depend on them will break.

Expected complexity level and risk

2 - codegen's always fiddly, but slapping a few extra HashMaps around is pretty simple.

Testing

  • Rust SDK tests still work, and rely on the .find methods behaving correctly.
  • Measure or assert performance somehow? Frankly I don't know how much we care.

This turns out to be effectively a prerequisite for client-side indices.
Storing indexes in a type-erased way
while making them `Clone` for storage in `im::HashMap`
is likely possible, but it's at least very challenging and complex.
Given that we no longer actually need the concurrent persistence offered by `im::HashMap`,
it seems easier to just revert to using `std::collections::HashMap`.
As opposed to having a bunch of `#[doc(hidden)] pub mod`s
with a variety of different purposes.
This means we can reorganize the SDK internals without breaking codegen.
Updates unique constraint `.find` methods on clients to be backed by actual indices,
rather than O(n) full scans.
Specifically, unique indices on clients are `HashMap`s,
whereas on the server they are `BTreeMap`s.
This is because:
- It was easier given that I haven't implemented client-side non-unique indices yet.
- We artifically restrict filter methods to a small set of known types,
  all of which are both `Ord` and `Hash`, so there's not much difference.
- `HashMap` is marginally more efficient, I guess?

Associated changes:
- Codegen now includes a mechanism for registering each table in the `ClientCache`
  during `DbConnectionBuilder::build`, where previously they were lazily added
  the first time a row was inserted into them.
  This is necessary so that the codegen can install unique indices up front.
- The codegen actually discriminates on filterable types now,
  and does not emit indices or access methods for unique columns of non-filterable types.
@gefjon gefjon self-assigned this Oct 25, 2024
@gefjon gefjon requested a review from Centril October 25, 2024 16:47
@gefjon
Copy link
Contributor Author

gefjon commented Nov 29, 2024

Merging this and closing its two parents, rather than going through the rigamarole of merging each individually and rebasing.

@gefjon gefjon added this pull request to the merge queue Nov 29, 2024
Merged via the queue into master with commit 80dff96 Nov 29, 2024
7 of 8 checks passed
@bfops bfops added the api-break A PR that makes an API breaking change label Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-break A PR that makes an API breaking change enhancement New feature or request release-1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants