0% completed
Isolation ensures that the intermediate state of a transaction is invisible to other concurrent transactions. It prevents interference, ensuring that transactions execute as if they are happening sequentially, even in a multi-user environment.
Key Points:
Transactions work independently, unaffected by others happening at the same time.
A dirty read occurs when one transaction reads uncommitted changes made by another transaction, which may later be rolled back. This leads to potential inconsistencies.
Example:
Problem: Transaction B reads the uncommitted value of $400. Once Transaction A rolls back, the balance is restored to $500, but Transaction B has already processed the incorrect value, leading to dirty read inconsistency.
A dirty write happens when two concurrent transactions overwrite each other’s uncommitted changes, leading to data inconsistency.
Example:
Problem: Transaction B overwrites the changes made by Transaction A before Transaction A is committed. When Transaction A aborts, it leaves the database in an inconsistent state because Transaction B's update used uncommitted data.
A nonrepeatable read occurs when a transaction reads the same row multiple times and gets different values due to modifications by another transaction.
Example:
Problem Transaction A reads the same data twice (balance of Account A) but gets different values each time ($500 in T2 and $400 in T4). This inconsistency occurs because Transaction B committed its changes while Transaction A was still active, causing a non-repeatable read.
A phantom read happens when a transaction executes the same query multiple times and gets a different set of rows due to modifications by another transaction.
Example:
Problem: Transaction A reads the same query twice (number of rows in the table) but gets different results each time. In T2, it reads 1 row, but in T4, it reads 2 rows because Transaction B inserted a new row and committed its changes during Transaction A’s execution.
Isolation levels define the degree to which one transaction is isolated from other concurrent transactions. The higher the isolation level, the greater the guarantee of data consistency, but with a potential trade-off in performance.
The Lost Update Problem occurs when two or more transactions modify the same data concurrently, and the updates of one transaction are overwritten by another, leading to data loss.
X = 5
.X = 1
.X
by 1 and writes X = 6
.X
by 1 and writes X = 6
.X
should be 7, but because Transaction B overwrites the value updated by Transaction A, the final value is incorrectly recorded as 6.CAS (Compare-And-Swap) is an atomic operation used to address the Lost Update Problem by ensuring that updates are applied only if the original value matches the expected value.
X = 5
and intends to update it to X = 6
.X = 5
and intends to update it to X = 7
.X = 5
).X = 6
), so it retries with the updated value......
.....
.....