Get the App
SLTechnology News&Howtos  ›  Database  › 

How to use innodb row locks

Shulou Source: shulou.com Published: 2022-05-31 13:58:29 10月29日 Update

This article focuses on "how to use innodb row locks". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use innodb line locks.

Three levels

Record lock locks a row of records

Gap lock locks records in a certain range

Next key lock is the superposition of the first two effects.

Experimental environment

Mysql > select @ @ tx_isolation

+-+

| | @ @ tx_isolation |

+-+

| | REPEATABLE-READ |

+-+

1 row in set (0.00 sec)

Mysql > select * from t

+-+

| | id |

+-+

| | 2 |

| | 8 |

| | 19 |

| | 22 |

+-+

Mysql > create index t_ind on t (id)

Query OK, 0 rows affected (8.52 sec)

Open two sessions at the same time and open things

Conversation one

Mysql > start transaction

Query OK, 0 rows affected (0.00 sec)

Mysql > delete from t where id=19

Query OK, 1 row affected (0.00 sec)

Conversation two

Mysql > start transaction

Query OK, 0 rows affected (0.00 sec)

Mysql > insert into t values (55)

Query OK, 1 row affected (0.00 sec)

Mysql > insert into t values (10)

^ C ^ C-- query aborted

ERROR 1317 (70100): Query execution was interrupted

Mysql >

Mysql > insert into t values (1)

Query OK, 1 row affected (0.00 sec)

Mysql > insert into t values (12)

^ C ^ C-- query aborted

ERROR 1317 (70100): Query execution was interrupted

Mysql >

Session 2 indicates that between 8-22 is locked and data cannot be inserted. This is gap lock.

Cancel gap lock

Modify the isolation level of things to READ COMMITTED

At this point, I believe you have a deeper understanding of "how to use innodb row locks". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Things content level learning practical deeper one line two between interest at the same time practical practical that is simple operation effect data method more friends. Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux MySQL Shulou Tech Info MariaDB vpn