Neidi
Neidi

Reputation: 116

Does a lock FOR UPDATE allows simple SELECT statements by another connection in MySQL

I read that SELECT ... FOR UPDATE inside a transaction disallows other transactions from SELECTing the affected records.

So far so good, but what is with SELECT statements from other connections that are not inside a transaction. Can these statements read my affected records?

I read something that all MySQL statements are transactions implicitly. That would mean, that a normal SELECT that is not wrapped inside START TRANSACTION ... COMMIT cannot read my affected records. However, I don't found much on this topic. So my Question is if this is correct?

Upvotes: 0

Views: 235

Answers (1)

danblack
danblack

Reputation: 14761

Statements outside your transaction won't read your modified data. The exclusive lock prevents it as does an isolation level of not read-uncommmitted. A transaction started before yours may quite legitimately read the old value.

Yes normal SELECT statements without a START TRANSACTION / BEGIN are implicitly their own transaction. As such a SELECT .. FOR UPDATE as a single statement is rather pointless.

Upvotes: 1

Related Questions