Skip to content

Primary key best practices #366

Answered by jgreet
CTOJoe asked this question in Documentation
Jan 7, 2023 · 1 comments · 4 replies
Discussion options

You must be logged in to vote

Hi @CTOJoe ,

PlanetScale databases are Vitess clusters of Innodb backed MySQL 8 instances so the same general guidelines apply.

Use integers and AUTO_INCREMENT for primary keys where possible. If you have to use strings, they should be as short as possible and sequential. Entirely random primary keys have the potential for performance problems on large or busy tables.

We use NanoIDs in our own application as external identifiers but the primary keys for those records are integers:
https://planetscale.com/blog/why-we-chose-nanoids-for-planetscales-api

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@CTOJoe
Comment options

@aMacDawg
Comment options

@jgreet
Comment options

@205g0
Comment options

Answer selected by CTOJoe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants