# TiDB Server Logs - Expensive Query 

+ When a statement reaches the resource usage threshold during execution (execution time < tidb_expensive_query_time_threshold >/amount of memory used< mem-quota-query >), TiDB will instantly write this query details to tidb-server log.
```
[2020/02/05 15:32:25.096 +08:00] [WARN] [expensivequery.go:167] [expensive_query] [cost_time=60.008338935s] [wait_time=0s] [request_count=1] [total_keys=70] [process_keys=65] [num_cop_tasks=1] [process_avg_time=0s] [process_p90_time=0s] [process_max_time=0s] [process_max_addr=10.0.1.9:20160] [wait_avg_time=0.002s] [wait_p90_time=0.002s] [wait_max_time=0.002s] [wait_max_addr=10.0.1.9:20160] [stats=t:pseudo] [conn_id=60026] [user=root] [database=test] [table_ids="[122]"] [txn_start_ts=414420273735139329] [mem_max="1035 Bytes (1.0107421875 KB)"] [sql="insert into t select sleep(1) from t"]
```
-------------------------------------------------------------
- TiDB will output the statements whose execution time exceeds the tidb_expensive_query_time_threshold limit (the default value is 60s) or the memory usage exceeds the mem-quota-query limit (the default value is 1 GB) to the tidb-server log file (the default file is "tidb.log" )middle. This type of SQL is called an expensive query.

- “Note that the difference between the expensive query log and the slow query log is that the slow query log is printed after the statement is executed, and the expensive query log can print out the relevant information about the statement being executed. When a statement reaches the resource usage threshold (execution time/amount of memory used) during execution, TiDB will immediately write the relevant information of the statement to the log.”

- In tidb.log grep "expensive_query", you can see the following information:

[2020/02/05 15:32:25.096 +08:00] [WARN] [expensivequery.go:167] [expensive_query] [cost_time=60.008338935s] [wait_time=0s] [request_count=1] [total_keys=70] [process_keys=65] [num_cop_tasks=1] [process_avg_time=0s] [process_p90_time=0s] [process_max_time=0s] [process_max_addr=10.0.1.9:20160] [wait_avg_time=0.002s] [wait_p90_time=0.002s] [wait_max_time=0.002s] [wait_max_addr=10.0.1.9:20160] [stats=t:pseudo] [conn_id=60026] [user=root] [database=test] [table_ids="[122]"] [txn_start_ts=414420273735139329] [mem_max="1035 Bytes (1.0107421875 KB)"] [sql="insert into t select sleep(1) from t"]

Fields related to memory usage:
- mem_max: The memory space already used by the statement when the log is printed. This item identifies memory usage in two units, Bytes, and an easy-to-read adaptive unit (such as MB, GB, etc.).


