Bug #53921 | Wrong locks for SELECTs used stored functions may lead to broken SBR | ||
---|---|---|---|
Submitted: | 23 May 2010 5:32 | Modified: | 17 Dec 2010 22:43 |
Reporter: | Dmitry Lenev | Email Updates: | |
Status: | Won't fix | Impact on me: | |
Category: | MySQL Server: Locking | Severity: | S3 (Non-critical) |
Version: | 5.1.47-bzr | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[23 May 2010 5:32]
Dmitry Lenev
[23 May 2010 5:45]
Dmitry Lenev
Note the fact that we set wrong lock type for such SELECTs in parser/SQL-layer means that InnoDB tables are also affected by similar issues. See script below: --source include/have_innodb.inc --source include/have_binlog_format_mixed_or_statement.inc connect (con1, localhost, root,,); connection default; # The problem arises only in REPEATABLE-READ mode. select @@session.tx_isolation; # Returns: # @@session.tx_isolation # REPEATABLE-READ create table t1(i int) engine=innodb; create table t2(j int) engine=innodb; delimiter |; create function f1() returns int begin declare j int; select count(*) from t1 into j; insert into t2 values (j); return j; end| delimiter ;| --echo # connection 'con1' connection con1; begin; insert into t1 values (1); --echo # connection 'default' connection default; begin; select f1(); # Returns: # f1() # 0 --echo # connection 'con1' connection con1; commit; --echo # connection 'default' connection default; commit; select * from t2; # Returns: # j # 0 show binlog events; # Returns: # Log_name Pos Event_type Server_id End_log_pos Info # master-bin.000001 4 Format_desc 1 106 Server ver: 5.1.47-debug-log, Binlog ver: 4 # master-bin.000001 106 Query 1 205 use `test`; create table t1(i int) engine=innodb # master-bin.000001 205 Query 1 304 use `test`; create table t2(j int) engine=innodb # master-bin.000001 304 Query 1 526 use `test`; CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11) begin declare j int; select count(*) from t1 into j; insert into t2 values (j); return j; end # master-bin.000001 526 Query 1 594 BEGIN # master-bin.000001 594 Query 1 682 use `test`; insert into t1 values (1) # master-bin.000001 682 Xid 1 709 COMMIT /* xid=17 */ # master-bin.000001 709 Query 1 777 BEGIN # master-bin.000001 777 Query 1 860 use `test`; SELECT `test`.`f1`() # master-bin.000001 860 Xid 1 887 COMMIT /* xid=19 */ Notice that order of events in binary log contradicts contents of t2 table.
[25 May 2010 7:40]
Sveta Smirnova
Thank you for the report. Verified as described.
[17 Dec 2010 22:43]
Omer Barnir
Issue is fixed in 5.5 and will not be back ported