Oracle 5.0 Reference Manual page 1292

Table of Contents

Advertisement

SELECT ... FROM ... LOCK IN SHARE MODE
the search encounters.
• For index records the search encounters,
sessions from doing
transaction isolation levels. Consistent reads will ignore any locks set on the records that exist in the
read view.
UPDATE ... WHERE ...
DELETE FROM ... WHERE ...
encounters.
sets an exclusive lock on the inserted row. This lock is an index-record lock, not a next-key
INSERT
lock (that is, there is no gap lock) and does not prevent other sessions from inserting into the gap
before the inserted row.
Prior to inserting the row, a type of gap lock called an insertion intention gap lock is set. This lock
signals the intent to insert in such a way that multiple transactions inserting into the same index gap
need not wait for each other if they are not inserting at the same position within the gap. Suppose
that there are index records with values of 4 and 7. Separate transactions that attempt to insert
values of 5 and 6 each lock the gap between 4 and 7 with insert intention locks prior to obtaining the
exclusive lock on the inserted row, but do not block each other because the rows are nonconflicting.
If a duplicate-key error occurs, a shared lock on the duplicate index record is set. This use of a
shared lock can result in deadlock should there be multiple sessions trying to insert the same row
if another session already has an exclusive lock. This can occur if another session deletes the row.
Suppose that an
InnoDB
CREATE TABLE t1 (i INT, PRIMARY KEY (i)) ENGINE = InnoDB;
Now suppose that three sessions perform the following operations in order:
Session 1:
START TRANSACTION;
INSERT INTO t1 VALUES(1);
Session 2:
START TRANSACTION;
INSERT INTO t1 VALUES(1);
Session 3:
START TRANSACTION;
INSERT INTO t1 VALUES(1);
Session 1:
ROLLBACK;
The first operation by session 1 acquires an exclusive lock for the row. The operations by sessions
2 and 3 both result in a duplicate-key error and they both request a shared lock for the row. When
session 1 rolls back, it releases its exclusive lock on the row and the queued shared lock requests
for sessions 2 and 3 are granted. At this point, sessions 2 and 3 deadlock: Neither can acquire an
exclusive lock for the row because of the shared lock held by the other.
A similar situation occurs if the table already contains a row with key value 1 and three sessions
perform the following operations in order:
Session 1:
START TRANSACTION;
The
Transaction Model and Locking
InnoDB
SELECT ... FROM ... FOR UPDATE
SELECT ... FROM ... LOCK IN SHARE MODE
sets an exclusive next-key lock on every record the search encounters.
sets an exclusive next-key lock on every record the search
table
has the following structure:
t1
1272
sets shared next-key locks on all index records
or from reading in certain
blocks other

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents