Skip to content

Commit 1e25604

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: [Uid] Add a caution message about using UUIDs as primary keys
2 parents 9ebd8d4 + 28eceb8 commit 1e25604

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

components/uid.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ sortable (like :ref:`ULIDs <ulid>`). It's more efficient for database indexing
113113
It's recommended to use UUIDv7 instead of UUIDv6 because it provides
114114
better entropy.
115115

116+
.. _uid-uuid-v7:
117+
116118
**UUID v7** (UNIX timestamp)
117119

118120
Generates time-ordered UUIDs based on a high-resolution Unix Epoch timestamp
@@ -332,6 +334,14 @@ entity primary keys::
332334
// ...
333335
}
334336

337+
.. caution::
338+
339+
Using UUIDs as primary keys is usually not recommended for performance reasons:
340+
indexes are slower and take more space (because UUIDs in binary format take
341+
128 bits instead of 32/64 bits for auto-incremental integers) and the non-sequential
342+
nature of UUIDs fragments indexes. :ref:`UUID v7 <uid-uuid-v7>` is the only
343+
variant that solves the fragmentation issue (but the index size issue remains).
344+
335345
When using built-in Doctrine repository methods (e.g. ``findOneBy()``), Doctrine
336346
knows how to convert these UUID types to build the SQL query
337347
(e.g. ``->findOneBy(['user' => $user->getUuid()])``). However, when using DQL
@@ -510,9 +520,15 @@ entity primary keys::
510520
}
511521

512522
// ...
513-
514523
}
515524

525+
.. caution::
526+
527+
Using ULIDs as primary keys is usually not recommended for performance reasons.
528+
Although ULIDs don't suffer from index fragmentation issues (because the values
529+
are sequential), their indexes are slower and take more space (because ULIDs
530+
in binary format take 128 bits instead of 32/64 bits for auto-incremental integers).
531+
516532
When using built-in Doctrine repository methods (e.g. ``findOneBy()``), Doctrine
517533
knows how to convert these ULID types to build the SQL query
518534
(e.g. ``->findOneBy(['user' => $user->getUlid()])``). However, when using DQL

0 commit comments

Comments
 (0)