Exercise 5
Exercise 5
Transactions
Isolation
Concurrency means trouble
Several processes
manipulating the
same data at the
same time can lead
to inconsistencies
Transactions
START TRANSACTION Isolated: Different
transactions may not
COMMIT/ROLLBACK interact with each
other.
Durable: Effects of a
Atomic: Either the transaction are not
whole transaction is lost in case of a
run, or nothing. system crash.
Consistent: Database
constraints are
preserved.
Serializability
If the outcome of a
number of
transactions is
equal to the
outcome of the
transactions
executed without
time overlap
To run transactions serially
…would solve the problem…
”Dirty
reads” – data modified by
another transaction, but not yet
committed
Isolation 1 – read committed
Asks for read lock,
but releases it
after reading
”Non-repeatable
reads” – the same
query can give
different results
Isolation 2 – repeatable read
If a query has a T1 T2
WHERE clause SELECT *
FROM users
spanning a range, a WHERE age
read lock is acquired BETWEEN 10
only for the result, not AND 30;
the entire range (no INSERT INTO
users VALUES
range lock) ( 3, 'Bob', 27 );
COMMIT;
SELECT *
The result can’t be FROM users
changed, but new WHERE age
data can be added – BETWEEN 10
AND 30;
so called ”Phantoms”
Isolation 3 - serializable
No other transactions are allowed to
interact with the data
All
locks collected are kept until after
COMMIT
None of this is of course true…
Optimistic
approach never blocks
concurrent transactions
Timestamp ordering
Read is only
Every transaction allowed if Tt>Tw,
is given a otherwise abort
timestamp Tt – Set Tr=Tt