node.js - Lock wait timeout exceeded in MySQL amazon rds -
i have 1 store procedure, doing saving operation in 1 table. in store procedure, inserting multiple records in table.
here table structure
table : invitemst ~~~~~~~~~~~~~~~~~ name datatype description -------- ------------ ---------------------- inviteid int primarykey (auto incr) date date userid int (forignkey) emailid varchar(50) guid varchar(36) store procedure : usp_invitemst ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ create procedure `usp_invitemst`( in n_userid int, in emaillist mediumtext ) begin declare d_date datetime default now(); if length(emaillist) > 0 set @sqlquery = ""; set npos = instr(emaillist, ","); while (npos <> 0) set c_emailid = trim(substring(emaillist, 1,npos - 1)); if c_emailid <> "" set c_guid = ""; //here checking if user exists same emailid in same date or note. select guid c_guid invitemst userid = n_userid , date = date(d_date) , guid not null , emailid = c_emailid order date desc limit 0, 1; set c_guid = coalescec_guid ,""); if (c_guid = "") set c_guid = uuid(); //here preparing statement/query insert set @sqlquery = concat(@sqlquery, if(length(@sqlquery) > 0,",",""), "(", n_userid, ", '", d_date, "','", c_emailid, "', c_guid, "') "); end if; end if; set emaillist = substring(emaillist, npos +1, length(emaillist)); set npos = instr(emaillist, ","); end while; if (length(@sqlquery) > 0) //finally here inserting in table set @sqlquery = concat("insert invitemst ( userid, date, emailid, guid ) values ", @sqlquery); prepare stmt @sqlquery; execute stmt; set @sqlquery = ""; end if; end if; end
i calling store procedure :
call usp_invitemst( 1, 'a@a.com,b@b.com,c@c.co.in,g@yahoo.com' );
it working perfect, in may cases, time (in live project) thoring error 'lock wait timeout exceeded'. 'innodb_lock_wait_timeout' set 100.
if there better way this. or how can insert multipul records in single request.
i using node.js , using transaction right now.
Comments
Post a Comment