The tidb_last_query_info
is a system variable in TiDB used to store execution information of the last query statement. It is typically used to view various information about the last executed SQL statement, including resource consumption.
This variable mainly records information for DML (Data Manipulation Language) statements, such as INSERT
, UPDATE
, DELETE
, etc. These operations usually involve data modification and thus consume Resource Units (RU).
However, for DQL (Data Query Language) statements, such as SELECT
, SHOW
, etc., tidb_last_query_info
may not record detailed RU consumption information. Since DQL statements typically do not involve data modification, they do not directly consume RUs. Nevertheless, some complex queries, especially those involving significant computation or resource-consuming operations (such as sorting, aggregation, etc.), might be recorded in tidb_last_query_info
.
To view the information recorded in tidb_last_query_info
, you can execute the following query in TiDB’s SQL command line interface:
SELECT * FROM information_schema.tidb_last_query_info;
The information in tidb_last_query_info
is only valid for a certain period after the query execution, controlled by the system variable tidb_query_info_expire_seconds
. By default, this period might be a few minutes, but you can adjust it as needed.
If you want to understand the RU consumption of a specific SQL statement, the best approach is to examine the execution plan of that statement and analyze the resource consumption of each operation in the plan. This can be achieved using TiDB’s EXPLAIN
statement.