All Products
Search
Document Center

Tablestore:Storage usage

Last Updated:Aug 01, 2023

You are charged for the storage usage of all instances within your Alibaba Cloud account on an hourly basis. Tablestore calculates the data size at a specific interval and uses the sizes that are obtained to calculate the average total data size per hour.

Note

For more information about pricing, see Tablestore pricing.

This topic describes how to calculate the data size of a single row and a single table.

Calculate the data size of a single row

Each row of data in Tablestore consumes storage space. After you configure MaxVersions or time to live (TTL), the data of each version includes the version number (8 bytes), column name, and data value.

The data size of a single row is calculated by using the following formula: Data size of a single row = Data size of primary key columns + Data size of all attribute columns. For more information, see Primary keys and attributes.

  • Data size of primary key columns = Sum of the lengths of all primary key column names + Data size of values in all primary key columns

  • For information about the size of all attribute columns, see the examples on how to calculate the size of a single row and a single table in this topic.

The following table describes the number of bytes that are used to calculate the data size of values in columns of various types.

Data type

Number of bytes

String

The number of bytes that are used by a string encoded in UTF-8. Tablestore allows empty strings. The data size of an empty string is 0.

Integer

8

Double

8

Boolean

1

Binary

The number of bytes that are used by binary data.

Example on how to calculate the data size of a single row:

The row contains only one primary key column named ID. The data type of the primary key column is Integer. Other columns are attribute columns.

ID

Name

Length

Comments

1

timestamp=1466676354000,value='zhangsan'

timestamp=1466676354000,value=20

timestamp=1466676354000,value=String(100 Bytes)

timestamp=1466679954000,value=String(150 Bytes)

In the row, the Comments column contains two valid versions of data.

  • If you set MaxVersions to 2 and TTL to 2592000:

    The data size of an attribute column is calculated by using the following formula: Data size of an attribute column = (Length of the attribute column name + 8) × Number of valid versions + Total data size of values of valid versions in the attribute column.

    Note

    If you set MaxVersions to a value greater than 1 or set TTL to a value other than -1, each version number consumes 8 bytes. In this example, a timestamp is equivalent to a version number.

    The data size of the row is the sum of 10, 20, 22, and 282 bytes, which is equal to 334 bytes. Details:

    • Data size of the primary key column: len ('ID') + len (1) = 10 bytes

    • Data size of the Name attribute column: (len ('Name') + 8) x 1 + len ('zhangsan') = 20 bytes

    • Data size of the Length column: (len ('Length') + 8) x 1 + len (20) = 22 bytes

    • Data size of the Comments column: (len ('Comments') + 8) x 2 + 100 + 150 = 282 bytes

  • If you set MaxVersions to 1 and TTL to -1:

    The data size of an attribute column is calculated by using the following formula: Data size of an attribute column = Length of the attribute column name + Total data size of the value in the attribute column.

    Note
    • If you set MaxVersions to 1 and TTL to -1, the version number does not consume bytes.

    • Although the Comments column contains values of two versions, only the latest version is calculated because MaxVersions is set to 1.

    The data size of the row is the sum of 10, 12, 14, and 158 bytes, which is equal to 194 bytes. Details:

    • Data size of the primary key column: len ('ID') + len (1) = 10 bytes

    • Data size of the Name attribute column: len ('Name') + len ('zhangsan') = 12 bytes

    • Data size of the Length attribute column: len ('Length') + len (20) = 14 bytes

    • Data size of the Comments attribute column: len ('Comments') + 150 (bytes) = 158 bytes

Calculate the data size of a single table

The data size of a table is the sum of the data sizes of all rows of data in the table. For example, a table contains one primary key column named ID and attribute columns. The following figure shows how to calculate the data size of the table when you set MaxVersions to 2 and TTL to -1.

  • Data size of the row whose value in the ID column is 1 = 10 (data size of the primary key column) + 282 (data size of the values of the two versions in the Comments column). In this case, the data size of the row whose value in the ID column is 1 is 292 bytes.

  • Data size of the row whose value in the ID column is 2 = 10 (data size of the primary key column) + 216 (data size of the value in the Comments column) + 22 (data size of the value in the Length column). In this case, the data size of the row whose value in the ID column is 2 is 248 bytes.

  • The data size of the table is the sum of 292 and 248, which is equal to 540 bytes.

If the size of the data in the table remains unchanged within 1 hour, you are charged for the storage of 540 bytes. Tablestore does not impose limits on the storage volume of a single table. You are charged for your storage usage on a pay-as-you-go basis.

Note

Tablestore asynchronously deletes data with expired TTL value and data of earlier versions if the number of versions exceeds the value that is specified for MaxVersions from each partition. Then, Tablestore calculates the amount of data in each partition. The amount of time that is consumed to delete data is related to the total size of the data. In most cases, data is deleted within 24 hours. If a delete operation is performed and then data is written to a partition, you are charged for the storage of the data after the next delete operation is performed.

Statistical period for storage usage

The metering for the storage usage of Tablestore may be delayed. In most cases, the metering for the storage usage is completed within 24 hours.

Data tables in Tablestore are implemented based on the LSM architecture. Data is written to the memory in append mode. If the data in the memory meets specified conditions, a small data file is generated. Multiple update and delete operations on a single row of data may be distributed to multiple small files. If you calculate the total size of all files, redundant metering occurs. In this case, the system performs data file compaction on a regular basis to delete redundant data and calculates the size of files after compaction. This ensures the accuracy of metering for storage usage.

After data is written, updated, or deleted, the table size may not change within a short period of time, and the metering for storage usage may be delayed. The statistical period for storage usage is the same as the period that is required by the system to perform data file compaction.