• Dmitry Shulga's avatar
    Fixed bug#11753738 (formely known as bug#45235) - 5.1 DOES NOT SUPPORT 5.0-ONLY · 1fea8c1b
    Dmitry Shulga authored
    SYNTAX TRIGGERS IN ANY WAY
    
    Table with triggers which were using deprecated (5.0-only) syntax became
    unavailable for any DML and DDL after upgrade to 5.1 version of server.
    Attempt to execute any statement on such a table resulted in parsing
    error reported. Since this included DROP TRIGGER and DROP TABLE
    statements (actually, the latter was allowed but was not functioning
    properly for such tables) it was impossible to fix the problem without
    manual operations on .TRG and .TRN files in data directory.
    
    The problem was that failure to parse trigger body (due to 5.0-only
    syntax) when opening trigger file for a table prevented the table
    from being open. This made all operations on the table impossible
    (except DROP TABLE which due to peculiarity in its implementation
    dropped the table but left trigger files around).
    
    This patch solves this problem by silencing error which occurs when
    we parse trigger body during table open. Error message is preserved
    for the future use and table is marked as having a broken trigger.
    We also try to analyze parse tree to recover trigger name, which
    will be needed in order to drop the broken trigger. DML statements
    which invoke triggers on the table marked as having broken trigger
    are prohibited and emit saved error message. The same happens for
    DDL which change triggers except DROP TRIGGER and DROP TABLE which
    try their best to do what was requested. Table becomes no longer
    marked as having broken trigger when last such trigger is dropped.
    
    mysql-test/r/trigger-compat.result:
      Add results for test case for bug#45235
    mysql-test/t/trigger-compat.test:
      Add test case for bug#45235.
    sql/sp_head.cc:
      Added protection against MEM_ROOT double restoring to
      sp_head::restore_thd_mem_root() method. Since this
      method can be sometimes called twice during parsing
      of stored routine (the first time during normal flow
      of parsing, and the second time when a syntax error
      is detected) we need to shortcut execution of the
      method to avoid damaging MEM_ROOT by the second
      consecutive call to this method.
    sql/sql_trigger.cc:
      Added error handler Deprecated_trigger_syntax_handler to 
      catch non-OOM errors during parsing of trigger body.
      
      Added handling of parse errors into method 
      Table_triggers_list::check_n_load().
    sql/sql_trigger.h:
      Added new members to handle broken triggers and error messages.
    1fea8c1b
trigger-compat.test 8.31 KB