Concurrent execution refers to the simultaneous execution of more than one transaction. This is a common scenario in multi-user database environments where many users or applications might be accessing or modifying the database at the same time. Concurrent execution is crucial for achieving high throughput and efficient resource utilization. However, it introduces the potential for conflicts and data inconsistencies.
One transaction's updates could be overwritten by another.
Examples:
T1 | T2
----------|-----------
Read(A) |
A = A+50 |
| Read(A)
| A = A+100
Write(A) |
| Write(A)
Result: T1's updates are lost.
One transaction might read an inconsistent state of data that's being updated by another.
Examples:
T1 | T2
------------------|-----------
Read(A) |
A = A+50 |
Write(A) |
| Read(A)
| A = A+100
| Write(A)
Read(A)(rollbacks)|
| commit
Result: T2 has a "dirty" value, that was never committed in T1 and doesn't actually exist in the database.
when a single transaction reads the same row multiple times and observes different values each time. This occurs because another concurrent transaction has modified the row between the two reads.
Examples:
T1 | T2
----------|----------
Read(A) |
| Read(A)
| A = A+100
| Write(A)
Read(A) |
Result: Within the same transaction, T1 has read two different values for the same data item. This inconsistency is the unrepeatable read.
To manage concurrent execution and ensure the consistency and reliability of the database, DBMSs use concurrency control techniques. These typically include locking mechanisms, timestamps, optimistic concurrency control, and serializability checks.