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

Row Lock of mysql innodb (5)-- next-Key Lock

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The gap lock next-key is locked for records where the range condition does not exist to avoid unrepeatable reading and phantom reading. If it is the isolation level of read committed, this problem does not exist.

So: in our development, if we use the isolation level of repeatable read, we should minimize updates to a certain range of records, otherwise it will seriously affect concurrent insertion.

Special case: applying for a lock of a record that does not exist through equal conditions will also use the next-key lock and affect the insertion of the record.

Root@sakila 10:46:49 > show variables like'% tx_isolation%'

+-+ +

| | Variable_name | Value |

+-+ +

| | tx_isolation | REPEATABLE-READ |

+-+ +

1 row in set (0.00 sec)

Session 1:

Root@sakila 10:49:04 > select * from tab_no_index where id=111 for update

Empty set (0.00 sec)

Session 2: because the first session lock record does not exist, the next-key is locked. There is no scope, which is equal to all, so the new record cannot be inserted.

Root@sakila 10:47:43 > insert into tab_no_index values (200Japanese 200')

ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

Root@sakila 10:49:17 > rollback

Query OK, 0 rows affected (0.01 sec)

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