Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use innodb row locks

2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report