• unknown's avatar
    BUG#20141 "User-defined variables are not replicated properly for SF/ · e52ec3e6
    unknown authored
               Triggers in SBR mode."
    BUG#14914 "SP: Uses of session variables in routines are not always
               replicated"
    BUG#25167 "Dupl. usage of user-variables in trigger/function is not
               replicated correctly"
    
    User-defined variables used inside of stored functions/triggers in
    statements which did not update tables directly were not replicated.
    We also had problems with replication of user-defined variables which
    were used in triggers (or stored functions called from table-updating
    statements) more than once.
    
    This patch addresses the first issue by enabling logging of all
    references to user-defined variables in triggers/stored functions
    and not only references from table-updating statements.
    
    The second issue stemmed from the fact that for user-defined
    variables used from triggers or stored functions called from
    table-updating statements we were writing binlog events for each
    reference instead of only one event for the first reference.
    This problem is already solved for stored functions called from
    non-updating statements with help of "event unioning" mechanism.
    So the patch simply extends this mechanism to the case affected.
    It also fixes small problem in this mechanism which caused wrong
    logging of references to user-variables in cases when non-updating
    statement called several stored functions which used the same
    variable and some of these function calls were omitted from binlog
    as they were not updating any tables.
    
    
    mysql-test/r/rpl_user_variables.result:
      BUG#20141 - User-defined variables are not replicated properly for SF/Triggers in SBR mode.
      This patch adds the correct results for execution of the added test procedures to the
      rpl_user_variables test.
    mysql-test/t/rpl_user_variables.test:
      BUG#20141 - User-defined variables are not replicated properly for SF/Triggers in SBR mode.
      This patch adds additional tests to the rpl_user_variables test that test many of the
      different ways user-defined variables can be required to be replicated.
    sql/item_func.cc:
      BUG#20141 - User-defined variables are not replicated properly for SF/Triggers in SBR mode.
      To properly log accesses to user-defined variables from stored functions/triggers,
      the get_var_with_binlog() method needs to log references to such variables even from 
      non-table-updating statements within them.
    sql/log.cc:
      BUG#20141 - User-defined variables are not replicated properly for SF/Triggers in SBR mode.
      This patch modifies the start_union_events method to accept the query id from a parameter.
      This allows callers to set the query_id to the id of the sub statement such as a trigger
      or stored function. Which permits the code to identify when a user defined variable has
      been used by the statement and this already present in THD::user_var_event.
      
      Note:
      The changes to sql_class.cc, sp_head.cc, and log.cc are designed to allow the proper 
      replication of access to user-defined variables under a special test case (the last case 
      shown in rpl_user_variables.test).
    sql/sp_head.cc:
      BUG#20141 - User-defined variables are not replicated properly for SF/Triggers in SBR mode.
      This patch modifies the code to allow for cases where events for function calls have
      a separate union for each event and thus cannot use the query_id of the caller as the
      start of the union. Thus, we use an artifically created query_id to set the start of 
      the events.
      
      Note:
      The changes to sql_class.cc, sp_head.cc, and log.cc are designed to allow the proper 
      replication of access to user-defined variables under a special test case (the last case 
      shown in rpl_user_variables.test).
    sql/sql_class.cc:
      BUG#20141 - User-defined variables are not replicated properly for SF/Triggers in SBR mode.
      This patch adds the query_id parameter to the calls to mysql_bin_log.start_union_events().
      
      Note:
      The changes to sql_class.cc, sp_head.cc, and log.cc are designed to allow the proper 
      replication of access to user-defined variables under a special test case (the last case 
      shown in rpl_user_variables.test).
    sql/sql_class.h:
      BUG#20141 - User-defined variables are not replicated properly for SF/Triggers in SBR mode.
      This patch adds the query_id parameter to the calls to mysql_bin_log.start_union_events().
    e52ec3e6
log.cc 86.2 KB