[MDEV-32637] Implement native UUID7 function Created: 2023-10-31  Updated: 2023-12-25

Status: Open
Project: MariaDB Server
Component/s: None
Fix Version/s: None

Type: Task Priority: Minor
Reporter: Juan Lago Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: beginner-friendly, uuid

Issue Links:
PartOf
is part of MDEV-23748 support not-MAC-address based UUID ve... Open
Relates
relates to MDEV-11339 Support UUID v4 generation Open

 Description   

MariaDB provides the UUID method that generates UUID v4, however UUID v4 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 sortable and a good collision resistance.

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

Right now is possible to generate UUID7 using a poor custom UDF however it may be very slow.



 Comments   
Comment by Sergei Golubchik [ 2023-10-31 ]

Correction: MariaDB UUID() function generates UUIDv1, not UUIDv4. They are time sortable.

Anyway, being able to generate UUID's of other versions is a totally valid feature request.

Comment by Daniel Black [ 2023-11-01 ]

In the mean time, a fast uuidv7:

From https://github.com/pluots/udf-suite/releases

doc: https://github.com/pluots/udf-suite/blob/main/udf-uuid/README.md

Untar from the github release with the .so files put into /usr/lib/mysql/plugin

MariaDB [test]> CREATE FUNCTION uuid_generate_v7 RETURNS string SONAME 'libudf_uuid.so';
Query OK, 0 rows affected (0.000 sec)
 
 
MariaDB [test]> SELECT BENCHMARK(1000000,uuid_generate_v7());
+---------------------------------------+
| BENCHMARK(1000000,uuid_generate_v7()) |
+---------------------------------------+
|                                     0 |
+---------------------------------------+
1 row in set (0.063 sec)

Unlike the SQL version you had which generates invalid uuids:

MariaDB [test]> SELECT BENCHMARK(1000000,uuidv7());
ERROR 1292 (22007): Incorrect uuid value: '06541949-30-7602-4E1D-DD59E218E01A'
MariaDB [test]> SELECT BENCHMARK(1000000,uuidv7());
ERROR 1292 (22007): Incorrect uuid value: '0654194A-90-738F-4364-563AF35DC398'
MariaDB [test]> SELECT BENCHMARK(1000000,uuidv7());
ERROR 1292 (22007): Incorrect uuid value: '0654194A-30-75A3-48A3-89854C46C137'
MariaDB [test]> SELECT BENCHMARK(1000000,uuidv7());
ERROR 1292 (22007): Incorrect uuid value: '0654194A-70-7E23-49E4-E49A5AE9C3FE'

Comment by Juan Lago [ 2023-11-01 ]

@Daniel Black: Thank you for provide me a plugin that can generate UUIDv7. Unfortunately some the server that I am using are hosted in cloud providers like AWS and they don't allow to install custom plugins.

I will fix the UDF so it will generate correctly UUID7.

Comment by Daniel Black [ 2023-11-01 ]

Sorry to hear that. Welcome a share of the corrected SQL too.

If anyone feels comfortable implementing it, the two item_uuidfunc* files in https://github.com/MariaDB/server/tree/11.3/plugin/type_uuid contain the current UUIDv1 implementation. Adding 1 class and an implementation is all that is required.

And the my_uuid function is a useful reference.

Comment by Juan Lago [ 2023-11-01 ]

I fixed the code.

I also implemented a procedure that test collisions.

Comment by Jaydeep Das [ 2023-12-23 ]

juanparati, danblack, So, is the issue fixed or still open to work on?

Comment by Juan Lago [ 2023-12-25 ]

@Jaydeep Das: I am not MariaDB developer. I just fixed a poor function that can we use as a workaround: https://gist.github.com/juanparati/0ded9c04d4cd43e5aae8f5a438a8b18b

Generated at Thu Feb 08 10:32:51 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.