Tagged articles
13 articles
Page 1 of 1
Sanyou's Java Diary
Sanyou's Java Diary
Aug 25, 2025 · Databases

Understanding MySQL Next-Key Locks: Preventing Phantom Reads and Deadlocks

This article explains MySQL InnoDB's Next-Key Lock mechanism, how it combines row and gap locks to prevent phantom reads under the REPEATABLE READ isolation level, illustrates lock ranges with examples, discusses when it degrades to row or gap locks, and highlights its advantages and potential deadlock risks.

InnoDBNext-key Lockdeadlock
0 likes · 8 min read
Understanding MySQL Next-Key Locks: Preventing Phantom Reads and Deadlocks
New Oriental Technology
New Oriental Technology
Jun 13, 2024 · Databases

Understanding InnoDB Row-Level Locks and Locking Rules in MySQL

This article explains the types of InnoDB row‑level locks—record lock, gap lock, and next‑key lock—describes how MySQL determines lock ranges based on indexing, outlines the two fundamental locking principles with associated optimizations, and provides concrete examples for primary‑key and ordinary indexes.

Gap LockInnoDBNext-key Lock
0 likes · 11 min read
Understanding InnoDB Row-Level Locks and Locking Rules in MySQL
ITPUB
ITPUB
Jul 28, 2023 · Databases

Master InnoDB Row Locking: Rules, Examples, and How Locks Are Applied

This article explains InnoDB's three row‑lock types, when MySQL statements acquire implicit or explicit locks, and walks through concrete examples for unique and non‑unique index queries, showing how Next‑key, Record and Gap locks are determined.

Database ConcurrencyInnoDBNext-key Lock
0 likes · 10 min read
Master InnoDB Row Locking: Rules, Examples, and How Locks Are Applied
政采云技术
政采云技术
Feb 23, 2023 · Databases

Understanding Next-Key Lock Deadlocks in MySQL: Analysis and Solutions

This article examines how common business operations using SELECT ... FOR UPDATE and INSERT can cause MySQL Next‑Key lock deadlocks, explains the underlying gap‑lock and row‑lock mechanisms, demonstrates practical experiments, and proposes strategies such as postponing locks or using primary‑key updates to avoid such deadlocks.

Next-key LockSQLdatabase
0 likes · 14 min read
Understanding Next-Key Lock Deadlocks in MySQL: Analysis and Solutions
政采云技术
政采云技术
Feb 21, 2023 · Databases

Understanding Next-Key Lock Deadlocks in MySQL and How to Avoid Them

This article examines how common business operations using SELECT ... FOR UPDATE and INSERT can cause Next‑Key lock deadlocks in MySQL under repeatable‑read isolation, demonstrates the locking behavior with practical SQL examples, and proposes strategies such as post‑locking and primary‑key updates to prevent such deadlocks.

Isolation LevelNext-key LockSQL
0 likes · 14 min read
Understanding Next-Key Lock Deadlocks in MySQL and How to Avoid Them
ITPUB
ITPUB
Feb 8, 2023 · Databases

Why Does One MySQL UPDATE Block While Another Doesn’t? A Deep Dive into Row‑Level Locks

This article explains why an UPDATE on a MySQL row that changes a regular column proceeds without blocking, while an UPDATE that modifies the primary‑key value gets blocked, by analyzing the locks set by preceding transactions, the B+‑tree index structure, and the delete‑plus‑insert rewrite performed by InnoDB.

B+TreeGap LockNext-key Lock
0 likes · 9 min read
Why Does One MySQL UPDATE Block While Another Doesn’t? A Deep Dive into Row‑Level Locks
政采云技术
政采云技术
Jul 28, 2022 · Databases

Analyzing and Resolving MySQL Next‑Key Lock Deadlocks: A Practical Case Study

This article walks through a real MySQL deadlock scenario, explaining the four necessary deadlock conditions, illustrating how Next‑Key locks on non‑unique indexes cause gap locks, and presenting step‑by‑step analysis, experimental verification, and practical recommendations to avoid such deadlocks in production systems.

Next-key LockSQLdatabase
0 likes · 15 min read
Analyzing and Resolving MySQL Next‑Key Lock Deadlocks: A Practical Case Study
Selected Java Interview Questions
Selected Java Interview Questions
Sep 27, 2020 · Databases

Understanding How MySQL InnoDB Solves Phantom Reads

This article explains the four transaction isolation levels, defines phantom reads, and details how MySQL's InnoDB engine uses MVCC snapshot reads and next‑key locking (including the next‑key principle and lock composition) to prevent phantom reads under the REPEATABLE READ isolation level.

InnoDBIsolation LevelMVCC
0 likes · 2 min read
Understanding How MySQL InnoDB Solves Phantom Reads
Programmer DD
Programmer DD
Sep 21, 2020 · Databases

How MySQL Prevents Phantom Reads: MVCC and Next‑Key Locks Explained

This article explains why phantom reads occur under MySQL's REPEATABLE READ isolation, how InnoDB uses MVCC for snapshot reads and next‑key locks for current reads, and demonstrates the mechanisms with code examples and version‑tracking diagrams.

Isolation LevelMVCCNext-key Lock
0 likes · 7 min read
How MySQL Prevents Phantom Reads: MVCC and Next‑Key Locks Explained
dbaplus Community
dbaplus Community
Mar 17, 2019 · Databases

Understanding InnoDB Locks: From Record Locks to Deadlocks

This article explains MySQL InnoDB’s transaction locking mechanisms—including shared, exclusive, intention, gap, and next‑key locks—covers lock compatibility, demonstrates lock behavior with practical examples, explores phantom reads, lost updates, optimistic vs. pessimistic locking, and analyzes common deadlock scenarios.

Gap LockInnoDBLocks
0 likes · 28 min read
Understanding InnoDB Locks: From Record Locks to Deadlocks
ITPUB
ITPUB
Oct 17, 2016 · Databases

Why Some MySQL Inserts Are Blocked: Decoding Next‑Key Lock Ranges

This article examines MySQL InnoDB's next‑key lock behavior by creating a test table, running concurrent transactions, and analyzing how the lock range is determined across primary and secondary index columns, revealing why certain insert statements are blocked while others succeed.

Gap LockInnoDBNext-key Lock
0 likes · 9 min read
Why Some MySQL Inserts Are Blocked: Decoding Next‑Key Lock Ranges