Skip to main content
Jagdish Kumawat
Founder @ Dewiride
View all authors

How to Find What Is Holding a Metadata Lock in MySQL

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

An ALTER TABLE is stuck, and everything that arrives after it queues up behind it. The row-lock views are empty, because this is a different kind of lock: a metadata lock, which protects a table's structure. The holder is often something harmless looking, such as a transaction that ran one SELECT and never finished.

How to Use Savepoints in MySQL

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

ROLLBACK throws away a whole transaction. Sometimes you only want to undo the last part: try something, and if it doesn't work, carry on with what you've already done. A savepoint is a marker inside the transaction that lets you do just that.

How Gap Locks Block an INSERT in MySQL

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

An INSERT adds a brand-new row. So what could it possibly be waiting for? Under MySQL's default isolation level, it can be waiting for a gap: the space between rows, locked by a transaction that asked about a row that isn't there. Here's a gap lock, the insert it blocks, and how READ COMMITTED removes it.