Bug #25167 Dupl. usage of user-variables in trigger/function is not replicated correctly
Submitted: 19 Dec 2006 9:32 Modified: 9 Mar 2007 14:29
Reporter: Dmitry Lenev Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Replication Severity:S3 (Non-critical)
Version:5.0.34-BK, 5.0.32 OS:Linux (Linux Suse 10.1)
Assigned to: Chuck Bell CPU Architecture:Any

[19 Dec 2006 9:32] Dmitry Lenev
Description:
Some statements which invoke triggers which use same user variable twice in their body can be replicated incorrectly.
The same happens for table-modifying statement which use stored functions which use same user variable twice.

See "How to repeat" section for more info.

Also bug #20141 is related to this bug.

How to repeat:
# Here is small test for mysqltest which demonstrates the problem
create table t1 (i int);
create table t2 (k int);
delimiter |;
create trigger t1_bi before insert on t1 for each row
begin
  insert into t2 values (@a);
  set @a:=42;
  insert into t2 values (@a);
end|
delimiter ;|
set @a:=100;
insert into t1 values (5);
show binlog events;
# Log_name      Pos     Event_type      Server_id       End_log_pos     Info
# master-bin.000001     4       Format_desc     1       98      Server ver: 5.0.32-debug-log, Binlog ver: 4
# master-bin.000001     98      Query   1       184     use `test`; create table t1 (i int)
# master-bin.000001     184     Query   1       270     use `test`; create table t2 (k int)
# master-bin.000001     270     Query   1       491     use `test`; CREATE DEFINER=`root`@`localhost` trigger t1_bi before insert on t1 for each row
# begin
# insert into t2 values (@a);
# set @a:=42;
# insert into t2 values (@a);
# end
#
# Here we have two User_var events for the same variable, as only
# second of them will affect execution of insert statement replication
# will be broken.
#
# master-bin.000001     491     User var        1       533     @`a`=100
# master-bin.000001     533     User var        1       575     @`a`=42
# master-bin.000001     575     Query   1       663     use `test`; insert into t1 values (5)

# Another test snippet that demonstrates problem for stored functions
create table t1 (i int);
create table t2 (k int);
delimiter |;
create function f1() returns int
begin
  insert into t2 values (@a);
  set @a:=42;
  insert into t2 values (@a);
  return 5;
end|
delimiter ;|
set @a:=100;
insert into t1 values (f1());
show binlog events;
# Log_name      Pos     Event_type      Server_id       End_log_pos     Info
# master-bin.000001     4       Format_desc     1       98      Server ver: 5.0.32-debug-log, Binlog ver: 4
# master-bin.000001     98      Query   1       184     use `test`; create table t1 (i int)
# master-bin.000001     184     Query   1       270     use `test`; create table t2 (k int)
# master-bin.000001     270     Query   1       480     use `test`; CREATE DEFINER=`root`@`localhost` function f1() returns int
# begin
# insert into t2 values (@a);
# set @a:=42;
# insert into t2 values (@a);
# return 5;
# end
#
# Ok, below we can see problem as with triggers
#
# master-bin.000001     480     User var        1       522     @`a`=100
# master-bin.000001     522     User var        1       564     @`a`=42
# master-bin.000001     564     Query   1       663     use `test`; insert into t1 values (f1())
[19 Dec 2006 20:54] Valeriy Kravchuk
Thank you for a bug report. Verified just as described, aslo - with latest 5.0.34-BK on Linux.
[11 Jan 2007 0:17] Chuck Bell
The patch for this bug is satisfied by the patch for BUG#20141. Please see BUG#20141 for more details.
[8 Mar 2007 8:00] Andrei Elkin
fixed in 5.0.38,5.1.17-beta
[8 Mar 2007 8:08] Andrei Elkin
"fixed" above meant pushed
[9 Mar 2007 14:29] MC Brown
A note has been added to the 5.1.17 and 5.0.38 changelogs.