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.
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.
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?
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:
Number of rows + timeout
Number of rows + memory limit
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.
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.
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.