getting lock wait timout when calling mysql proc from java -
i have below proc:
create procedure updatepath() begin declare cnt, n int; update foo set a.path=a.name a.parent_id null; select count(*) cnt foo path null; while cnt > 0 update foo a, foo b set a.path = concat(b.path, '/', a.name) b.path not null , a.parent_id = b.id; select row_count() cnt; end while; end; ;;
when call proc mysql workbench below:
call updatepath(); executes in few milliseconds. when run same code java program takes enormous amount of time , have kill java process. code calling proc below:
{ jdbctemplate.execute( new callablestatementcreator() { public callablestatement createcallablestatement(connection con) throws sqlexception { callablestatement cs = con.preparecall("{call updatepath()}"); return cs; } }, new callablestatementcallback() { public object doincallablestatement(callablestatement cs) throws sqlexception { cs.execute(); return null; } } ); }
above method running in separate transaction.when kill transaction after sometime,i see waiting lock. on doing show engine innodb status, below:
---transaction 4186138, active 532 sec fetching rows mysql tables in use 2, locked 2 37 lock struct(s), heap size 6544, 2437 row lock(s), undo log entries 307157 mysql thread id 14, os thread handle 0x2b38, query id 461758 localhost 127.0.0.1 root sending data update foo a, foo b set a.path = concat(b.path, '/', a.name) b.path not null , a.parent_id = b.id;
the problem seems "select row_count() cnt" statement after update in loop.this row_count responsible maintaining loop. in case while going in infinite loop update statement true after records updated. when run query on mysql work bench separately.i see 0 rows modified,6 rows found.while running proc workbench,row_count seems populated modified rows when ran java program ,it seems picking found rows. got running both work bench , java app modifying query in loop below:
update foo a, foo b set a.path = concat(b.path, '/', a.name) b.path not null , a.parent_id = b.id **and a.path null** ;
Comments
Post a Comment