Auto-increment in Google Cloud Spanner

Google Cloud Spanner recommends against using monotonically increasing integers for primary keys. This makes sense for top-level tables, as this would create hot spots. But what about alternating tables? They will still be stored on the same node. They are also stored in sort order, so using a UUID or some other random identifier seems suboptimal, especially if they are also found in sorted order.

Is reading max id and saving maxId + 1 for a new line is the right solution here?

+5
source share
1 answer

Rows of alternating child tables are prefixed with the parent table key, so they can be considered as non-sequential keys, since the parent key is not sequential. In this situation, this should be good, because, as you noticed, this entire range of keys will be served by a single Span server. If you are concerned that in this situation, a hot search for a single Span server is best not to interleave the table.

It should also be noted that it really monotonically increases or decreases the keys that are recommended against, since they have the same effect, only on opposite sides of the range.

+3
source

Source: https://habr.com/ru/post/1264295/


All Articles