Bug #27329 rollback of SF() due to dealock asserts in ha_rollback_trans()
Submitted: 21 Mar 2007 14:00 Modified: 21 Mar 2007 14:17
Reporter: Andrei Elkin Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S3 (Non-critical)
Version:5.0.38 OS:
Assigned to: CPU Architecture:Any

[21 Mar 2007 14:00] Andrei Elkin
Description:
In case of deadlock connection executing 
select SF() hits assert(0); SF() is defined with queries on innodb table.

#0  ha_rollback_trans (thd=0x8b88cf0, all=true) at handler.cc:791
#1  0x082907a6 in convert_error_code_to_mysql (error=-1265058672, 
    thd=0x8b89648) at ha_innodb.cc:459
#2  0x08296e7f in ha_innobase::index_read (this=0x8bbf858, 
    buf=0x8bbf980 "ý\002", key_ptr=0x8bf63e0 "\002", key_len=4, 
    find_flag=HA_READ_KEY_EXACT) at ha_innodb.cc:3850
#3  0x082838f6 in handler::read_range_first (this=0x8bbf858, 
    start_key=0x8be82f8, end_key=0x8be8304, eq_range_arg=true, sorted=false)
    at handler.cc:2633
#4  0x08283baa in handler::read_multi_range_first (this=0x8bbf858, 
    found_range_p=0xb498bdd8, ranges=0x8be82f8, range_count=1, sorted=false, 
    buffer=0x0) at handler.cc:2507
#5  0x08269a3b in QUICK_RANGE_SELECT::get_next (this=0x8bd8228)
    at opt_range.cc:6750
#6  0x0827ef60 in rr_quick (info=0xb498bf8c) at records.cc:224
#7  0x08235cf5 in mysql_update (thd=0x8b88cf0, table_list=0x8bc9a38, 
    fields=@0x8bbdba0, values=@0x8bbdd8c, conds=0x8bc9e08, order_num=0, 
    order=0x0, limit=566935683072, handle_duplicates=DUP_ERROR, ignore=false)
    at sql_update.cc:447
#8  0x081ca399 in mysql_execute_command (thd=0x8b88cf0) at sql_parse.cc:3428
#9  0x082fe83f in sp_instr_stmt::exec_core (this=0x8bc9f00, thd=0x8b88cf0, 
    nextp=0xb498cc6c) at sp_head.cc:2551
#10 0x082fea7c in sp_lex_keeper::reset_lex_and_exec_core (this=0x8bc9f28, 
    thd=0x8b88cf0, nextp=0xb498cc6c, open_tables=false, instr=0x8bc9f00)
    at sp_head.cc:2400
#11 0x083050c0 in sp_instr_stmt::execute (this=0x8bc9f00, thd=0x8b88cf0, 
    nextp=0xb498cc6c) at sp_head.cc:2504
#12 0x083026c6 in sp_head::execute (this=0x8bc90b8, thd=0x8b88cf0)
    at sp_head.cc:1039
#13 0x08304600 in sp_head::execute_function (this=0x8bc90b8, thd=0x8b88cf0, 

How to repeat:
Run into deadlock with doing:

create table `t1` (`a` int auto_increment primary key) ENGINE=innodb;
create table `t2` (`a` int auto_increment primary key, b int) ENGINE=innodb;
insert into t2 values (null,1);
insert into t2 values (null,2);
delimiter |;

create function sf() returns int deterministic 
begin 
  update t2 set b=2 where a=1; 
  update t2 set b=2 where a=2; 
return 1; 
end|

delimiter ;

connection one;
begin; 
  insert into t1 values (null);
  insert into t1 values (null);
  insert into t1 values (null);  
  update  t2 set b=1 where a=2;

connection two;
select sf();

connection one;
update t2 set b=1 where a=1 /* dl, this conn wins */;

Suggested fix:
Fix the assert.
[21 Mar 2007 14:17] Dmitry Lenev
Hi Andrei!

This bug is duplicate of bug #24989 "'Explicit or implicit commit' error/server crash with concurrent transactions"