diff --git a/components/uid.rst b/components/uid.rst index e64eabee0fb..4830be747b2 100644 --- a/components/uid.rst +++ b/components/uid.rst @@ -344,6 +344,14 @@ entity primary keys:: // ... } +.. caution:: + + Using UUIDs as primary keys is usually not recommended for performance reasons: + indexes are slower and take more space (because UUIDs in binary format take 128 bits + instead of 32/64 bits for auto-incremental integers) and the non-sequential nature of + UUIDs fragments indexes. UUID v7 is the only variant that solves the fragmentation + issue (but the index size issue remains). + When using built-in Doctrine repository methods (e.g. ``findOneBy()``), Doctrine knows how to convert these UUID types to build the SQL query (e.g. ``->findOneBy(['user' => $user->getUuid()])``). However, when using DQL @@ -530,9 +538,15 @@ entity primary keys:: } // ... - } +.. caution:: + + Using ULIDs as primary keys is usually not recommended for performance reasons. + Although ULIDs don't suffer from index fragmentation issues (because the values + are sequential), their indexes are slower and take more space (because ULIDs + in binary format take 128 bits instead of 32/64 bits for auto-incremental integers). + When using built-in Doctrine repository methods (e.g. ``findOneBy()``), Doctrine knows how to convert these ULID types to build the SQL query (e.g. ``->findOneBy(['user' => $user->getUlid()])``). However, when using DQL