Answer the question
In order to leave comments, you need to log in
Lock wait timeout exceeded; try restarting transaction?
There is the following request, in which, I expected that one record would be selected, a lock would be taken, again for one record, set a flag - used and release the lock on this record, but judging by the error
'Lock wait timeout exceeded; try restarting transaction'
, the lock is taken over the entire table, and since I have 300 processes simultaneously trying to get a record from this table, this is very bad.
begin;
SELECT GetDistance('newhaven', area) as distance, id = (SELECT @proxy_id := id) from checkins
WHERE last_checkin > DATE_SUB(NOW(), INTERVAL 5 MINUTE)
AND active = 1
AND offline = 0
AND usage_flag = 0
ORDER BY distance ASC, RAND() limit 1 FOR UPDATE;
UPDATE checkins set usage_flag=1 where [email protected]_id;
commit;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question