Bug #46747 Crash in MDL_ticket::upgrade_shared_lock_to_exclusive on TRIGGER + TEMP table
Submitted: 16 Aug 2009 16:34 Modified: 7 Mar 2010 1:54
Reporter: Philip Stoev Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Locking Severity:S2 (Serious)
Version:5.4 OS:Any
Assigned to: Dmitry Lenev CPU Architecture:Any

[16 Aug 2009 16:34] Philip Stoev
Description:
When DROP-ing a trigger that has been defined on a table that was temporarily masked by a temporary table, mysqld crashed as follows:

#3  <signal handler called>
#4  0x000000000089dfd9 in MDL_ticket::upgrade_shared_lock_to_exclusive (this=0x0) at mdl.cc:1001
#5  0x00000000006d6e71 in wait_while_table_is_used (thd=0x1948e98, table=0x18cb458, function=HA_EXTRA_FORCE_REOPEN) at sql_base.cc:2105
#6  0x0000000000874793 in mysql_create_or_drop_trigger (thd=0x1948e98, tables=0x188b2a0, create=false) at sql_trigger.cc:471
#7  0x000000000068661b in mysql_execute_command (thd=0x1948e98) at sql_parse.cc:4682
#8  0x000000000068726f in mysql_parse (thd=0x1948e98, inBuf=0x188b120 "DROP TRIGGER trigger_1", length=22, found_semicolon=0x7ffb7d26cf00)
    at sql_parse.cc:5945
#9  0x0000000000687e8a in dispatch_command (command=COM_QUERY, thd=0x1948e98, packet=0x18870c9 "DROP TRIGGER trigger_1", packet_length=22)
    at sql_parse.cc:1062
#10 0x0000000000689356 in do_command (thd=0x1948e98) at sql_parse.cc:744
#11 0x000000000067656b in handle_one_connection (arg=0x1948e98) at sql_connect.cc:1163
#12 0x000000315b0073da in start_thread () from /lib64/libpthread.so.0
#13 0x000000315a4e627d in clone () from /lib64/libc.so.6

How to repeat:
CREATE TABLE `table10_innodb` ( `int_key` int, `int` int,       key (`int_key` ));
CREATE TRIGGER trigger_1 BEFORE INSERT ON table10_innodb FOR EACH ROW  UPDATE table10_innodb SET `int_key` = 0;
CREATE TEMPORARY TABLE table10_innodb ( `int` INTEGER, `int_key` INTEGER, KEY (`int_key`) );
DROP TRIGGER trigger_1;

Between the CREATE TRIGGER and the DROP TRIGGER, we CREATE a TEMPORARY table having the same name as the standard table. This is allowed in MySQL -- the TEMPORARY table masks the previous table in the table namespace.
[19 Aug 2009 12:28] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/81068

