MySQL Forums :: InnoDB :: Is this normal?

Advanced Search

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

Richard, Radu,


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,

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

Options: ReplyQuote

Subject Views Written By Posted
Is this normal? 3401 Björn Danielsson 01/06/2005 12:32PM
Re: Is this normal? 2521 Radu Chiriac 01/07/2005 03:30PM
Re: Is this normal? 2381 Radu Chiriac 01/07/2005 03:36PM
Re: Is this normal? 2679 Björn Danielsson 01/07/2005 10:55PM
Re: Is this normal? 2480 Heikki Tuuri 01/10/2005 05:08PM
Re: Is this normal? 2460 Björn Danielsson 01/11/2005 10:35AM
Re: Is this normal? 2649 Richard Cook 01/12/2005 09:56AM
Re: Is this normal? 2509 Radu Chiriac 01/12/2005 04:46PM
Re: Is this normal? 2510 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.