Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Uid] Add a caution message about using UUIDs as primary keys #19783

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion components/uid.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT to add anchor link on UUUD v7 ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! I did this while merging. Thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UUIDv6 are also fine from a fragmentation PoV

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the docs here: 2cbc55e Thanks!

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 @@ -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
Expand Down
Loading