• Jon Olav Hauglid's avatar
    Bug #51240 ALTER TABLE of a locked MERGE table fails · 7fd30bf6
    Jon Olav Hauglid authored
    The problem was that ALTER TABLE on a merge table which was locked 
    using LOCK TABLE ... WRITE, by mistake gave 
    ER_TABLE_NOT_LOCKED_FOR_WRITE.
    
    During opening of the table to be ALTERed, open_table() tried to
    get an upgradable metadata lock. In LOCK TABLEs mode, this lock
    must already exist (i.e. taken by LOCK TABLE) as new locks of this
    type cannot be acquired for fear of deadlock. So in LOCK TABLEs
    mode, open_table() tried to find an existing upgradable lock for
    the table to be altered.
    
    The problem was that open_table() also tried to find upgradable
    metadata locks for children of merge tables even if no such
    locks are needed to execute ALTER TABLE on merge tables.
    
    This patch fixes the problem by making sure that open tables code
    only searches for upgradable metadata locks for the merge table
    and not for the merge children tables. 
    
    The patch also fixes a related bug where an upgradable metadata
    lock was aquired outside of LOCK TABLEs mode even if the table in
    question was temporary. This bug meant that LOCK TABLES or DDL on
    temporary tables by mistake could be blocked/aborted by locks held
    on base tables with the same table name by other connections.
    
    Test cases added to merge.test and lock_multi.test.
    7fd30bf6
sql_base.cc 288 KB