Transaction Characteristics in SQL
Transaction Characteristics in SQL
• Each transaction, on its own, preserves database consistency i.e. serial execution of
transactions preserves database consistency. A (possibly concurrent) schedule is
serializable if it is equivalent to a serial schedule
Different forms of schedule equivalence give rise to the notions of conflict
serializability and view serializability
Conflict Serializability
Instructions li and lj of transactions Ti and Tj respectively, conflict if and only if there
exists some item Q accessed by both li and lj, and at least one of these instructions wrote Q.
• 1. li = read(Q), lj = read(Q). li and lj don’t conflict.
• 2. li = read(Q), lj = write(Q). They conflict.
• 3. li = write(Q), lj = read(Q). They conflict
• 4. li = write(Q), lj = write(Q). They conflict
View Serializability
• Let S and S´ be two schedules with the same set of transactions. S and S´ are view
equivalent if the following three conditions are met, where Q is a data item and Ti
is a transaction:
• 1. If Ti reads the initial value of Q in schedule S, then Ti must, in schedule S´, also
read the initial value of Q
• 2. If Ti executes read(Q) in schedule S, and that value was produced by transaction
Tj (if any), then transaction Ti must in schedule S´ also read the value of Q that
was produced by transaction Tj
• 3. The transaction (if any) that performs the final write(Q) operation in schedule S
(for any data item Q) must perform the final write(Q) operation in schedule S´
Testing for Serializability
• Consider some schedule of a set of transactions T1, T2, ..., Tn
• Precedence graph: a directed graph where the vertices are transaction names • We draw an arc from Ti to Tj
if the two transaction conflict, and Ti accessed the data item before Tj
• We may label the arc by the item that was accessed \• Example:
• Example Schedule and Precedence Graph
Lock Management
• The data items must be accessed in a mutually exclusive manner in order to ensure serializability i.e.,
a data item can be accessed by only one transaction at a time. This can be accomplished by allowing
the transaction to access a dataitem only if it is holding a lock o that data item.
• • A lock manager is a component of the DBMS that keeps track of the locks issued to the
transactions. It maintains a hash tables with the data object identifier as a key called Lock Table.
• • It also maintains a unique entry for each transaction in a transaction table (TT) and each entry
contains a pointer to a series of locks held by the transaction.
• A Lock Table Entry: While can either be a page or a record for an object contains the following
information:
• i) The number of transactions which holds a lock on the object currently which can be more than one
in shared mode.
• ii) The nature of the lock which can either be shared or exclusive and
• iii) A pointer to a queue holding lock requests
• Locking Modes
• i) Shared: A transaction T-I can read the dataitem P but
cannot write it, if it is holding a shared, mode lock. It is
denoted by S.
• ii) Exclusive: A transaction T-I can both read and write the
dataitem P if it is holding an exclusive-mode lock. It is
denoted by X.
Dealing with Deadlocks