[MDEV-11339] Support UUID v4 generation Created: 2016-11-23 Updated: 2023-12-27 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Minor |
| Reporter: | richardeaxon | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 10 |
| Labels: | beginner-friendly | ||
| Issue Links: |
|
||||||||||||||||||||||||
| Description |
|
I need to use an external routine to generate RFC 4122 UUID's (https://tools.ietf.org/html/rfc4122) as MariaDB generates v1 UUID's. v1 UUID's are not opaque enough for our needs. I suggest that the uuid() function call accepts an optional parameter - uuid(4) to generate a v4 uuid, or create a new function call uuid4(). The RFC document above includes C source code for UUID types 1 to 5. |
| Comments |
| Comment by Christopher Halbersma [ 2020-02-18 ] | ||||||||||||
|
I'd second this. UUID4 make it simpler to shard queries across instances. Since it's random I can say where uuid_column REGEXP ^[ab] and I know that I'm getting statistically 1/8th of the rows in my table. This becomes very handy when doing pagination stuff. | ||||||||||||
| Comment by Dario Seidl [ 2021-07-01 ] | ||||||||||||
|
I would love to see this too. We often generated UUIDs in application logic (e.g. Java UUID.randomUUID()) and when doing database migrations we need to generate compatible UUIDs in MariaDB. | ||||||||||||
| Comment by Trevor Gross [ 2021-10-24 ] | ||||||||||||
|
Agreed with this, it would pair nicely with the new UUID datatype. V5 could occasionally be handy too, but with a less high priority. I don't think there's an ISO-SQL way of doing it, postgres implements it with a plugin uuid_generate_v1(), uuid_generate_v4(), uuid_generate_v5(). https://www.postgresql.org/docs/9.4/uuid-ossp.html @chalbersma you could do something similar with v1. Not sure about where mariadb makes the cutoff, but most v1 implementations use random for parts of the third and/or fourth groups (https://www.uuidtools.com/img/version_1_diagram.png). Regex gets a bit more complex but it's possible to extract the random bits. | ||||||||||||
| Comment by Trevor Gross [ 2022-02-17 ] | ||||||||||||
|
Copying my comment from MDEV-23748 which might get closed as a duplicate:
| ||||||||||||
| Comment by Michael Berg [ 2022-11-28 ] | ||||||||||||
|
This issue was created more than 6 years ago. Is there any update? | ||||||||||||
| Comment by Trevor Gross [ 2022-12-20 ] | ||||||||||||
|
As a solid workaround until something official comes out, I created a UDF that adds functions matching the postgres uuid-osp signatures. It can generate v1 and v4 UUIDs, v1 with a randomized MAC address, validate UUIDs, and generate the namespace UUIDs (v3 & v5 are a work in progress). Repo: https://github.com/pluots/udf-suite you can compile it yourself, or download the `.so`/`.dll` files from the releases page | ||||||||||||
| Comment by Michael Berg [ 2022-12-21 ] | ||||||||||||
|
@Trevor Gross Thanks for that, this is helpful and precisely what is required. I can't use it though, since I'm connecting to a server that hosts many different databases and where I'm not root or have any control of the server or the client for that matter. It would be even better if you could branch off and work these functions into the mariadb codebase itself. Then a PR and hope someone will accept it. Minor rant not aimed at you: When a Jira issue gets this old it should be closed with "Won't fix" because for all practical purposes, that is the defacto status. Six years without being accepted or rejected is frankly a disgrace. | ||||||||||||
| Comment by Jaydeep Das [ 2023-12-23 ] | ||||||||||||
|
I would like to work on it since it's unassigned. | ||||||||||||
| Comment by Sergei Golubchik [ 2023-12-23 ] | ||||||||||||
|
Sure, please, do. A question for users with practical use cases (I believe those two requested it in comments above could help with an answer): what would better fit your use case, multiple functions like UUIDv1(), UUIDv4(), UUIDv7(), etc or one function with an argument, like UUID(1), UUID(4), UUID(7)? I personally suspect that the query like SELECT UUID(tbl1.ver) FROM tbl1 is rather artificial, but perhaps someone needs that? | ||||||||||||
| Comment by Christopher Halbersma [ 2023-12-27 ] | ||||||||||||
|
> UUIDv1(), UUIDv4(), UUIDv7(), etc or one function with an argument, like UUID(1), UUID(4), UUID(7) Honestly either one could work. The second seems to fit the patterns of other built in functions nominally better, but I think the primary use case for UUID generation is upon insertion of data, but I imagine the 3/5 types might be used on select logic. |