Primary keys
Every table in Cloud Spanner must have a primary key. The primary key may be a single field or a composite key containing many fields, but the key must be globally unique. Cloud Spanner stores all data in splits by ordering table rows according to their primary keys. Because each split is assigned to exactly one node at a time, choosing a good primary key is extremely important for database performance. Adding to that, while most schema updates on Cloud Spanner are zero-downtime, changing a primary key cannot currently be done online.
When deciding on a primary key, your goal should be for rows to be evenly distributed among the nodes in your instance. This is similar to balancing data across shards in many other database technologies, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access