2867 Dmitry Lenev	2009-08-19
      Fix for bug #46747 "Crash in MDL_ticket::upgrade_shared_lock_to_exclusive
                          on TRIGGER + TEMP table".
      
      Server crashed when one tried to drop trigger which had its subject 
      table shadowed by a temporary table with the same name.
      
      This problem occured because in such situation DROP TRIGGER has opened
      temporary table instead of base table on which trigger was defined.
      Attempt to upgrade metadata lock on this temporary table led to crash
      (we don't acquire metadata locks for temporary tables).
      
      This fix ensures that DROP TRIGGER ignores temporary tables when
      trying to open table on which trigger to be dropped is defined.
     @ mysql-test/r/trigger.result
        Added test case for bug #46747 "Crash in
        MDL_ticket::upgrade_shared_lock_to_exclusive
        on TRIGGER + TEMP table".
     @ mysql-test/t/trigger.test
        Added test case for bug #46747 "Crash in
        MDL_ticket::upgrade_shared_lock_to_exclusive
        on TRIGGER + TEMP table".
     @ sql/sql_trigger.cc
        Prevent DROP TRIGGER from opening temporary table which might
        shadow base table on which trigger to be dropped is defined.
[19 Aug 2009 14:13] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/81080

2868 Dmitry Lenev	2009-08-19
      Fix for bug #46747 "Crash in MDL_ticket::upgrade_shared_lock_to_exclusive
                          on TRIGGER + TEMP table".
      
      Server crashed when one tried to drop trigger which had its subject 
      table shadowed by a temporary table with the same name.
      
      This problem occured because in such situation DROP TRIGGER has opened
      temporary table instead of base table on which trigger was defined.
      Attempt to upgrade metadata lock on this temporary table led to crash
      (we don't acquire metadata locks for temporary tables).
      
      This fix ensures that DROP TRIGGER ignores temporary tables when
      trying to open table on which trigger to be dropped is defined.
     @ mysql-test/r/trigger.result
        Added test case for bug #46747 "Crash in
        MDL_ticket::upgrade_shared_lock_to_exclusive
        on TRIGGER + TEMP table".
     @ mysql-test/t/trigger.test
        Added test case for bug #46747 "Crash in
        MDL_ticket::upgrade_shared_lock_to_exclusive
        on TRIGGER + TEMP table".
     @ sql/sql_trigger.cc
        Prevent DROP TRIGGER from opening temporary table which might
        shadow base table on which trigger to be dropped is defined.
[19 Aug 2009 14:16] Dmitry Lenev
Fix for this bug was pushed into mysql-next-bugfixing team (?) tree.
[24 Aug 2009 13:54] Bugs System
Pushed into 5.4.4-alpha (revid:alik@sun.com-20090824135126-2rngffvth14a8bpj) (version source revid:dlenev@mysql.com-20090819141227-63cx8rw3qv6lbnmc) (merge vers: 5.4.4-alpha) (pib:11)
[28 Aug 2009 2:06] Paul DuBois
Noted in 5.4.4 changelog.

The server crashed for attempts to drop a trigger for which the
subject table was shadowed by a temporary table with the same name.
[9 Dec 2009 9:38] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/93285

3011 Konstantin Osipov	2009-12-09
      Backport of:
      ------------------------------------------------------------
      revno: 2617.69.32
      committer: Dmitry Lenev <dlenev@mysql.com>
      branch nick: mysql-next-bg46747
      timestamp: Wed 2009-08-19 18:12:27 +0400
      message:
        Fix for bug #46747 "Crash in MDL_ticket::upgrade_shared_lock_to_exclusive
        on TRIGGER + TEMP table".
      
        Server crashed when one tried to drop trigger which had its subject
        table shadowed by a temporary table with the same name.
      
        This problem occured because in such situation DROP TRIGGER has opened
        temporary table instead of base table on which trigger was defined.
        Attempt to upgrade metadata lock on this temporary table led to crash
        (we don't acquire metadata locks for temporary tables).
      
        This fix ensures that DROP TRIGGER ignores temporary tables when
        trying to open table on which trigger to be dropped is defined.
     @ mysql-test/r/trigger.result
        Added test case for bug #46747 "Crash in
        MDL_ticket::upgrade_shared_lock_to_exclusive
        on TRIGGER + TEMP table".
     @ mysql-test/t/trigger.test
        Added test case for bug #46747 "Crash in
        MDL_ticket::upgrade_shared_lock_to_exclusive
        on TRIGGER + TEMP table".
     @ sql/sql_trigger.cc
        Prevent DROP TRIGGER from opening temporary table which might
        shadow base table on which trigger to be dropped is defined.
[16 Feb 2010 16:49] Bugs System
Pushed into 6.0.14-alpha (revid:alik@sun.com-20100216101445-2ofzkh48aq2e0e8o) (version source revid:kostja@sun.com-20091211154405-c9yhiewr9o5d20rq) (merge vers: 6.0.14-alpha) (pib:16)
[16 Feb 2010 16:58] Bugs System
Pushed into mysql-next-mr (revid:alik@sun.com-20100216101208-33qkfwdr0tep3pf2) (version source revid:kostja@sun.com-20091209093754-jpm3ypi2tjfyc1cu) (pib:16)
[16 Feb 2010 18:47] Dmitry Lenev
Closing this bug as it is not repeatable in any publicly available tree with version < 6.0.
[6 Mar 2010 10:54] Bugs System
Pushed into 5.5.3-m3 (revid:alik@sun.com-20100306103849-hha31z2enhh7jwt3) (version source revid:vvaintroub@mysql.com-20100216221947-luyhph0txl2c5tc8) (merge vers: 5.5.99-m3) (pib:16)
[7 Mar 2010 1:54] Paul DuBois
No changelog entry needed.