This page describes how you can create and manage split points in your database. You can create split points to pre-split your database to help prepare for an anticipated increase in traffic. For more information about pre-splitting, see Pre-splitting overview.
Before you begin
-
To get the permission that you need to create and manage split points, ask your administrator to grant you the Cloud Spanner Database Admin (
roles/spanner.databaseAdmin
) IAM role on your instance. For more information about granting roles, see Manage access to projects, folders, and organizations.This predefined role contains the
spanner.databases.addSplitPoints
permission, which is required to create and manage split points.You might also be able to get this permission with custom roles or other predefined roles.
The gcloud CLI examples on this page make the following assumptions:
- You've set up gcloud CLI for use with Spanner. If you're new to using gcloud CLI with Spanner, see Create and query a database using the gcloud CLI.
You have configured gcloud CLI with your project. For example:
gcloud config set core/project PROJECT_ID
Ensure your Spanner instance has enough nodes to support the anticipated increase in traffic. For more information, see Pre-splitting overview.
Create split points
You can create split points using the Google Cloud CLI or the REST APIs.
gcloud
If you want to create split points using the Google Cloud CLI, you need to create a file that contains all the splits and supply the path in the gcloud CLI command. The file must not exceed the API limit of 100 points per API request. For more information, see Quotas and limits.
The file must use the following format to specify the split points:
ObjectType ObjectName (SplitValue)
ObjectType ObjectName (SplitValue)
ObjectType ObjectName (SplitValue)
Replace the following variables when creating the file:
- ObjectType: the object type you want to add splits in. Valid
values are
TABLE
andINDEX
. - ObjectName: the name of the database table or index.
- SplitValue: the split point value where you want to introduce the splits.
Use the following rules when creating the split point values in the file:
- String values need to be in single quotes. For example,
'splitKeyPart'
- Boolean values need to be either
true
orfalse
. INT64
andNUMERIC
Spanner data type values need to be in single quotes. For example,'123'
or'99.99'
.- All other number values need to be written without single quotes. For example,
1.287
. - Timestamp values should be provided in the
'2020-06-18T17:24:53Z'
format in single quotes. - Split values need to be surrounded by parentheses.
- The split keys value order must be the same as the primary key order.
- If the split value needs to have a comma, you must escape the comma using a `\` character.
- For splitting indexes, you can either provide the index key or the entire index and the complete table key.
- You must always use the complete key when specifying the split point.
The following is a sample file that shows how split points are specified:
TABLE Singers ('c32ca57a-786c-2268-09d4-95182a9930be')
TABLE Singers ('bb98c7e2-8240-b780-346d-c5d63886594a')
INDEX Order ('5b8bac71-0cb2-95e9-e1b0-89a027525460')
TABLE Payment ('6cf41f21-2d77-318f-c504-816f0068db8b')
INDEX Indx_A (2152120141932780000)
TABLE TableD (0,'7ef9d̦b22-d0e5-6041-8937-4bc6a7ef9db2')
INDEX IndexXYZ ('8762203435012030000',NULL,NULL)
INDEX IndexABC (0, '2020-06-18T17:24:53Z', '2020-06-18T17:24:53Z') TableKey
(123,'ab\,c')
Before using any of the command data below, make the following replacements:
- SPLITS_FILE: the path to the splits file.
- INSTANCE_ID: the instance ID.
- DATABASE_ID: the database ID.
- EXPIRATION_DATE: the expiration date of the split points.
- INITIATOR: the initiator of the split points.
Execute the following command:
Linux, macOS, or Cloud Shell
gcloud spanner databases splits add \ --splits-file=SPLITS_FILE \ --instance=INSTANCE_ID\ --database=DATABASE_ID\ --split-expiration-date EXPIRATION_DATE\ --initiator INITIATOR\
Windows (PowerShell)
gcloud spanner databases splits add ` --splits-file=SPLITS_FILE ` --instance=INSTANCE_ID` --database=DATABASE_ID` --split-expiration-date EXPIRATION_DATE` --initiator INITIATOR`
Windows (cmd.exe)
gcloud spanner databases splits add ^ --splits-file=SPLITS_FILE ^ --instance=INSTANCE_ID^ --database=DATABASE_ID^ --split-expiration-date EXPIRATION_DATE^ --initiator INITIATOR^
REST v1
You can use the
projects.instances.databases.addSplitPoints
method to create split points.
Before using any of the request data, make the following replacements:
- PROJECT_ID: the project ID.
- INSTANCE_ID: the instance ID.
- DATABASE_ID: the database ID.
HTTP method and URL:
POST https://spanner.googleapis.com/v1/projects//instances/ /databases/ :addSplitPoints
Request JSON body:
{ "split_points": [ { "table": "T1", "index": "T1_IDX", "expire_time": "2023-04-22T10:00:20.021Z", "keys": [ { "key_parts": { "values": [ 3 ] } }, { "key_parts": { "values": [ 10 ] } } ] }, { "table": "T2", "expire_time": "2023-04-22T10:00:20.021Z", "keys": [ { "key_parts": { "values": [ 50 ] } } ] } ] }
To send your request, expand one of these options:
You should receive a successful status code (2xx) and an empty response.
Client libraries
Go
Java
Node.js
Python
Possible error scenarios
The following scenarios can result in an error when creating split points:
- The index level split has an incorrect table name in the input.
- The table level split point has more than one key.
- The index level split point has more than two keys.
- The split points are defined on tables or indexes that aren't defined in the database schema.
- The request contains duplicate split points.
For information about quotas and limits, see Quotas and limits.
View split points
You can view all the created split points on your database using the Google Cloud console or gcloud CLI:
Console
To get the split point count by querying the SPANNER_SYS.USER_SPLIT_POINTS
view in the Google Cloud console, do the following:
Open the Spanner instances page.
Select the names of the Spanner instance and the database that you want to query.
Click Spanner Studio in the left navigation panel.
Type the following query in the text field:
SELECT * FROM SPANNER_SYS.USER_SPLIT_POINTS
Click Run query.
A result similar to the following appears:
TABLE_NAME | INDEX_NAME | INITIATOR | SPLIT_KEY | EXPIRE_TIME |
---|---|---|---|---|
T | CloudAddSplitPointsAPI | T(90,153,4,2024-04-30T17:00:00-07:00,1,2024-05-01,a) | 2025-03-06T09:58:58.007201Z | |
T | T_IDX | CloudAddSplitPointsAPI | Index: T_IDX on T, Index Key: (10), Primary Table Key: (<begin>,<begin>,<begin>,<begin>,<begin>,<begin>,<begin>) | 2025-03-08T07:33:23.861682Z |
T | T_IDX | CloudAddSplitPointsAPI | Index: T_IDX on T, Index Key: (9091), Primary Table Key: (4567,123,4.2,2024-04-30T17:00:00-07:00,1,2024-05-01,a) | 2025-03-08T07:35:25.990007Z |
gcloud
Run the following gcloud CLI command to view split points in your database:
gcloud spanner databases splits list \
--instance INSTANCE_ID\
--database DATABASE_ID
Replace the following variables when running this command:
- INSTANCE_ID: the Spanner instance ID.
- DATABASE_ID: the Spanner database ID.
A response similar to the following appears:
TABLE_NAME: T
INDEX_NAME:
INITIATOR: CloudAddSplitPointsAPI
SPLIT_KEY: T(90,153,4,2024-04-30T17:00:00-07:00,1,2024-05-01,a)
EXPIRE_TIME: 2025-03-06T09:58:58.007201Z
TABLE_NAME: T
INDEX_NAME: T_IDX
INITIATOR: CloudAddSplitPointsAPI
SPLIT_KEY: Index: T_IDX on T, Index Key: (10), Primary Table Key: (<begin>,<begin>,<begin>,<begin>,<begin>,<begin>,<begin>)
EXPIRE_TIME: 2025-03-08T07:33:23.861682Z
TABLE_NAME: T
INDEX_NAME: T_IDX
INITIATOR: CloudAddSplitPointsAPI
SPLIT_KEY: Index: T_IDX on T, Index Key: (9091), Primary Table Key: (4567,123,4.2,2024-04-30T17:00:00-07:00,1,2024-05-01,a)
EXPIRE_TIME: 2025-03-08T07:35:25.990007Z
How to expire a split point
You can set an expiration time for each split point you create. For more information, see Split point expiration. You can expire split points using the Google Cloud CLI or the REST APIs.
gcloud
If you want to expire split points the Google Cloud CLI, you need to
create a file that contains all the splits you want to expire and supply its
path using the splits-file
parameter in the
gcloud CLI command. The file must not exceed the API limit of 100
points per API request. For more information, see
Quotas and limits.
The file must use the following format to specify the split points:
ObjectType ObjectName (SplitValue)
ObjectType ObjectName (SplitValue)
ObjectType ObjectName (SplitValue)
Replace the following variables when creating the file:
- ObjectType: the object type of the split you want to expire. Valid
values are
TABLE
andINDEX
. - ObjectName: the name of the database table or index.
- SplitValue: the split point value you want to expire.
Use the following rules when creating the split point values in the file:
- String values need to be in single quotes. For example,
'splitKeyPart'
- Boolean values can be either
true
orfalse
. INT64
andNUMERIC
Spanner data type values need to be in single quotes. For example,'123'
or'99.99'
.- All other number values need to be written without single quotes. For example,
1.287
. - Timestamp values should be provided in the
'2020-06-18T17:24:53Z'
format in single quotes. - Split values need to be surrounded by parentheses.
- The split keys value order must be the same as the primary key order.
- If the split value needs to have a comma, you must escape the comma using a `\` character.
- For splitting indexes, you can either provide the index key or the entire index and the complete table key.
- You must always use the complete key when specifying the split point.
The following is a sample file that shows how split points are specified:
TABLE Singers ('c32ca57a-786c-2268-09d4-95182a9930be')
TABLE Singers ('bb98c7e2-8240-b780-346d-c5d63886594a')
INDEX Order ('5b8bac71-0cb2-95e9-e1b0-89a027525460')
TABLE Payment ('6cf41f21-2d77-318f-c504-816f0068db8b')
INDEX Indx_A (2152120141932780000)
TABLE TableD (0,'7ef9db22-d0e5-6041-8937-4bc6a7ef9db2')
INDEX IndexXYZ ('8762203435012030000',NULL,NULL)
INDEX IndexABC (0, '2020-06-18T17:24:53Z', '2020-06-18T17:24:53Z') TableKey
(123,'ab\,c')
Before using any of the command data below, make the following replacements:
- SPLITS_FILE: the path to the splits file.
- INSTANCE_ID: the instance ID.
- DATABASE_ID: the database ID.
- EXPIRATION_DATE: the expiration date of the split points.
- INITIATOR: the initiator of the split points.
Execute the following command:
Linux, macOS, or Cloud Shell
gcloud spanner databases splits add \ --splits-file=SPLITS_FILE \ --instance=INSTANCE_ID\ --database=DATABASE_ID\ --split-expiration-date EXPIRATION_DATE\ --initiator INITIATOR\
Windows (PowerShell)
gcloud spanner databases splits add ` --splits-file=SPLITS_FILE ` --instance=INSTANCE_ID` --database=DATABASE_ID` --split-expiration-date EXPIRATION_DATE` --initiator INITIATOR`
Windows (cmd.exe)
gcloud spanner databases splits add ^ --splits-file=SPLITS_FILE ^ --instance=INSTANCE_ID^ --database=DATABASE_ID^ --split-expiration-date EXPIRATION_DATE^ --initiator INITIATOR^
REST v1
Before using any of the request data, make the following replacements:
- PROJECT_ID: the project ID.
- INSTANCE_ID: the instance ID.
- DATABASE_ID: the database ID.
HTTP method and URL:
POST https://spanner.googleapis.com/v1/projects//instances/ /databases/ :addSplitPoints
Request JSON body:
{ "split_points": [ { "table": "T1", "index": "T1_IDX", "expire_time": "2023-04-22T10:00:20.021Z", "keys": [ { "key_parts": { "values": [ 3 ] } }, { "key_parts": { "values": [ 10 ] } } ] }, { "table": "T2", "expire_time": "2023-04-22T10:00:20.021Z", "keys": [ { "key_parts": { "values": [ 50 ] } } ] } ] }
To send your request, expand one of these options:
You should receive a successful status code (2xx) and an empty response.