launchbadge / realworld-axum-sqlx

A Rust implementation of the Realworld demo app spec using Axum and SQLx.
GNU Affero General Public License v3.0
803 stars 82 forks source link

UUID primary keys are enormous and difficult to work with #19

Closed benwilber closed 4 months ago

benwilber commented 4 months ago

https://github.com/launchbadge/realworld-axum-sqlx/blob/main/migrations/2_user.sql#L14

I know it seems like a good idea, but unless you have an extremely trivial amount of data, this is almost always bad. In my experience it's best to just have a serial bigint for internal database relations and then have a unique uuid field for application-level identifiers and natural keys. Then PG doesn't have to copy that humongous 128bit int to every side of the relation. Imagine you have 1 billion rows...32 gigabytes just for table storage + PK index. Yikes. Misery.