Overview of Serializablity in Data Base
Overview of Serializablity in Data Base
Key Concepts
Types of Serializability
Achieving Serializability
1. Lock-based Protocols:
o Two-Phase Locking (2PL): A transaction must acquire all the locks it needs
before releasing any lock. 2PL ensures conflict serializability by preventing
transactions from interfering with each other.
o Strict Two-Phase Locking (Strict 2PL): A stricter version of 2PL where a
transaction holds all locks until it commits or aborts, ensuring serializability.
2. Timestamp Ordering:
o Each transaction is given a unique timestamp. The DBMS ensures that
transactions with earlier timestamps are prioritized when reading or writing data
items. This prevents conflicts that could lead to non-serializability.
3. Serializable Schedules:
o The DBMS may analyze schedules to ensure they are serializable. If a schedule is
found to be non-serializable, the system may abort or delay some transactions to
resolve the conflicts.
4. Optimistic Concurrency Control:
o This method allows transactions to execute without locks and checks for conflicts
only during the commit phase. If conflicts are detected, the transaction is rolled
back. This can lead to serializable results if conflicts are rare.
1. Lost Update: When two transactions read the same data and then write changes to it, one
update might be lost, as only the last write is reflected in the database.
2. Temporary Inconsistency (or Dirty Read): A transaction reads a data item that has
been written by another transaction but not yet committed. If the second transaction is
rolled back, the first transaction may have read inconsistent data.
3. Uncommitted Data: If a transaction reads data that has been written by another
transaction but that transaction later fails, the first transaction will have read uncommitted
data, leading to potential inconsistencies.
1. T1: Read(X)
2. T2: Read(X)
3. T1: Write(X)
4. T2: Write(X)
In this schedule, T1 and T2 conflict when they both try to access X. However, this schedule can
be rearranged into a serial schedule, for example:
Conclusion
Serializability is a crucial property in database systems to maintain consistency and ensure the
correctness of concurrent transactions. By enforcing serializability, databases can ensure that
multiple transactions, even when executed in parallel, will result in a valid final state, equivalent
to some serial execution of the transactions. Various concurrency control techniques, such as
locking and timestamp ordering, help achieve this goal, protecting against anomalies like lost
updates, dirty reads, and temporary inconsistencies.
Serializability in DBMS
Last Updated : 06 Oct, 2023
Transaction-1 Transaction-2
R(a)
W(a)
R(b)
W(b)
R(b)
R(a)
W(b)
W(a)
We can observe that Transaction-2 begins its execution before
Transaction-1 is finished, and they are both working on the same
data, i.e., "a" and "b", interchangeably. Where "R"-Read, "W"-Write
Serializability testing
We can utilize the Serialization Graph or Precedence Graph to
examine a schedule's serializability. A schedule's full transactions
are organized into a Directed Graph, what a serialization graph is.
Precedence
Graph
It can be described as a Graph G(V, E) with vertices V = "V1, V2,
V3,..., Vn" and directed edges E = "E1, E2, E3,..., En". One of the two
operations—READ or WRITE—performed by a certain transaction is
contained in the collection of edges. Where Ti -> Tj, means
Transaction-Ti is either performing read or write before the
transaction-Tj.
Types of Serializability
There are two ways to check whether any non-serial schedule is
serializable.
Types of Serializability - Conflict & View
1. Conflict serializability
Conflict serializability refers to a subset of serializability that focuses
on maintaining the consistency of a database while ensuring that
identical data items are executed in an order. In a DBMS each
transaction has a value and all the transactions, in the database rely
on this uniqueness. This uniqueness ensures that no two operations
with the conflict value can occur simultaneously.
For example lets consider an order table and a customer table as
two instances. Each order is associated with one customer even
though a single client may place orders. However there are
restrictions for achieving conflict serializability in the database. Here
are a few of them.
1. Different transactions should be used for the two procedures.
2. The identical data item should be present in both transactions.
3. Between the two operations, there should be at least one write
operation.
Example
Three transactions—t1, t2, and t3—are active on a schedule "S" at
once. Let's create a graph of precedence.
Transaction - 1
(t1) Transaction - 2 (t2) Transaction - 3 (t3)
R(a)
R(b)
R(b)
W(b)
W(a)
W(a)
R(a)
W(a)
R(a)
W(a)
R(a)
W(a)
R(b)
W(b)
R(b)
W(b)
R(a)
W(a)
R(b)
W(b)
Transaction-1 (t1) Transaction-2 (t2)
R(a)
W(a)
R(b)
W(b)