All Products
Search
Document Center

Tablestore:Billable items of secondary indexes

Last Updated:Jan 15, 2024

Secondary indexes can be classified into global secondary indexes and local secondary indexes. You are charged storage fees when you use the secondary index feature. When the system inserts data into a data table, the system may also need to write the data to the index tables that are created for the data table. During this process, read and write capacity units (CUs) are consumed. This topic describes the billable items and billing rules for secondary indexes.

Billing rules

The following rules are used to calculate and meter the data sizes and read and write CUs for indexes:

  • The rules that are used to calculate the data sizes and read CUs for indexes are the same as the rules that are used to calculate the data sizes and read CUs for data tables. For more information, see Billing overview.

  • The following rules are used to meter the read and write CUs that are consumed to create an index table:

    • Write CUs are consumed only when an index row is inserted or updated.

    • Read CUs are consumed when an index row is deleted, updated, or inserted. The number of read CUs is determined based on the amount of data that is read from specific indexed columns in the data table.

Billable items

Index tables are created when you use the secondary index feature. Therefore, you are charged storage fees when you use the secondary index feature. When the system inserts data into a data table, the system may also need to write the data to the index tables that are created for the data table. During this process, read and write CUs are consumed.

The billable items of an index table include the data size of the index table, the read CUs that are consumed to create the index table, the write CUs that are consumed to create the index table, and the read CUs that are consumed to read the index table.

Billable item

Description

Data size of an index table

The data size of the index table. Unit: GB.

Read CUs consumed to create an index table

The number of read CUs that are consumed by read operations to delete, insert, or update index rows. Unit: CU.

Write CUs consumed to create an index table

The number of write CUs that are consumed to insert or update index rows. Unit: CU.

Read CUs that are consumed to read an index table

The number of read CUs that are consumed by read API operations that are called to read the index table. Unit: CU.

Data size of an index table

The method that is used to meter the data size of an index table is the same as the method that is used to meter the data size of a data table. The data size of an index table is equal to the total data size of all index rows. The total data size of all index rows is equal to the sum of the data size of the primary key and attribute columns in each index row. For more information, see Storage usage.

Read CUs consumed to create an index table

Read CUs are consumed when a secondary index is created for a data table. The following table describes how to calculate the number of read CUs that are consumed in different scenarios.

Scenario

Billing rule

Write a row by performing the PUT operation

Write a new row

  • The PUT operation does not insert data into the indexed attribute columns in the data table. Therefore, no index row is inserted. In this case, one read CU is consumed.

  • The PUT operation inserts data into the indexed columns in the data table. Therefore, a new index row is inserted. In this case, one read CU is consumed.

Overwrite an existing row

  • The PUT operation does not update the indexed attribute columns in the data table. In this case, one read CU is consumed.

  • The PUT operation updates the indexed columns in the data table. In this case, the number of read CUs that are consumed is calculated based on the following rules:

    The number of read CUs that are consumed is rounded up from the calculation result of the following formula: Number of read CUs = Size of data in indexed attribute columns of the existing row/4 KB. If the value of the rounded result is 0, one read CU is used for billing.

Update a row by performing the UPDATE operation

The row does not exist

  • If the UPDATE operation does not insert data into the indexed columns in the data table, no read CU is consumed.

  • If the UPDATE operation inserts data into the indexed columns in the data table, one read CU is consumed.

Update an existing row

  • If the UPDATE operation does not update data in the indexed attribute columns in the data table, no read CU is consumed.

  • If the UPDATE operation updates data in the indexed attribute columns in the data table, the number of read CUs that are consumed is calculated based on the following rules:

    The number of read CUs that are consumed is rounded up from the calculation result of the following formula: Number of read CUs = Size of data in indexed attribute columns of the existing row/4 KB. If the value of the rounded result is 0, one read CU is used for billing.

Delete a row by performing the DELETE operation

The number of read CUs that are consumed is calculated based on the following rules:

The number of read CUs that are consumed is rounded up from the calculation result of the following formula: Number of read CUs = Size of data in indexed attribute columns of the row/4 KB. If the value of the rounded result is 0, one read CU is used for billing.

If the data table contains an auto-increment primary key column and data is inserted into the data table, no read CU is consumed for the index table that is created for the data table. If you update a row that contains an auto-increment primary key column, read CUs are consumed. The read CUs are calculated by using the rules that are used to calculate the read CUs that are consumed when the UPDATE operation is performed on a row.

Note

If you use the auto-increment primary key column feature to write data, the number of read CUs that are consumed to create an index table is significantly reduced.

For data tables that do not contain an auto-increment primary key column, one read CU is consumed when a read operation is performed on the indexed columns, even if no data is retrieved. For data tables that contain an auto-increment primary key column, no read operation is performed on the indexed columns when you insert data. Therefore, no read CU is consumed.

Write CUs consumed to create an index table

Write CUs are consumed when a secondary index is created for a data table.

If you write a row of data to a data table, the following rules take effect when you calculate the number of write CUs that are consumed for the index table that is created for the data table based on whether the data in the index table is changed:

  • If the data in the index table is not changed, no write CU is consumed.

  • If a row is inserted into the index table, the number of write CUs that are consumed is determined based on the size of the index row that is inserted.

  • If a row in the index table is updated, the number of write CUs that are consumed is determined based on the size of data in the attribute columns of the index row that is updated.

  • If a row is deleted from the index table, the number of write CUs that are consumed is determined based on the size of data in the index row that is deleted.

  • If an index row is deleted from the index table and another index row is inserted into the index table, the number of write CUs that are consumed is determined based on the total size of data in the two rows.

