Skip to content

Commit

Permalink
docs: auto-generated keys (#833)
Browse files Browse the repository at this point in the history
* docs: sequence and uuid

* docs

* comment changes
  • Loading branch information
asthamohta committed Jun 24, 2024
1 parent 74e76a4 commit 9296b6e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
7 changes: 5 additions & 2 deletions docs/data-types/mysql.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,13 @@ maps `UNIQUE` constraint into `UNIQUE` secondary index. Note that due to limitat
mysqldump parser, we are not able to handle key column ordering (i.e. ASC/DESC) in
mysqldump files. All key columns in mysqldump files will be treated as ASC.

## Auto-Increment and Sequences

The tool creates a new sequence for auto-increment columns and maps the auto-generation of these columns to this sequence. The sequence type is of *bit reversed positive*. Users need to set skip range and/or start with counter to avoid duplicate key errors.

## Other MySQL features

MySQL has many other features we haven't discussed, including functions,
sequences, procedures, triggers, (non-primary) indexes and views. The tool does
MySQL has many other features we haven't discussed, including functions procedures, triggers, (non-primary) indexes and views. The tool does
not support these and the relevant statements are dropped during schema
conversion.

Expand Down
3 changes: 2 additions & 1 deletion docs/ui/schema-conv/issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ Spanner migration tool scans through the generated spanner schema and notifies t

## Warnings

- Detection of an auto-increment key in source database because auto-increments are currently not supported in spanner
- Detection of an auto-increment key in source database because auto-increments are currently not supported for all source databases.
- Spanner data type consuming more storage than source data type
- Redundant indexes
- Addition of [synthetic primary key](../ui.md/#termsterminology) - synth_id
- [Hotspotting](https://cloud.google.com/spanner/docs/schema-design) due to timestamp or auto-increment keys
- Auto Increment has been converted to Sequence, set Ignore Range or Start with Counter to avoid duplicate value errors

## Suggestions

Expand Down
1 change: 1 addition & 0 deletions docs/ui/schema-conv/schema-conv.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ In the configure schema page, the user can view details of the source database a
1. Interleave
1. SQL
1. Index details
1. Sequence Details (Only for Source DB MySql)
1. Issues & Suggestions

![](https://services.google.com/fh/files/helpcenter/asset-lwlr5arntba.png)
43 changes: 39 additions & 4 deletions docs/ui/schema-conv/spanner-draft.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ Users can view detailed information for a table by selecting it from the **Spann

### Column

Column tab provides information on the columns that are a part of the selected table. It also provides the option to edit the column wherein a user can modify a column name, delete a column, change the data type of the column or modify the null property of the column. Once the user is done with required modifications, they can click on **SAVE & CONVERT **and the update would reflect in the session file and across all the components in the database.
Column tab provides information on the columns that are a part of the selected table. It also provides the option to edit the column wherein a user can modify a column name, delete a column, change the data type of the column, add auto-generation to the column or modify the null property of the column. Once the user is done with required modifications, they can click on **SAVE & CONVERT **and the update would reflect in the session file and across all the components in the database.

![](https://services.google.com/fh/files/helpcenter/asset-oo8ugjhmgd.png)
![](https://services.google.com/fh/files/misc/column-info-edit.png)

### Primary Key

Users can view and edit the primary key of a table from the primary key tab. They can remove/add a column from the primary key or change the order of columns in the primary key. Once these changes are made, the session file is updated and they can also be verified from the [SQL tab](#sql).

![](https://services.google.com/fh/files/helpcenter/asset-syrsuek8k4r.png)
![](https://services.google.com/fh/files/misc/migration-pk.png)

### Foreign Key

Expand Down Expand Up @@ -82,4 +82,39 @@ Apart from the existing indexes for the source database, users can also add seco

![](https://services.google.com/fh/files/helpcenter/asset-6xbpmfyeplw.png)

![](https://services.google.com/fh/files/helpcenter/asset-ck63akvjank.png)
![](https://services.google.com/fh/files/helpcenter/asset-ck63akvjank.png)

## Auto-Generated Columns
*Only Supported for source database MySQL*

Auto-Generated Columns populate Spanner columns automatically if no value is provided. Currently Spanner Migration Tool support the following techniques for auto-generation:
1. UUID function: Generate a UUID (v4) as part of a table’s primary key DEFAULT expression.
2. Bit reverse function: Map existing integer keys using the same logic as a bit-reversed sequence to avoid hotspotting.

Refer to [documentation](https://cloud.google.com/spanner/docs/primary-key-default-value).

### UUID

The default recommendation for primary keys in Spanner is to use a Universally Unique Identifier, or UUID. Users can convert existing columns to be filled by UUID by choosing the **Edit** option in a table and under the **Auto-Generated** column choosing UUID.
![](https://services.google.com/fh/files/misc/column-edit-uuid.png)

### Sequences

Spanner offers a SEQUENCE object that generates unique integers as part of a primary key DEFAULT expression. However, unlike a monotonic sequence, the values generated by a Spanner sequence are distributed uniformly and thus won’t hotspot at scale. Existing **Auto-Increment** columns will be mapped to a new Sequence.

#### Create a new Sequence
In order to add a sequence, the user needs to select the **Add Sequence** option and provide some details mandatory to create a sequence like **sequence name** and **sequence type**. An existing sequence can also be modified using the **Edit** button.

<img src="https://services.google.com/fh/files/misc/sidebar-add-seq.png" width="30%" height="30%">

![](https://services.google.com/fh/files/misc/add-seq-column-info.png)
<img src="https://services.google.com/fh/files/misc/add-seq.png" width="30%" height="30%">

To assign a sequence to a column, users need to select the **Edit** option in a table and under the **Auto-Generated** column choose a Sequence.

![](https://services.google.com/fh/files/misc/edit-seq.png)

#### Drop a Sequence
Users can drop a sequence by selecting the sequence and clicking on **DROP SEQUENCE**. Once a sequence is dropped, all columns that used the sequence for auto-generated will have their auto-generation policy set to none.

![](https://services.google.com/fh/files/misc/seq-info.png)

0 comments on commit 9296b6e

Please sign in to comment.