[MDEV-21447] Uncontrollable memory allocation with TRIGGERS, PROCEDURES and FUNCTIONS Created: 2020-01-09 Updated: 2023-12-12 |
|
| Status: | Stalled |
| Project: | MariaDB Server |
| Component/s: | Server, Stored routines |
| Affects Version/s: | 10.1, 10.4.11, 10.2, 10.3, 10.4 |
| Fix Version/s: | 10.4 |
| Type: | Bug | Priority: | Major |
| Reporter: | Eimantas | Assignee: | Dmitry Shulga |
| Resolution: | Unresolved | Votes: | 3 |
| Labels: | memory, upstream | ||
| Environment: |
Any |
||
| Attachments: |
|
||||||||
| Issue Links: |
|
||||||||
| Description |
|
I have project with 8 databases, each 500Mb. Notices excessibe memory usage 128GB is not the limit. Prepared simple DB structure examples: In such DB simple (imposible query) is enougth to massivie memory usage:
Could not find server config variables that could limit such memory usage. Tried script on hosting servers with shared MySQL/MariaDB service - all of them failed using this kind of script. 256 tables script (expected 512GB memory usage) would kill almost any server. |
| Comments |
| Comment by Elena Stepanova [ 2020-01-09 ] | |||||||||||
|
eimix, thanks a lot for the report with the test case. Reproducible as described on MariaDB 10.1-10.5 and MySQL 5.7 (I didn't try 5.6 or 8.0). sanja (or whoever ends up debugging it), be careful with dSTAR64, it can indeed render your machine non-responsive, depending on how much memory you have. I think dSTAR16 is enough for debugging. | |||||||||||
| Comment by Eimantas [ 2020-01-11 ] | |||||||||||
|
"Tested" on free hosting server for longer time. Consider to make db structure atachements "not public". | |||||||||||
| Comment by Oleksandr Byelkin [ 2020-04-02 ] | |||||||||||
|
It looks like table definition cache problem. | |||||||||||
| Comment by Oleksandr Byelkin [ 2020-04-03 ] | |||||||||||
|
OK, I also checked 5.5 it also return end of resources error. and it is kind of expected, because trigger update tables and uses function which update tables and triger triggers which... and so on. So could someone explain me why such recursion should not eat all resources? | |||||||||||
| Comment by Oleksandr Byelkin [ 2020-04-03 ] | |||||||||||
|
CURRENT_TEST: main.test | |||||||||||
| Comment by Eimantas [ 2020-04-03 ] | |||||||||||
|
1. This is artificial test case - recursion is not needed to achieve high RAM usage If procedure AAA is used in procedures BBB and CCC, memory for AAA procedure's code is allocated 3 times. 2. On shared hosting servers - any user with similar script can "kill" server, and use resources without limit, and no way to configure limits. | |||||||||||
| Comment by Oleksandr Byelkin [ 2020-04-03 ] | |||||||||||
|
MariaDB have to open and lock tables used in one query at once (including triggers) and each time table used it add the table to the list, so no surprise that opening all tables which TRIGGERS/functions needs require a lot of resources, what is wrong? Also in my case memory quite controlled, it return EOM error I tested 5.5 10.1 and 10.5. Maybe problem in allowing mysql using more resources than computer really has? | |||||||||||
| Comment by Eimantas [ 2020-04-03 ] | |||||||||||
|
How this could be normal? mysql uses ram accordingly to my.ini, and there is no docomented variable to control this. | |||||||||||
| Comment by Oleksandr Byelkin [ 2020-04-03 ] | |||||||||||
|
OK, I got the problem (in my case it was limited by number of file). So the problem is that do not work one of memory limits (of we have such). | |||||||||||
| Comment by Oleksandr Byelkin [ 2020-04-08 ] | |||||||||||
|
I have impression that SP/TRIGGERS here only allow easy open thouthands of tables for one query. if one make the same with one query it will be the same. I can try to make query with subqueries and several thouthands of tables to open, but have not an idea how to make it automatically... | |||||||||||
| Comment by Oleksandr Byelkin [ 2020-04-08 ] | |||||||||||
|
ah and difference with 5.5 is table cache overhead... | |||||||||||
| Comment by Eimantas [ 2020-04-08 ] | |||||||||||
|
MySQL 5.6, 5.7, 8.0 has same problem, Last message was some debug info: Leak of 6910660480 bytes in 151130 objects allocated from: | |||||||||||
| Comment by Oleksandr Byelkin [ 2020-04-08 ] | |||||||||||
|
just for record the script with 16 actually opens something between 1024 and 2048 files (not 16*3) the script with 64 opens more that 4096 files before been killed for too big memory allocation. | |||||||||||
| Comment by Oleksandr Byelkin [ 2020-04-08 ] | |||||||||||
|
play with vlimit shows that script 16 uses something between 4 and 2 GB of memory (1-4MB per file so 2-3 times more for table) | |||||||||||
| Comment by Oleksandr Byelkin [ 2020-04-08 ] | |||||||||||
|
it is how triggers parsed, so for each table triggers goes to table memory. | |||||||||||
| Comment by Oleksandr Byelkin [ 2020-04-08 ] | |||||||||||
|
Statistic of usage is following: so 1.1 has even less ration memory per file, the probem is in many files opened by 10.1 | |||||||||||
| Comment by Oleksandr Byelkin [ 2020-04-08 ] | |||||||||||
|
according to internal statistics server uses for execution the UPDATE:
10.1 statistics is dubious because it needs higher limit by opened files in OS then it reported in statistics | |||||||||||
| Comment by Eimantas [ 2020-04-08 ] | |||||||||||
|
Expected this to be related to complexity/size of triggers, procedures and functions. | |||||||||||
| Comment by Oleksandr Byelkin [ 2020-04-09 ] | |||||||||||
|
almost 2 times more files opened and incorrect statistics by opened files it is problems caused by WSREP. | |||||||||||
| Comment by JiraAutomate [ 2023-12-05 ] | |||||||||||
|
Automated message: |