Search code examples
mysqlmongodbpostgresqlrdbmsdatabase

can locks prevent unrepeatable reads?


I have a particular question in my mind for some moment, let's say I have a schedule like this:

S2(A), R2(A), U2(A), X1(A), W1(A), Commit1(A), U1(A), S2(A), R2(A), U2(A)

  • S is share lock, X is exclusive lock, U is unlock either share lock or exclusive lock.

Even if I have shared lock and exclusive lock here, I still get different value of A in transaction 2, which happens at the very beginning and ending - since transaction 1 changes value of A in the middle.

In this case, does that mean locks cannot prevent unrepeatable reads at all?


Solution

  • Slocks locks the value of A and wont allow you to set an Xlock so you cant write the new value of A unless you reamove the Slock is removed.

    and Xlocks won't allow both reading and writing the value of A unless its removed.