Out of memory quota

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

Original topic: out of memory quota

| username: 等一分钟

Sorry, I can’t assist with that.

| username: 等一分钟 | Original post link

The memory usage of this SQL exceeded 1GB. Is there any way to confirm which table is occupying it?

Because when I delete a few select fields from the SQL, it works fine.

| username: xfworld | Original post link

SQL is not like this…

| username: 等一分钟 | Original post link

I have the SQL, but I don’t know which subquery is using more memory.

| username: 等一分钟 | Original post link

Or checked which table is occupying more memory, using explain analyze to check memory usage is not much either.

| username: caiyfc | Original post link

Expand the execution plan on the dashboard, and on the far right, it shows the memory usage of each operator. Then, based on the execution plan, you can identify which table is using more memory.

| username: 等一分钟 | Original post link

The image you provided is not accessible. Please provide the text you need translated.

| username: 等一分钟 | Original post link

I deleted some fields and it can be executed now, but it still shows that 1G is being used here.

| username: 胡杨树旁 | Original post link

Expand this section, and you will see the memory usage behind the execution plan.

| username: 等一分钟 | Original post link

The memory here is cumulative, right?

| username: 等一分钟 | Original post link

The variable tidb_mem_quota_query cannot be set globally in version 5.0.2, right?

| username: 裤衩儿飞上天 | Original post link

System Variables | PingCAP Docs

| username: WalterWj | Original post link

It seems there is disk usage, so SQL has written to disk.

However, looking at the execution plan, the memory usage is not much. Could it be that the statistics are incorrect? :thinking:

| username: 等一分钟 | Original post link

I’ll try updating all the statistics.

| username: 等一分钟 | Original post link

The execution plan above is only a part of it; there was too much to capture it all.

| username: caiyfc | Original post link

In the case of complex SQL, it’s better to adjust the memory. A 1GB memory limit is indeed a bit small; we usually set it to 10GB.

| username: 等一分钟 | Original post link

If a single SQL query uses up to 10GB, will it cause the server’s memory to OOM (Out of Memory)?

| username: 等一分钟 | Original post link

This SQL is complex, but the data volume is not large.

| username: 等一分钟 | Original post link

It can be queried in 6-7 seconds without any errors.

| username: caiyfc | Original post link

There is indeed such a risk, but if you handle the SQL statements well, the server OOM situation will basically not occur.