Skip to content
/ server Public

MDEV-32637 Implement native UUID7 function#3093

Closed
StefanoPetrilli wants to merge 2 commits intoMariaDB:11.6from
StefanoPetrilli:11.5-MDEV-32637
Closed

MDEV-32637 Implement native UUID7 function#3093
StefanoPetrilli wants to merge 2 commits intoMariaDB:11.6from
StefanoPetrilli:11.5-MDEV-32637

Conversation

@StefanoPetrilli
Copy link
Contributor

@StefanoPetrilli StefanoPetrilli commented Feb 29, 2024

  • The Jira issue number for this PR is: MDEV-32637

Description

MariaDB provides the UUID method that generates UUID v1, however, UUID v1 generates non-linear UUIDS that will spread data across different linear partitions based on key or hash.

The new UUID7 (https://uuid7.com/) will guarantee that continuous records are time-sorted and a good collision resistance.

The main advantage of the UUID7 function is that it will allow MariaDB to avoid the limitation of using a unique combined primary key for time series records, where a unique ID and a date are required to create key/hash partitions. With UUID7 is possible to only use the key as ID and time reference.

Release Notes

Adds the function:
UUIDv7(): returns a UUIDv7

How can this PR be tested?

This PR adds automatic tests that partially test the new functions.

I am not aware of an easy way to change the time retrieved by my_hrtime(), hence, I could not write automatic tests to verify that the UUIDs generated are monotonic.
I am open to suggestions on how to accomplish that.

Basing the PR against the correct MariaDB version

  • This is a new feature and the PR is based against the latest MariaDB development branch.
  • This is a bug fix and the PR is based against the earliest maintained branch in which the bug can be reproduced.

PR quality check

  • I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
  • For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.

@CLAassistant
Copy link

CLAassistant commented Feb 29, 2024

CLA assistant check
All committers have signed the CLA.

@StefanoPetrilli StefanoPetrilli force-pushed the 11.5-MDEV-32637 branch 2 times, most recently from b34c8c2 to 155ab93 Compare February 29, 2024 19:18
Copy link
Member

@grooverdan grooverdan left a comment

Choose a reason for hiding this comment

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

Well done on the depth of initial implementation.

@StefanoPetrilli StefanoPetrilli force-pushed the 11.5-MDEV-32637 branch 2 times, most recently from 2d216a3 to e3496f2 Compare March 5, 2024 12:11
Copy link
Contributor

@dlenski dlenski left a comment

Choose a reason for hiding this comment

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

Other than the issue of breaking time-sortability if you build up too much "borrowed time" and then restart the server (CREATE new_table AS SELECT UUID7(), T.* FROM table_with_1_million_rows T), this looks really good to me. 🙌

@StefanoPetrilli StefanoPetrilli requested a review from dlenski March 10, 2024 18:24
@StefanoPetrilli StefanoPetrilli force-pushed the 11.5-MDEV-32637 branch 2 times, most recently from ba470e7 to 344bb52 Compare March 10, 2024 19:20
Copy link
Contributor

@dlenski dlenski left a comment

Choose a reason for hiding this comment

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

Other than my small remaining nitpick about the name(s) of the constant(s), this looks fantastic. Approving! 🙌

Copy link
Contributor

@LinuxJedi LinuxJedi left a comment

Choose a reason for hiding this comment

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

Great work! A few minor things to fix and I think we are there.

Later on (not for this Jira ticket or PR) we could add a test for this to check that the UUID timestamp is within a tolerable range of a timestamp (+/- 2 hours?) in the same column by creating a new function to extract the UUID timestamp. If we do it range based then we won't need to worry about monotonic / DST quite as much.

@StefanoPetrilli StefanoPetrilli force-pushed the 11.5-MDEV-32637 branch 3 times, most recently from c1cc665 to 96be6e7 Compare March 13, 2024 23:51
@dlenski
Copy link
Contributor

dlenski commented Mar 14, 2024

@LinuxJedi wrote:

we could add a test for this to check that the UUID timestamp is within a tolerable range of a timestamp (+/- 2 hours?) in the same column by creating a new function to extract the UUID timestamp. If we do it range based then we won't need to worry about monotonic / DST quite as much.

Since it's based on Unix-epoch timestamp, shouldn't need to worry about DST 😅

@grooverdan grooverdan requested a review from vuvova April 30, 2024 01:49
Copy link
Member

@vuvova vuvova left a comment

Choose a reason for hiding this comment

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

UUID code is pretty good, just doesn't need to reside in mysys.
The function could be greatly simplified by using the approach from https://github.com/MariaDB/server/tree/bb-11.5-bar-MDEV-11339 (after rebasing this PR on top of that branch).

@StefanoPetrilli , I know you're busy now. There's no hurry, you can get back to it after GSoC. Just, please, if you decide not to continue with the PR at all — add a comment and say so.

@StefanoPetrilli StefanoPetrilli changed the base branch from 11.5 to 11.6 July 24, 2024 13:40
@StefanoPetrilli StefanoPetrilli requested a review from vuvova July 24, 2024 13:46
@vuvova
Copy link
Member

vuvova commented Aug 22, 2024

you've marked all my comments as resolved without actually changing anything. how comes?

@StefanoPetrilli
Copy link
Contributor Author

you've marked all my comments as resolved without actually changing anything. how comes?

Hey @vuvova, now you should be able to see the changes, I messed up while pushing.

@vuvova
Copy link
Member

vuvova commented Sep 2, 2024

I still don't see any changes 🤷‍♂️

@vuvova
Copy link
Member

vuvova commented Sep 12, 2024

Thanks. I've cherry-picked both UUIDv4 and UUIDv7 code into bb-11.7-MDEV-33710-uuid branch to be tested and merged into main

@vuvova
Copy link
Member

vuvova commented Oct 30, 2024

pushed into 11.7, thanks!

@vuvova vuvova closed this Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

7 participants