The following table describes how to calculate the number of write CUs that are consumed in different scenarios.

Scenario

Billing rule

Write a row by performing the PUT operation

Write a new row

  • The PUT operation does not insert data into the indexed attribute columns in the data table. Therefore, no index row is inserted. In this case, no write CU is consumed.

  • The PUT operation inserts data into the indexed columns in the data table. Therefore, a new index row is inserted. In this case, the number of write CUs that are consumed is calculated based on the following rules for each index table:

    If a new index row is inserted, the metering method for the number of write CUs for the index table is the same as the metering method for the number of write CUs for the data table. The number of write CUs that are consumed is rounded up from the calculation result of the following formula: Number of write CUs = Size of data in the index row/4 KB. If no new index row is inserted, no write CU is consumed.

Overwrite an existing row

  • The PUT operation does not update the indexed attribute columns in the data table. In this case, no write CU is consumed.

  • The PUT operation updates the indexed columns in the data table. The write CUs are consumed based on the following rules for each index table:

    A specific number of write CUs are consumed for all indexes that are updated by the PUT operation, except for sparse indexes.

Update a row by performing the UPDATE operation

The row does not exist

  • If the UPDATE operation does not insert data into the indexed columns in the data table, no write CU is consumed.

  • If the UPDATE operation inserts data into the indexed columns in the data table, the write CUs are consumed based on the following rules for each index table:

    • If a new index row is inserted into the index table, write CUs are consumed. The number of write CUs that are consumed is rounded up from the calculation result of the following formula: Number of write CUs = Size of data in the index row/4 KB.

    • If no index row is inserted, no write CU is consumed.

Update an existing row

  • If the UPDATE operation does not update data in the indexed attribute columns in the data table, no write CU is consumed.

  • If the UPDATE operation updates data in the indexed attribute columns in the data table, the number of write CUs that are consumed is calculated based on the following rules for each index table:

    • If the index table contains an existing index row that is created based on the row that you want to update, write CUs are consumed when the delete operation is performed. The number of write CUs is determined based on the size of the primary key of the existing index row.

    • If a new index row is inserted based on the updated row, write CUs are consumed when the write operation is performed. The number of write CUs is determined based on the size of the primary key of the new index row.

    • If the UPDATE operation only updates the attribute columns of the existing index row and no new index row is inserted, write CUs are consumed when the update operation is performed.

    The number of write CUs that are consumed is rounded up from the calculation result of the following formula: Number of write CUs = Size of data in the index row/4 KB.

Delete a row by performing the DELETE operation

Write CUs are consumed based on the following rule:

If an index table contains an existing index row that is created based on the row that you want to delete, write CUs are consumed. Otherwise, no write CU is consumed. The number of write CUs that are consumed is rounded up from the calculation result of the following formula: Number of write CUs = Size of data in indexed columns and primary key columns of the row/4 KB.

If you insert data into a data table that contains an auto-increment primary key column, write CUs are consumed for the index table that is created for the data table. The write CUs are calculated by using the rules that are used to calculate the write CUs that are consumed when the PUT operation is performed on a row. If you update a row that contains an auto-increment primary key column, write CUs are consumed. The write CUs are calculated by using the rules that are used to calculate the write CUs that are consumed when the UPDATE operation is performed on a row.

Read CUs that are consumed to read an index table

When you read an index table by using the Tablestore console, Tablestore SDKs, or other methods, such as DataV, the metering rules for the read CUs that are consumed is the same as the metering rules for the read CUs that are consumed when you read a data table.

Examples

This section provides examples on how to calculate the number of CUs that are consumed when you write data to a data table for which two index tables are created.

A data table named Table contains two primary key columns named PK0 and PK1, and three predefined columns named Col0, Col1, and Col2. Two index tables named Index0 and Index1 are created for the data table. Index0 contains three primary key columns named Col0, PK0, and PK1 and one attribute column named Col2. Index1 contains four primary key columns named Col1, Col0, PK0, and PK1, and no attribute columns. In this example, the UPDATE operation is performed to update PK0 and PK1.

  • If the row does not exist in the data table:

    • If you update Col3, no read and write CUs are consumed.

    • If you update Col1, one read CU is consumed and no write CU is consumed.

    • If you update Col0 and Col1, one read CU is consumed.

      Write CUs are consumed for Index0. The number of write CUs is determined based on the total amount of data in Col0, PK0, and PK1. Write CUs are consumed for Index1. The number of write CUs is determined based on the total amount of data in Col0, Col1, PK0, and PK1.

  • If the row already exists in the data table:

    • If you update Col3, no read and write CUs are consumed.

    • If you update Col2, read CUs are consumed. The number of read CUs is determined based on the amount of data in Col0. If Col0 does not exist before, one read CU is consumed.

      If Col0 does not exist before, no write CU is consumed for Index0. If Col0 exists before, the number of write CUs that are consumed is determined based on the total amount of data in Col0, PK0, PK1, and Col2. No write CU is consumed for Index1.

    • If you update Col1, the number of read CUs that are consumed is determined based on the amount of data in the existing Col0 and Col1. If the value of the rounded result is 0, one read CU is used for billing.

      No write CU is consumed for Index0. If an index row is inserted into Index1, write CUs are consumed. The number of write CUs is determined based on the amount of data in the existing Col0 and the new Col1, PK0, and PK1. If Col0 does not exist before, no index row is inserted and no write CU is consumed. If Col0 and Col1 exist before, write CUs are consumed when you delete the existing index row. The number of write CUs is determined based on the total amount of data in the existing Col0 and Col1 and the new PK0 and PK1.