All Products
Search
Document Center

Tablestore:What are the primary key, partitions, and partition key of a data table?

Last Updated:Aug 14, 2024
Note

For more information, see Overview.

Primary key

Each row in a table is uniquely identified by a primary key. You must specify columns that compose a primary key when you create a table. These columns are called primary key columns. Each primary key column must contain a value. You must make sure that the combination of primary key column values in a row uniquely identifies the row. The data types of values in primary key columns cannot be modified after the data types are specified.

Partition and partition key

Tablestore automatically splits a table into different partitions to balance data loads. The first primary key column is called the partition key.

Rows that have the same partition key are located in the same partition. You can use a local transaction to perform operations on the data that shares the same partition key. The operations either all succeed or all fail.

The following figure shows a part of a mailing table from an email system. The following items describe the primary key and partitions of the table.

  • The UserID, ReceiveTime, and FromAddr columns represent the ID of the email user, the time when the email is received, and the email address of the sender from whom the email is sent, respectively. These columns are the primary key columns that are used to uniquely identify an email. The UserID column is the partition key.

  • The ToAddr, MailSize, Subject, and Read columns represent the email addresses of the receivers to whom the email is sent, the email size, the email subject, and whether the email is read. These columns are the attribute columns that are used to store information about the email.

The following figure shows that the rows in which the value of the UserID column is U0001 or U0002 are located in the same partition and the rows in which the value of the UserID column is U0003 or U0004 are located in another partition.