All Products
Search
Document Center

Tablestore:Billable items of SQL query

Last Updated:Apr 19, 2024

The SQL query feature provides a unified access interface for multiple data engines. Computing in SQL statements does not consume read throughput. However, when you use SQL to query data, operations such as table scanning and index-based queries consume read and write throughput. This topic describes the billable items of the SQL query feature and billing examples.

Usage notes

  • You are not charged for using the SQL query feature. However, when you use the SQL query feature, you are charged fees that are generated by operations such as table scanning and index-based queries.

  • When you use the SQL query feature to query data, only read throughput is consumed.

  • If reserved read throughput is configured for data tables and indexes and the read throughput that is consumed by SQL queries exceeds the reserved read throughput, you are charged for the excess read throughput based on the pay-as-you-go billing method.

  • When you execute SQL statements to query data, the ranges of queried data and scanned data vary based on the complexity of the SQL statements. Do not use the SQL statements that scan all data in tables but use SQL statements together with indexes to maximize resource utilization.

Billable items

Billable item

Billing method

Description

Metered read throughput

  • Pay-as-you-go

  • Resource plan

The read throughput that is consumed when you execute a single SQL statement is the sum of read throughput that is consumed when specific operations are performed on the table and the index. Unit: CU

When you execute SQL statements to query data, read throughput may be consumed when you perform the following operations:

  • Operations on data tables: data scanning and queries

  • Operations on secondary indexes: data scanning and queries

  • Operations on search indexes: data queries and computing

  • Operations on time series tables: data scanning and queries

Billing examples

An order table named sample_table is created in Tablestore. The order table has one primary key column named user_id and two attribute columns named order_id and order_cost. The data type of the user_id and order_id columns is String and the data type of the order_cost column is Double. The values in the order_id and user_id columns are unique within each column. The order table contains information about 10,000 users, each with 100 rows. The total number of rows in the order table is 1 million and the size of each row is about 1 KB.

The following table describes the types of resources on which the operations are performed and the amount of read throughput that is consumed when you execute specific SQL statements.

SQL statement

Resource type

Amount of read throughput

SELECT * FROM sample_table WHERE user_id="user1"

Data table

The column in the query conditions is the primary key column. Tablestore can use the data table to query data that meets the query conditions specified by using the user_id column.

The read throughput that is consumed is 25 CUs (100 rows x 1 KB/4 KB).

SELECT sum(order_cost) FROM sample_table WHERE user_id="user1"

Data table

The column in the query conditions is the primary key column. Tablestore can use the data table to query data that meets the query conditions specified by using the user_id column. Computing in SQL statements does not consume read throughput. Only data scanning consumes read throughput.

The read throughput that is consumed is 25 CUs (100 rows x 1 KB/4 KB).

SELECT order_cost FROM sample_table WHERE order_id="order1"

Data table

The column in the query conditions is not the primary key column. If no index is used, Tablestore scans the entire table to query data that meets the query conditions specified by using the order_id column.

The read throughput that is consumed is 250,000 CUs (1 million rows x 1 KB/4 KB).

Important

In actual scenarios, Tablestore limits the use of data scanning to reduce the number of CUs consumed. We recommend that you use SQL statements together with indexes. This way, data scanning is not performed and query performance is optimized.

Data table and index

The column in the query conditions is not the primary key column. If the column is included in the index that is created for the data table, Tablestore automatically uses the index to query data that meets the query conditions specified by using the order_id column.

The read throughput that is consumed is 1 CU (rounded up from the result of 1 row x 1 KB/4 KB).