Chi
Chi

Reputation: 259

AUTOINCREMENT Field in Cloud Spanner

Does Cloud Spanner support an AUTOINCREMENT Field so that a unique number is generated when a new record is inserted into a table?

Upvotes: 1

Views: 1942

Answers (2)

quangh
quangh

Reputation: 408

Cloud Spanner doesn't have that feature. Using sequential for primary key is even an anti-pattern because it creates hotspot.

If you insert records with a monotonically increasing integer as the key, you'll always insert at the end of your key space. This is undesirable because Cloud Spanner divides data among servers by key ranges, which means your inserts will be directed at a single server, creating a hotspot.

https://cloud.google.com/spanner/docs/schema-and-data-model#choosing_a_primary_key

Upvotes: 2

Chi
Chi

Reputation: 259

Cloud Spanner does not have an AUTOINCREMENT feature.

Upvotes: 0

Related Questions