Bug #75879 | memory consumed quickly while executing loop in procedure | ||
---|---|---|---|
Submitted: | 12 Feb 2015 17:04 | Modified: | 27 Apr 2015 14:25 |
Reporter: | zhai weixiang (OCA) | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Utilities: Binlog Events | Severity: | S2 (Serious) |
Version: | 5.6,5.7 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[12 Feb 2015 17:04]
zhai weixiang
[12 Feb 2015 19:07]
MySQL Verification Team
Thanks for the report! Requires --log-bin --server-id=2 to repeat.
[12 Feb 2015 19:11]
MySQL Verification Team
can clearly see the set_trans_pos call gobbling up memory!
Attachment: bug75879_5.7.6_memory_profile.pdf (application/pdf, text), 14.45 KiB.
[13 Feb 2015 2:28]
zhang yingqiang
mark
[27 Apr 2015 14:25]
David Moss
Thanks for your feedback, this is fixed in upcoming versions and the following was added to the changelog: When binary logging was enabled, using stored functions and triggers resulting in a long running procedure that inserted many records caused the memory use to increase rapidly. This was due to memory being allocated per variable. The fix ensures that in such a situation, memory is allocated once and the same memory is reused.
[24 Jun 2015 4:00]
Laurynas Biveinis
commit 03c5ef5516a11cd6aafb33aaae5ae09b09f5a582 Author: Sujatha Sivakumar <sujatha.sivakumar@oracle.com> Date: Tue Mar 31 16:21:08 2015 +0530 Bug#20531812: MEMORY CONSUMED QUICKLY WHILE EXECUTING LOOP IN PROCEDURE Problem: ======== With a long running procedure the thd::main_mem_root grows very rapidly. Analysis: ======== With binlog enabled, during commit of each instruction set_trans_pos gets called which stores the current binary log file name in a variable named "m_trans_fixed_log_file". Memory for the variable is allocated from thd::main_mem_root and it is set to NULL as part of THD::cleanup_after_query() at the end of the instruction. The thd::main_mem_root also gets freed at the end of the instruction. But a procedure which inserts thousands of records, is in progrees, the thd::main_mem_root will be getting cleared only at the end of the procedure. But for each instruction within the procedure, memory will be allocated from main_mem_root and the m_trans_fixed_log_file will be set to NULL at the end of each instruction. This causes the main_mem_root to grow very rapidly as we keep on allocating 512 bytes from the main_mem_root. Fix: === At present in case of stored functions and triggers we will not reset this variable to NULL. We allocate memory once and the same memory is reused. Hence a similar fix has been implemented as part of stored procedures as well. There is flag named "sp_runtime_ctx". This flag is set to true when the execution context refers to stored procedure, stored functions, triggers and events. So now when this flag is set we will not reset the "m_trans_fixed_log_file" to NULL. The memory will be allocated once from the main_mem_root and it will be reused. Hence no memory growth.