Hacker News new | ask | show | jobs
by avinassh 1221 days ago
> There are pros and cons to using random IDs as a PK. For RDBMS clustering on the PK (InnoDB), it's a terrible idea. If you're going to sort by the PK, it's usually a terrible idea (UUIDv1 isn't as bad since it includes the timestamp, but that assumes your access pattern is based on insertion time).

In which use cases you want to sort by PK? Isn't sorting by fields like created_at sufficient?

1 comments

Depends if you're using an autoincrementing int as your PK. If so, it may be a reasonable decision. It may have gaps, of course, but it's still monotonic.

Related, PG15 has an improved sort algorithm for some data types. Most integers, timestamps, and a few others. So the column type could matter here.