Innodb locks and high concurrency

1 innodb lock

1.1 s lock, i.e. read lock, i.e. share lock

1.2 x locks, i.e. write locks, exclusive locks

1.3 The relationship between s lock and x lock

Multiple read locks can coexist, but read locks cannot coexist with write locks. Write locks and write locks cannot coexist.

1.4 Gap lock

It is to lock a piece of data, such as the row with id greater than 3 and less than 10, to prevent data with id=4 from being inserted.

2 innodb high concurrency

It is suitable for high concurrency with more reads and fewer writes, so in order to obtain high concurrency, read and write separation is necessary.

3 deadlock

Transaction A has 1 and needs 2, and transaction B has 2 and needs 1.

4 Three kinds of row locks of innodb

First, record lock

A lock on a single row.

Second, gap lock

Locks on gaps, excluding the row itself, resolve phantom reads.

Third, next lock

Including the gap and the line itself.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324762084&siteId=291194637