The MySQL reference documentation provides these descriptions and examples of the gap lock [1].
A statement that locks a row by using a unique index to search for a unique row does not require a gap lock...For example, if an id column has a unique index, the next statement uses only index record lock for a row with a value of 100.
SELECT* FROM child WHERE id=100;
If an id is not indexed or a non-unique index is configured, the preceding gap is locked in this statement.
On the other hand, the Lock configured with various SQL statements in the InnoDB described below has these statements:
SELECT...FROM is a consistency read, reads a snapshot of the database, and does not set the lock unless the transaction isolation level is set to SERIALIZABLE.
The latter (no lock) and the former (index record lock or gap lock required) expressions seem to be inconsistent.I think I made a mistake, but I appreciate your guidance
mysql database
MySQL's default transaction level, REPEATABLE READ, is based on the following behavior:
In order to have this characteristic, especially in the update system, MySQL uses various locks provided by InnoDB for where clauses of update and delete.If anything, the table in which the transaction has been updated is locked until the transaction is finished to satisfy the nature of the update system of REPEATABLE READ.
So the next keylock or gaplock talk in the first half of the question is basically "If you want to issue a key scan to lock." For example, if the id is a primary key (that is, a type of unique index), the update below does not get a gap lock if the id=100 record exists.
UPDATE table_name SET name='new_name'WHERE id=100;
Now, the reason why SELECT statements are used as examples in these locks is that SELECT statements can get locks similar to the update system in the following cases:
SELECT...FROM...FOR UPDATE
syntax
SELECT...FROM...FOR UPDATE
is a read-locked version of SELECT...FROM...LOCK IN SHARE MODE
syntaxSELECT...FROM...
Syntax.
SELECT...FROM...LOCK IN SHARE MODE
is automatically convertedSELECT...FROM...FOR UPDATE
is a read-locked version of SELECT...FROM...LOCK IN SHARE MODE
syntaxSELECT...FROM...LOCK IN SHARE MODE
is automatically convertedTo sum up:
LOCK IN SHARE MODE
on their own, so scanning without locking is not performed
© 2024 OneMinuteCode. All rights reserved.