Skip navigation links

MySQL Forums :: InnoDB :: Is this normal?


Advanced Search

Re: Is this normal?
Posted by: Heikki Tuuri ()
Date: January 12, 2005 05:36PM

Richard, Radu,

READ COMMITTED and REPEATABLE READ only affect plain SELECTs, not SELECT ... FOR UPDATE.

In the 4.1.8 execution:

"
1.mysql> select * from T where C = 42 for update;

2.mysql> select * from T where C = 42 for update;
-- The above select doesn't block now.

1.mysql> insert into T set C = 42;
-- The above insert blocks.

2.mysql> insert into T set C = 42;
ERROR 1213: Deadlock found when trying to get lock; Try restarting transaction
"

the explanation is that the X lock on the 'gap' set in SELECT ... FOR UPDATE is purely 'inhibitive'. It blocks inserts by other users to the gap. But it does not give the holder of the lock a permission to insert.

Why the inhibitiveness: if we have three index records:

aab <first gap> aba <second gap> acc

there are two gaps there. Suppose user 1 locks the first gap, and user 2 locks the second gap.

But if 'aba' is delete-marked, purge can remove it, and these two gaps merge. Then BOTH user 1 and user 2 have an exclusive lock on the same gap. This explains why a lock on gap does not give a user a permission to insert. There must not be locks by OTHER users on the gap, only then is the insert allowed.

Best regards,

Heikki
Oracle Corp./Innobase Oy
InnoDB - transactions, row level locking, and foreign keys for MySQL

InnoDB Hot Backup - a hot backup tool for InnoDB which also backs up MyISAM tables
http://www.innodb.com/order.php

Options: ReplyQuote


Subject Views Written By Posted
Is this normal? 2635 Björn Danielsson 01/06/2005 12:32PM
Re: Is this normal? 2058 Radu Chiriac 01/07/2005 03:30PM
Re: Is this normal? 1990 Radu Chiriac 01/07/2005 03:36PM
Re: Is this normal? 2102 Björn Danielsson 01/07/2005 10:55PM
Re: Is this normal? 1994 Heikki Tuuri 01/10/2005 05:08PM
Re: Is this normal? 2036 Björn Danielsson 01/11/2005 10:35AM
Re: Is this normal? 2092 Richard Cook 01/12/2005 09:56AM
Re: Is this normal? 2028 Radu Chiriac 01/12/2005 04:46PM
Re: Is this normal? 2047 Heikki Tuuri 01/12/2005 05:36PM


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.