Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: 内存占用
[TiDB Usage Environment] Production Environment
[TiDB Version] 6.1.0
For the same SQL, is the memory occupied by tidb_server fixed and unchanged each time it is executed?
If the data volume and execution plan remain unchanged, it should be fixed.
For example, if an SQL execution takes up 1GB of memory, and then some filter conditions are removed, the amount of data queried should be larger, but the memory usage is actually smaller. Is this phenomenon normal?
It’s not normal. TiKV usually filters the WHERE clause and then sends the data to TiDB’s memory.
Are you only concerned about memory usage, or have you encountered any issues?
Based on the text description alone, the memory should remain unchanged.
It is related to system load.
Of course not, it is related to parameters, data, and execution paths.
Are you asking if the query results will be cached in memory after the first query, affecting the query time when the same query is executed again within a short period?
No, I just want to ask if the memory occupied by SQL execution in tidb_server is the same size each time.
The same SQL, size unchanged:
Below are the memory-related configurations for tidb-server:
Query:
show variables like ‘%quota%’;
tidb_mem_quota_query====> The memory size allocated for each SQL query
show variables like ‘%oom%’;
tidb_mem_oom_action | CANCEL | or LOG ===> Directly recorded in the log file
tidb_mem_oom_action====> If the memory size allocated for each SQL query exceeds the value of tidb_mem_quota_query,
and temporary disk is enabled, but the temporary disk has no space, this parameter controls whether to cancel or continue using
Enable temporary disk:
show variables like ‘tidb_enable_tmp_storage_on_oom’;
| tidb_enable_tmp_storage_on_oom | ON |
show config where name like ‘%tmp-storage-path%’;
tmp-storage-path
show config where name like ‘%tmp-storage-quota%’;
tmp-storage-quota
The changes are minimal, unless there is a qualitative change in the execution plan.
After deleting isdeleted=0 here, the data volume should theoretically increase, and the memory usage should logically also increase. However, after actual execution, it was found that the memory usage was actually less.
How can the memory usage be different between “select … from A.aaa join A.bbb” and “select … from B.aaa join A.bbb”?