• Dmitry Lenev's avatar
    Fix for bug #55273 "FLUSH TABLE tm WITH READ LOCK for Merge · 3326614d
    Dmitry Lenev authored
    table causes assert failure".
    
    Attempting to use FLUSH TABLE table_list WITH READ LOCK
    statement for a MERGE table led to an assertion failure if
    one of its children was not present in the list of tables
    to be flushed. The problem was not visible in non-debug builds.
    
    The assertion failure was caused by the fact that in such
    situations FLUSH TABLES table_list WITH READ LOCK implementation
    tried to use (e.g. lock) such child tables without acquiring
    metadata lock on them. This happened because when opening tables
    we assumed metadata locks on all tables were already acquired
    earlier during statement execution and a such assumption was
    false for MERGE children.
    
    This patch fixes the problem by ensuring at open_tables() time
    that we try to acquire metadata locks on all tables to be opened. 
    For normal tables such requests are satisfied instantly since
    locks are already acquired for them. For MERGE children metadata
    locks are acquired in normal fashion.
    
    Note that FLUSH TABLES merge_table WITH READ LOCK will lock for
    read both the MERGE table and its children but will flush only 
    the MERGE table. To flush children one has to mention them in table
    list explicitly. This is expected behavior and it is consistent with
    usage patterns for this statement (e.g. in mysqlhotcopy script).
    3326614d
flush.test 13.9 KB