First, there are three locking contexts:
- Database Level Lock
- Table level lock
- Row level lock
Then you have four lock modes:
IX and IS locks are intent locks. These locks are held before acquiring other types of locks. Lock X is a lock (write), and lock S is a general (read) lock.
(IX, IS, X X) . , X . , SQLlite. S , X . Writes S S X , . .
MySQL . MyISAM X S () . X S X- . X , S-. , LOW_PRIORITY_UPDATES, , - .
MySQL X , "FLUSH TABLES WITH READ LOCK".
InnoDB , . InnoDB . InnoDB , "gap", REPEATABLE-READ. , , UPDATE, . , InnoDB S SELECT. , .
X . :
>connection 1
start transaction;
update T set c = c + 1 order by id asc;
>connection 2
start transaction;
update T set c = c - 1 order by id desc;
. , , , . . InnoDB , . MyISAM , , .
, , X ( , ). , , , X. X. , . , , X. , DELETE UPDATE, , .
UPDATE X, UPDATE X , .