Transaction Isolation

COMP9315 21T1 ♢ Transaction Isolation ♢ [0/11]
❖ Transaction Isolation

Simplest form of isolation: serial execution   (T1 ; T2 ; T3 ; ...)

Problem: serial execution yields poor throughput.

Concurrency control schemes (CCSs) aim for "safe" concurrency

Abstract view of DBMS concurrency mechanisms:

[Diagram:Pics/txproc/txproc1.png]

COMP9315 21T1 ♢ Transaction Isolation ♢ [1/11]
❖ Serializability

Consider two schedules S1 and S2 produced by

S1 and S2 are equivalent if StateAfter(S1)  =  StateAfter(S2)
S is a serializable schedule (for a set of concurrent tx's T1 ..Tn) if Under these circumstances, consistency is guaranteed
(assuming no aborted transactions and no system failures)
COMP9315 21T1 ♢ Transaction Isolation ♢ [2/11]
❖ Serializability (cont)

Two formulations of serializability:

View serializability is strictly weaker than conflict serializability.
COMP9315 21T1 ♢ Transaction Isolation ♢ [3/11]
❖ Checking Serializability

Conflict serializablility checking:

make a graph with just nodes, one for each Ti
for each pair of operations across transactions {
    if (Ti and Tj have conflicting ops on variable X) {
        put a directed edge between Ti and Tj
            where the direction goes from
            first tx to access X to second tx to access X
        if this new edge forms a cycle in the graph
            return "Not conflict serializable"
    }
}
return "Conflict serializable"

COMP9315 21T1 ♢ Transaction Isolation ♢ [4/11]
❖ Checking Serializability (cont)

View serializability checking:

// TC,i denotes transaction i in concurrent schedule
for each serial schedule S {
    // TS,i denotes transaction i in serial schedule
    for each shared variable X {
        if TC,i reads same version of X as TS,i
            (either initial value or value written by Tj)
            continue
        else
            give up on this serial schedule
        if TC,i and TS,i write the final version of X
            continue
        else
            give up on this serial schedule
     }
     return "View serializable"
}
return "Not view serializable"

COMP9315 21T1 ♢ Transaction Isolation ♢ [5/11]
❖ Transaction Isolation Levels

SQL programmers' concurrency control mechanism ...

set transaction
    read only  -- so weaker isolation may be ok
    read write -- suggests stronger isolation needed
isolation level
    -- weakest isolation, maximum concurrency
    read uncommitted
    read committed
    repeatable read
    serializable
    -- strongest isolation, minimum concurrency

Applies to current tx only; affects how scheduler treats this tx.

COMP9315 21T1 ♢ Transaction Isolation ♢ [6/11]
❖ Transaction Isolation Levels (cont)

Implication of transaction isolation levels:

Isolation
Level
Dirty
Read
Nonrepeatable
Read
Phantom
Read
Read
Uncommitted
Possible Possible Possible
Read
Committed
Not Possible Possible Possible
Repeatable
Read
Not Possible Not Possible Possible
Serializable Not Possible Not Possible Not Possible
COMP9315 21T1 ♢ Transaction Isolation ♢ [7/11]
❖ Transaction Isolation Levels (cont)

For transaction isolation, PostgreSQL


Note: cannot implement read uncommitted because of MVCC


For more details, see PostgreSQL Documentation section 13.2

COMP9315 21T1 ♢ Transaction Isolation ♢ [8/11]
❖ Transaction Isolation Levels (cont)

A PostgreSQL tx consists of a sequence of SQL statements:

BEGIN S1; S2; ... Sn; COMMIT;

Isolation levels affect view of DB provided to each Si:

Transactions fail if the system detects violation of isolation level.
COMP9315 21T1 ♢ Transaction Isolation ♢ [9/11]
❖ Transaction Isolation Levels (cont)

Example of repeatable read vs serializable

COMP9315 21T1 ♢ Transaction Isolation ♢ [10/11]
❖ Concurrency Control

Isolation requires some method to control concurrency

Possible approaches to implementing concurrency control:

COMP9315 21T1 ♢ Transaction Isolation ♢ [11/11]


Produced: 14 Apr 2021