• Dmitry Shulga's avatar
    MDEV-33218: Assertion `active_arena->is_stmt_prepare_or_first_stmt_execute()... · d7758deb
    Dmitry Shulga authored
    MDEV-33218: Assertion `active_arena->is_stmt_prepare_or_first_stmt_execute() || active_arena->state == Query_arena::STMT_SP_QUERY_ARGUMENTS' failed in st_select_lex::fix_prepare_information
    
    In case there is a view that queried from a stored routine or
    a prepared statement and this temporary table is dropped between
    executions of SP/PS, then it leads to hitting an assertion
    at the SELECT_LEX::fix_prepare_information. The fired assertion
     was added by the commit 85f2e4f8
    (MDEV-32466: Potential memory leak on executing of create view statement).
    Firing of this assertion means memory leaking on execution of SP/PS.
    Moreover, if the added assert be commented out, different result sets
    can be produced by the statement SELECT * FROM the hidden table.
    
    Both hitting the assertion and different result sets have the same root
    cause. This cause is usage of temporary table's metadata after the table
    itself has been dropped. To fix the issue, reload the cache of stored
    routines. To do it  cache of stored routines is reset at the end of
    execution of the function dispatch_command(). Next time any stored routine
    be called it will be loaded from the table mysql.proc. This happens inside
    the method Sp_handler::sp_cache_routine where loading of a stored routine
    is performed in case it missed in cache. Loading is performed unconditionally
    while previously it was controlled by the parameter lookup_only. By that
    reason the signature of the method Sroutine_hash_entry::sp_cache_routine
    was changed by removing unused parameter lookup_only.
    
    Clearing of sp caches affects the test main.lock_sync since it forces
    opening and locking the table mysql.proc but the test assumes that each
    statement locks its tables once during its execution. To keep this invariant
    the debug sync points with names "before_lock_tables_takes_lock" and
    "after_lock_tables_takes_lock" are not activated on handling the table
    mysql.proc
    d7758deb
sql_base.cc 308 KB