Conflict in DBMS

The conflict in dbms happens when concurrent transactions try to access or modify the same data at the same time. It leads to inconsistencies or incorrect outcomes. Such conflicts generally occur in dbms when multiple transactions are executed concurrently. 

Types of Conflicts

Various kinds of conflicts may occur in a DBMS, some of them are listed below

  1. Read-Write Conflict: This occurs when one transaction (T1) READ a data item while another transaction (T2) is trying to WRITE to the same data item simultaneously. If the READ operation is completed before the WRITE operation, then the transaction (T1) will obtain an incorrect or outdated value.

  2. Write-Write Conflict: This situation happens when multiple transactions (i.e. T1, T2) attempt to write on the same data simultaneously. The problem is, that if one transaction changes then it may be overwritten by other transaction.

  3. Lost Update Problem: This is an instance of a write-write conflict. The case when one transaction overwrites but another transaction changes without considering the first one, resulting in data loss.

  4. Dirty Read: This occurs when one transaction reads a data item that has been modified by another transaction but not yet committed. If the first transaction reads data before the second transaction is rolled back, the data read by the first transaction becomes invalid.

Conditions for Conflicts in DBMS

Read and Write operations are considered the conflict operations in DBMS if they hold the following conditions.

  • Both the operations (Read and Write) are on the same data.
  • Both the operations belong to the different transactions.
  • At least one of the two operations is a write operation.

Two operations (Read and Write) are considered as Non-Conflict Operations if they hold the following conditions.

  • Both the operations are on different data item
  • Both operations belong to different transactions

Note: Both READ operation of the same or different data is also a non-conflict pair

Let’s consider T1 and T2 are the two transactions. Data is named as “A” and “B”, on which READ or WRITE operations are performed.  let explain it for same and different data

Note: READ (A) for T1 and READ (A) for T2 is called a pair. Pair can be conflict or non-conflict.

Conflict – For Same Data (“A”)

Before proceeding with conflict for the same data, look at the descriptive diagram

Conflict pairs in DBMS

As in the above diagram, there is only one non-conflict pair when both transactions operate on the same data. The  non-conflict pair is given below 

  • READ (A) for T1 and READ (A) for T2

Similarly, the following are the three conflict pairs when both transactions operate on the same data.

  • READ (A) for T1 and WRITE (A) for T2
  • WRITE (A) for T1 and READ (A) for T2
  • WRITE (A) for T1 and WRITE (A) for T2

Conflict – For Different Data (“A” and “B”)

 Following are the four non-conflict pairs when both transactions operate on the same data.

  • READ (A) for T1 and READ (B) for T2
  • READ (A) for T1 and WRITE (B) for T2
  • WRITE (A) for T1 and READ (B) for T2
  • WRITE (A) for T1 and WRITE (B) for T2

The descriptive diagram for conflict in different data is given below

Non-conflict pairs in DBMS

As in the above diagram, there is no conflict pair when both transactions operate on different data.

Swapping of Non-Conflict Pairs

You must remember, only the Non-conflict pairs are swappable. There is no possibility to swap the conflict pairs. Sometimes, a given schedule is parallel, and we try to make it serial by swapping non-conflict pairs. If a given schedule becomes serial, then this schedule is known as a conflict serializable schedule; otherwise, it will not be a conflict serializable schedule.

there are two basic steps to for swaping of non conflict pairs in dbms

  • Step 01: Find the Adjacent Non-conflict pairs.
  • Step 02: Swap the non-conflict pairs. Just swap the position of non-conflict pairs in the same transaction; don’t swap the operation of that transaction.

Example 01: Non-Conflict Pair Swapping

Let’s explain with an example. Consider the following schedule

Step 01:  First, find the “adjacent Non-conflict pair” from the given schedule. If it exists, then swap it as given below in the diagram

Step 02: Repeat step 1 until no adjacent non-conflict pair exists.

As we can see, the given schedule “A” (which was not serial ) is converted into the serial schedule. so it is a serial schedule.  After swapping, if the given schedule (Say “A”) becomes serial and equal to some other schedule(Say “B”), then both schedules  (“A” and “B”) will conflict with equivalent schedules.

Example 02 – No Swapping in Non-Conflict Pair

In the following example, there is no adjacent non-conflict pair, so the following schedule cannot be converted into serial, so the following schedule is not serial.