Skip to content

Commit 63e4578

Browse files
committed
minor #19783 [Uid] Add a caution message about using UUIDs as primary keys (javiereguiluz)
This PR was squashed before being merged into the 6.4 branch. Discussion ---------- [Uid] Add a caution message about using UUIDs as primary keys Fixes #19705. Commits ------- f2de304 [Uid] Add a caution message about using UUIDs as primary keys
2 parents 88d2cd0 + f2de304 commit 63e4578

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

components/uid.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,14 @@ entity primary keys::
344344
// ...
345345
}
346346

347+
.. caution::
348+
349+
Using UUIDs as primary keys is usually not recommended for performance reasons:
350+
indexes are slower and take more space (because UUIDs in binary format take 128 bits
351+
instead of 32/64 bits for auto-incremental integers) and the non-sequential nature of
352+
UUIDs fragments indexes. UUID v7 is the only variant that solves the fragmentation
353+
issue (but the index size issue remains).
354+
347355
When using built-in Doctrine repository methods (e.g. ``findOneBy()``), Doctrine
348356
knows how to convert these UUID types to build the SQL query
349357
(e.g. ``->findOneBy(['user' => $user->getUuid()])``). However, when using DQL
@@ -530,9 +538,15 @@ entity primary keys::
530538
}
531539

532540
// ...
533-
534541
}
535542

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

0 commit comments

Comments
 (0)