diff options
author | Alexander Barkov <bar@mariadb.com> | 2018-06-28 16:55:42 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2018-06-28 16:55:42 +0400 |
commit | 724a5105cba31fe48bd0a2754d074d8942b21153 (patch) | |
tree | ce032fcc6a755ed17768ba8cf457e5196942391e /sql/sp_rcontext.h | |
parent | 445339feac2b9f0164870b3c90b20b2075d117bb (diff) | |
download | mariadb-git-724a5105cba31fe48bd0a2754d074d8942b21153.tar.gz |
MDEV-16584 SP with a cursor inside a loop wastes THD memory aggressively
Problem:
push_handler() created sp_handler_entry instances on THD::main_mem_root,
which is freed only after the SP instructions execution.
So in case of a CONTINUE HANDLER inside a loop (e.g. WHILE) this approach
leaked thread memory on every loop iteration.
Changes:
- Removing sp_handler_entry declaration, it's not really needed.
- Fixing the data type of sp_rcontext::m_handlers from
Dynamic_array<sp_handler_entry*> to Dynamic_array<sp_instr_hpush_jump*>
- Fixing sp_rcontext::push_handler() to push the pointer to
an sp_instr_hpush_jump instance to the handler stack.
This instance contains everything we need.
There is no a need to allocate anything else.
Diffstat (limited to 'sql/sp_rcontext.h')
-rw-r--r-- | sql/sp_rcontext.h | 34 |
1 files changed, 6 insertions, 28 deletions
diff --git a/sql/sp_rcontext.h b/sql/sp_rcontext.h index 40d636b3529..b02ba14b99b 100644 --- a/sql/sp_rcontext.h +++ b/sql/sp_rcontext.h @@ -31,6 +31,7 @@ class sp_cursor; class sp_lex_keeper; class sp_instr_cpush; +class sp_instr_hpush_jump; class Query_arena; class sp_head; class Item_cache; @@ -87,27 +88,6 @@ private: sp_rcontext(const sp_rcontext &); void operator=(sp_rcontext &); -private: - /// This is an auxillary class to store entering instruction pointer for an - /// SQL-handler. - class sp_handler_entry : public Sql_alloc - { - public: - /// Handler definition (from parsing context). - const sp_handler *handler; - - /// Instruction pointer to the first instruction. - uint first_ip; - - /// The constructor. - /// - /// @param _handler sp_handler object. - /// @param _first_ip first instruction pointer. - sp_handler_entry(const sp_handler *_handler, uint _first_ip) - :handler(_handler), first_ip(_first_ip) - { } - }; - public: /// This class stores basic information about SQL-condition, such as: /// - SQL error code; @@ -235,18 +215,16 @@ public: // SQL-handlers. ///////////////////////////////////////////////////////////////////////// - /// Create a new sp_handler_entry instance and push it to the handler call - /// stack. + /// Push an sp_instr_hpush_jump instance to the handler call stack. /// - /// @param handler SQL-handler object. - /// @param first_ip First instruction pointer of the handler. + /// @param entry The condition handler entry /// /// @return error flag. /// @retval false on success. /// @retval true on error. - bool push_handler(sp_handler *handler, uint first_ip); + bool push_handler(sp_instr_hpush_jump *entry); - /// Pop and delete given number of sp_handler_entry instances from the handler + /// Pop and delete given number of instances from the handler /// call stack. /// /// @param count Number of handler entries to pop & delete. @@ -411,7 +389,7 @@ private: bool m_in_sub_stmt; /// Stack of visible handlers. - Dynamic_array<sp_handler_entry *> m_handlers; + Dynamic_array<sp_instr_hpush_jump *> m_handlers; /// Stack of caught SQL conditions. Dynamic_array<Handler_call_frame *> m_handler_call_stack; |