MySQL Forums
Forum List  »  InnoDB

Re: Transaction deadlock with many threads
Posted by: Rick James
Date: April 26, 2010 08:39PM

"select for update; update"
-->
"BEGIN; select for update; update; COMMIT;"

The uuid approach:
* Would need index on uuid
* Would require updating the uuid index
* Would still lock row(s)

Would it be even better to stuff random numbers in the table to start with (as opposed to when the update comes along)? This might be a way to grab the row:
BEGIN;
$id = SELECT id, ... FROM grabber_in
    WHERE status = 'FREE'
      AND rnd >= RAND()
    LIMIT 1 FOR UPDATE;
UPDATE grabber_in SET status = 'BUSY' WHERE id=$id;
COMMIT;

You might get away with a single statement, something like this:
UPDATE grabber_in SET
        status = 'BUSY',
        id = LAST_INSERT_ID(id)
    WHERE status = 'FREE'
      AND rnd >= RAND()
    LIMIT 1;
SELECT LAST_INSERT_ID();  -- session-specific, no need for LOCK or BEGIN
(Caveat: I am not sure of the details.)
http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_last-insert-id

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Transaction deadlock with many threads
1482
April 26, 2010 08:39PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.