Memory Usage

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

Original topic: 内存占用

| username: 等一分钟

[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?

| username: Miracle | Original post link

If the data volume and execution plan remain unchanged, it should be fixed.

| username: 等一分钟 | Original post link

Thank you.

| username: 等一分钟 | Original post link

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?

| username: zhanggame1 | Original post link

It’s not normal. TiKV usually filters the WHERE clause and then sends the data to TiDB’s memory.

| username: TiDBer_QYr0vohO | Original post link

Basically the same.

| username: TiDBer_JUi6UvZm | Original post link

Are you only concerned about memory usage, or have you encountered any issues?

| username: TiDBer_JUi6UvZm | Original post link

Based on the text description alone, the memory should remain unchanged.

| username: YuchongXU | Original post link

It is related to system load.

| username: Jack-li | Original post link

It is not fixed.

| username: 洪七表哥 | Original post link

Of course not, it is related to parameters, data, and execution paths.

| username: 数据库真NB | Original post link

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?

| username: 等一分钟 | Original post link

No, I just want to ask if the memory occupied by SQL execution in tidb_server is the same size each time.

| username: wangkk2024 | Original post link

Got it.

| username: yulei7633 | Original post link

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

| username: oceanzhang | Original post link

The changes are minimal, unless there is a qualitative change in the execution plan.

| username: 等一分钟 | Original post link

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.

| username: 等一分钟 | Original post link

How can the memory usage be different between “select … from A.aaa join A.bbb” and “select … from B.aaa join A.bbb”?

| username: zhaokede | Original post link

It might be different.

| username: QH琉璃 | Original post link

Learn it.