2

I've been given this schedule:

enter image description here

And I'm asked why Postrgre doesn't make T1 wait before executing the update. I thought that sice both are serializable, T1 shouldn't do anything until T2 has commited since both are accessing the samne data. But apparently this isn't the case.

Can someone explain?

Thank you!

1 Answer 1

3

There is a difference between “serializable” and “serialized”. The latter is what you expect, and the former means that there is a serial execution order of the same transactions that produces the same result. Or, in the words of the SQL standard (ISO/IEC 9075-2:2003, chapter 4.35.4):

The execution of concurrent SQL-transactions at transaction isolation level SERIALIZABLE is guaranteed to be serializable. A serializable execution is defined to be an execution of the operations of concurrently executing SQL-transactions that produces the same effect as some serial execution of those same SQL-transactions. A serial execution is one in which each SQL-transaction executes to completion before the next SQL-transaction begins.

Now the equivalent serial execution of your example would be first T2, then T1. So they are serializable. Be happy – you get better performance than you would with an actual serial execution.

In other words, T2 processes as if T1 had never started. Transaction isolation levels are about isolating (protecting) one database session from the effects of others, which is what you see here. It does not matter that T1 actually started before T2 – they have no bi-directional dependencies. All that matters is that the end result cannot have an anomaly, an effect that could not happen during some serial execution.

2
  • 1
    Thank you for your answer! So from what I understand from it is that for a schedule to be serializable, it must have an equivalent serialized schedule. But I don't know how to connect that with my question. As you said, the equivalent serialized schedule would be T2; T1 so the update order from T1 has to wait. But according to the problem statement it doesn't have to. Why the update from T1 does not have to wait?
    – matsrom
    Commented Dec 1, 2021 at 21:43
  • All clear now. Thank you!
    – matsrom
    Commented Dec 5, 2021 at 2:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.