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

Support UUID v7 #24079

Open
kibertoad opened this issue May 5, 2024 · 4 comments
Open

Support UUID v7 #24079

kibertoad opened this issue May 5, 2024 · 4 comments
Labels
kind/feature A request for a new feature. team/client Issue for team Client. team/schema Issue for team Schema. topic: uuid

Comments

@kibertoad
Copy link

kibertoad commented May 5, 2024

Problem

Efficient cursor-based pagination relies on lexicographical and chronological sorting support, which is not provided by older UUID versions.

Suggested solution

UUID v7 fills a big gap in the database space by addressing the need for the lexicographically and chronologically sortable identifiers. CUID and ULID are strong contenders, but they come with a significant adoption friction involved, due to not being UUID-compatible, and hence not qualifying as a drop-in replacement. Also Prisma currently doesn't support ULID at all, and for CUID only deprecated version 1 is supported.

Implementing UUID v7 support on Prisma level would have a huge impact for addressing this need and enabling the adoption of the new standard. Since it is storage-compatible with UUID v4, it could already be adopted in existing databases with very little changes.

UUID v7 was already published as an RFC, see https://www.rfc-editor.org/info/rfc9562, so it should be safe to implement it already.

There is an existing Rust implementation: https://crates.io/crates/uuid7 - it implements the published RFC, and can be used to provide support.

Usage syntax could be identical to the existing CUID support:

  id   String @id @default(uuidv7())  @db.Uuid

Alternatives

  • Implement new spec-compliant v7 implementation from a scratch - that would be extra work for unclear benefits.
  • Wait till databases implement UUID v7 support natively - since approval is going to happen past the PostgreSQL feature freeze period, it is likely to take at least two years until this is going to happen.

Additional context

@sergeyprokhorenko
Copy link

sergeyprokhorenko commented May 5, 2024

UUIDv7 with exactly the same structure as the existing implementation in Rust, has already been implemented in ClickHouse DBMS.

But ClickHouse ensures monotonicity even for multithreading, which is impossible to achieve in Rust in isolation from the DBMS. The PostgreSQL proposal does not provide monotonicity for multithreading due to complexity.

I recommend using an existing implementation in Rust. Someday in the future it will be possible to replace it with some implementation that ensures monotonicity for multithreading.

For generation on the client side, I recommend using this implementation from the same author.

@Druue Druue added kind/feature A request for a new feature. team/schema Issue for team Schema. team/client Issue for team Client. topic: uuid labels May 8, 2024
@kibertoad
Copy link
Author

rfc-9562 was published (https://www.rfc-editor.org/info/rfc9562), I've updated the ticket accordingly

@kibertoad
Copy link
Author

https://crates.io/crates/uuid7 was updated to clarify being in sync with the published RFC, I've edited the issue description accordingly.

@mcuelenaere
Copy link

I've taken a stab at this at prisma/prisma-engines#4877

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature A request for a new feature. team/client Issue for team Client. team/schema Issue for team Schema. topic: uuid
Projects
None yet
Development

No branches or pull requests

4 participants