• Alexander Barkov's avatar
    MDEV-16584 SP with a cursor inside a loop wastes THD memory aggressively · 56145be2
    Alexander Barkov authored
    Problem:
    
    push_cursor() created sp_cursor instances on THD::main_mem_root,
    which is freed only after the SP instructions loop.
    
    Changes:
    - Moving sp_cursor declaration from sp_rcontext.h to sql_class.h
    - Deriving sp_instr_cpush from sp_cursor. So now sp_cursor is created
      only once (at the SP parse time) and then reused on all loop iterations
    - Adding a new method reset() into sp_cursor (and its parent classes)
      to reset an sp_cursor instance before reuse.
    - Moving former sp_cursor members m_fetch_count, m_row_count, m_found
      into a separate class sp_cursor_statistics. This helps to reuse
      the code in sp_cursor constructors, and in sp_cursor::reset()
    - Adding a helper method sp_rcontext::pop_cursor().
    - Adding "THD*" parameter to so_rcontext::pop_cursors() and pop_all_cursors()
    - Removing "new" and "delete" from sp_rcontext::push_cursor() and
      sp_rconext::pop_cursor().
    - Fixing sp_cursor not to derive from Sql_alloc, as it's now allocated
      only as a part of sp_instr_cpush (and not allocated separately).
    - Moving lex_keeper->disable_query_cache() from sp_cursor::sp_cursor()
      to sp_instr_cpush::execute().
    - Adding tests
    56145be2
sp_rcontext.cc 26.5 KB