Skip to content

Fix variant in UUIDv7#87

Merged
dverite merged 6 commits intoqonto:mainfrom
vmercierfr:postgresql18
Apr 9, 2026
Merged

Fix variant in UUIDv7#87
dverite merged 6 commits intoqonto:mainfrom
vmercierfr:postgresql18

Conversation

@vmercierfr
Copy link
Copy Markdown
Collaborator

@vmercierfr vmercierfr commented Apr 3, 2026

Objective

Fix variant field in UUIDv7 generated by PostgreSQL partition Manager

Why

PPM is currently generating UUIDv7 with variant field set to 0, which is reserved for Network Computing System (NCS) backward compatibility.

UUIDv7 should be use lowest variant as boundary for partition to comply with RFC9562. PostgreSQL implemented the RFC9562 and expect variant 8 (PostgreSQL 18 source code)

In current implementation, UUIDv7 are not valid so timestamp could not be extracted

postgres=# select uuid_extract_timestamp('019d50a3-b800-7000-0000-000000000000');
 uuid_extract_timestamp 
------------------------
 
(1 row)

With new implementation, PostgreQL built-in uuid_extract_timestamp() function correctly resolve UUIDv7 timestamp

postgres=# select uuid_extract_timestamp('019d50a3-b800-7000-8000-000000000000');
 uuid_extract_timestamp 
------------------------
 2026-04-03 00:00:00+00
(1 row)

How

  • Update local development environment to use PostgreSQL 18
  • Update FromTime() function to generate UUIDv7 with variant field set to 8 (lower bound)
  • Update tests and local environments

Release

Release v1.2.0

Signed-off-by: Vincent Mercier <vincmer@amazon.com>
Signed-off-by: Vincent Mercier <vincmer@amazon.com>
Signed-off-by: Vincent Mercier <vincmer@amazon.com>
Signed-off-by: Vincent Mercier <vincmer@amazon.com>
Signed-off-by: Vincent Mercier <vincmer@amazon.com>
Signed-off-by: Vincent Mercier <vincmer@amazon.com>
@vmercierfr
Copy link
Copy Markdown
Collaborator Author

@dverite as discussed during PostgreSQL meetup, the variant is not valid.

This change do not brake existing partitioning as previous implementation was allowing invalid UUIDv7 and should not be used. However for sake of clarity, I'll add a migration script, but feel free to have a first look.

@vmercierfr vmercierfr added the bug Something isn't working label Apr 3, 2026
Copy link
Copy Markdown
Collaborator

@dverite dverite left a comment

Choose a reason for hiding this comment

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

LGTM
About it being a bug, it's not that bad. The uuid comparison function in postgres does not care about the semantics of the bit fields and the conformance to RFC9562.
So when partition boundaries have the variant bits to 00 instead of 10, aside from the fact that they cannot be passed directly to uuid_extract_timestamp(), it does not seem to make any significant difference for the rest.

@dverite dverite merged commit fc6e0fb into qonto:main Apr 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants