Skip to content

Commit

Permalink
Merge branch '7.0' into 7.1
Browse files Browse the repository at this point in the history
* 7.0:
  [Uid] Add a caution message about using UUIDs as primary keys
  • Loading branch information
javiereguiluz committed Apr 15, 2024
2 parents a5cc16d + 1e25604 commit 68d6b11
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion components/uid.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ sortable (like :ref:`ULIDs <ulid>`). It's more efficient for database indexing
It's recommended to use UUIDv7 instead of UUIDv6 because it provides
better entropy.

.. _uid-uuid-v7:

**UUID v7** (UNIX timestamp)

Generates time-ordered UUIDs based on a high-resolution Unix Epoch timestamp
Expand Down Expand Up @@ -357,6 +359,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. :ref:`UUID v7 <uid-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
Expand Down Expand Up @@ -535,9 +545,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
Expand Down

0 comments on commit 68d6b11

Please sign in to comment.