uuid_v7
Returns a time-ordered UUID v7 of the VARCHAR type. UUID v7 is defined in RFC 9562 and provides better database performance compared to random UUIDs (v4) because it maintains temporal ordering, which improves index locality and reduces fragmentation.
The UUID is 36 characters in length and contains 5 hexadecimal numbers connected with four hyphens in the xxxxxxxx-xxxx-7xxx-xxxx-xxxxxxxxxxxx format, where the version field is always 7.
This function is non-deterministic. Two calls to this function generate two different UUIDs.
Syntaxβ
uuid_v7()
Return valueβ
Returns a value of the VARCHAR type.
Examplesβ
mysql> SELECT uuid_v7();
+--------------------------------------+
| uuid_v7() |
+--------------------------------------+
| 019ba290-15ce-7f13-86b4-ebc97d2f72c0 |
+--------------------------------------+
1 row in set (0.01 sec)