docs/en/sql-reference/sql-functions/utility-functions/uuidv7.md
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.
uuid_v7()
Returns a value of the VARCHAR type.
mysql> SELECT uuid_v7();
+--------------------------------------+
| uuid_v7() |
+--------------------------------------+
| 019ba290-15ce-7f13-86b4-ebc97d2f72c0 |
+--------------------------------------+
1 row in set (0.01 sec)
UUID v7 follows RFC 9562 specification with the following structure:
7.This structure ensures that UUIDs generated later will sort after earlier ones, improving index performance.
| Feature | uuid() (v4) | uuid_v7() (v7) |
|---|---|---|
| Ordering | Random | Time-ordered |
| Index Performance | Poor | Good |
| Fragmentation | High | Low |
| Timestamp Info | No | Yes (48-bit ms) |