[MDEV-16584] SP with a cursor inside a loop wastes THD memory aggressively Created: 2018-06-26 Updated: 2018-07-02 Resolved: 2018-06-27 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Stored routines |
| Affects Version/s: | 10.0, 10.1, 10.2, 10.3, 10.4 |
| Fix Version/s: | 10.3.8, 10.4.0 |
| Type: | Bug | Priority: | Major |
| Reporter: | Alexander Barkov | Assignee: | Alexander Barkov |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | upstream-fixed | ||
| Issue Links: |
|
||||||||
| Description |
|
The problem is repeatable starting from 10.0 with help of the Memory_used status variable, but the excessive memory consumption probably also takes place in 5.5 (which does not have Memory_used). This script:
produced the following output:
The thread leaks some memory at every loop iteration. If I now comment out the line with cursor:
and rerun the script, the amount of thread memory reported permanently stays near 64K and does not grow through iterations. The problem resides in this code:
At the the push_cursor() call time, callers_area points to THD::main_mem_root, which is freed only after the SP instructions loop. Cursors should be created at some different memory root. |
| Comments |
| Comment by Alexander Barkov [ 2018-06-26 ] | ||||||||||||||||||||||||||||||
|
As this script demonstrates, the original thread memory grows from 87K to 175K after around 685 iterations:
| ||||||||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2018-06-26 ] | ||||||||||||||||||||||||||||||
|
This problem seems to be fixed in the upstream. In MySQL-8.0, sp_cursor is allocated in the system heap (rather than in the routine memory root) and is freed in sp_inst_cpop::execute(). The relevant upstream change: BUG#16857395 - EXCESSIVE MEMORY USAGE AFTER REPEATED TRIGGER | ||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2018-06-27 ] | ||||||||||||||||||||||||||||||
|
OK to push |