uuid_v7_numeric
Returns a time-ordered UUID v7 of the LARGEINT 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.
This function returns the UUID v7 as a 128-bit integer instead of a string format, which can be more efficient for storage and comparison operations.
This function is non-deterministic. Two calls to this function generate two different UUIDs.
Syntaxβ
uuid_v7_numeric()
Return valueβ
Returns a value of the LARGEINT type (128-bit integer).
Examplesβ
mysql> SELECT uuid_v7_numeric();
+---------------------------------------+
| uuid_v7_numeric() |
+---------------------------------------+
| 2088748395792837468371928374619283746 |
+---------------------------------------+
1 row in set (0.01 sec)
Benefitsβ
- Time-ordered: UUID values generated later will be larger than earlier ones.
- Improved Index Performance: Better locality in B-tree indexes.
- Reduced Fragmentation: Sequential inserts cause fewer page splits.
- Unique: Random bits ensure uniqueness even within the same millisecond.
- Efficient Storage: Numeric representation can be more compact than string format.
Comparison with uuid_numericβ
| Feature | uuid_numeric() (v4) | uuid_v7_numeric() (v7) |
|---|---|---|
| Ordering | Random | Time-ordered |
| Index Performance | Poor | Good |
| Fragmentation | High | Low |
| Timestamp Info | No | Yes (48-bit ms) |