Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: 在运行SQL文件时报错
[TiDB Usage Environment] Production Environment / Testing / PoC
[TiDB Version]
[Reproduction Path] What operations were performed to encounter the issue
Running insert statement SQL file
[Encountered Issue: Issue Phenomenon and Impact]
Error occurred
Your query has been cancelled due to exceeding the allowed memory limit for a single SQL query. Please try narrowing your query scope or increase the tidb_mem_quota_query limit and try again.
Due to exceeding the allowed memory limit, your query has been cancelled
[Resource Configuration] Go to TiDB Dashboard - Cluster Info - Hosts and take a screenshot of this page
[Attachments: Screenshots / Logs / Monitoring]
Increase the parameter a bit.
The SQL query exceeded the memory limit. If resources are sufficient, try adjusting the tidb_mem_quota_query.
Why am I not getting this prompt when a single statement exceeds memory?
But the reason is the same, the memory used by the statement exceeds the limit set by tidb_mem_quota_query.
Increase the value of the tidb_mem_quota_query
parameter in the TiDB configuration file to expand the memory limit available for a single query.
The default tidb_mem_quota_query
is 1g. If it’s not enough, try increasing it to 4g or 8g.
Why doesn’t it take effect after adding it?
Use set
SET GLOBAL tidb_server_memory_limit = “32GB”;
How to Configure the Memory Usage Threshold for a SQL Execution
Use the system variable tidb_mem_quota_query
to configure the memory usage threshold for a SQL execution, with the unit in bytes. For example:
Configure the memory usage threshold for the entire SQL to 8GB:
SET tidb_mem_quota_query = 8 << 30;
Configure the memory usage threshold for the entire SQL to 8MB:
SET tidb_mem_quota_query = 8 << 20;
Configure the memory usage threshold for the entire SQL to 8KB:
SET tidb_mem_quota_query = 8 << 10;
That 8KB is somewhat risky. I remember a classmate set it like this before, and as a result, the cluster couldn’t even start because internal SQL was also restricted~~~
So it can be more reliable with the unit.
No, it was a classmate who saw that it could be set so small and wanted to see what effect it would have after setting it small. Fortunately, it was tested in a personal test environment at that time.
I’ll try it later as well. At what setting did you encounter the issue?
It’s not me, it’s a community member. You can try setting it to 8KB. 
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.