Issues Related to Expensive Queries

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: expensive query的相关问题

| username: Raymond

According to the official documentation, when the number of rows queried (including intermediate results, based on statistical information) exceeds the value of this parameter (expensive-threshold), the operation will be considered an expensive query, and a log with the prefix [EXPENSIVE_QUERY] will be output. However, when I tested it myself, even with a full table scan of a table with 76,568 rows, the tidb.log did not show EXPENSIVE_QUERY. Does this mean that in order for tidb.log to generate an expensive query, it also needs to meet the values set by tidb_mem_quota_query or tidb_expensive_query_time_threshold? Just reaching the expensive-threshold is not enough? You can try it yourself; it’s easy to test.

| username: xfworld | Original post link

The documentation introduces it. It shows the number of detailed rows output, which triggers this positioning. It still relies on the default settings described in the figure, but you can also modify this configuration according to the scenario requirements.

| username: xiaohetao | Original post link

:+1::+1::+1::+1:

| username: ddhe9527 | Original post link

Bumping the thread, I have the same question as the original poster. What is the purpose of the TiDB configuration item expensive-threshold? What is the logical relationship between it and mem-quota-query, tidb_expensive_query_time_threshold?

| username: Raymond | Original post link

So what role does this parameter expensive-threshold play?

| username: xfworld | Original post link

The concept of three indispensable parameters (when we configure overall resources, there will definitely be a limit on the resources occupied or used by a single SQL, which can also be called a safety limit), and then I understand it as a combination of usage. For example:

  1. Number of rows + timeout
  2. Number of rows + memory limit
  3. Number of rows + timeout + memory limit
    This helps to measure which queries will exceed this range, so we can record it, making it easier to troubleshoot later, which is essentially a positioning function.
| username: Raymond | Original post link

I roughly understand, thank you, teacher. It seems that the official documentation doesn’t fully explain it, so it might be necessary to test it yourself or look through the code.

| username: h5n1 | Original post link

tidb_expensive_query_time_threshold is an environment variable that can be modified online using the set session/global method. When the SQL execution time exceeds this threshold, it will be recorded in the expensive_query section of tidb.log.

expensive-threshold is a parameter that needs to be modified using commands like tiup edit-config. This parameter is used to determine whether the steps in the execution plan exceed the threshold based on statistical information. If the threshold is exceeded, the actual execution will run with low priority. It seems that this is not recorded in tidb.log. Currently, only SQLs that exceed expensive_query_time and memory_quota are recorded in tidb.log.

| username: ddhe9527 | Original post link

Is the expensive-threshold just a placeholder for now?

| username: Raymond | Original post link

Boss, excellent.

| username: system | Original post link

This topic was automatically closed 1 minute after the last reply. No new replies are allowed.