Language OfDbaba
Language OfDbaba
Language OfDbaba
Example:
A has an account with an amount of #150. B has an account with an amount of #50. A is transferring
amount #100 to B’s account.
Atomicity: Operations required for transfer are: Deduct amount #100 from A’s account. Add amount
#100 to B’s account. All operations should be done. If system fails to add amount in B’s account after
deducting from A’s account, revert the operation on A’s account.
Consistency: The sum amount in A’s account and B’s account should be same before and after the
transaction completes. In the example the sum of both account before and after transaction is #200, which
preserves the consistency.
Isolation: If there is any other transaction (let between A and C) is going on, it should not affect the
transaction between A and B i.e., both the transactions should be isolated.
Durability: It may happen system gets crashed after the completion of all operations then, after restarting
it should preserve all the changes. The amount in A’s and B’s account should be same before and after
the system restart.
The answer is a set of rows, each of which is a pair 〈 sname, age 〉. If two or more sailors have the same
name and age, the answer still contains just one pair with that name and age.
The answer to this query with and without the keyword DISTINCT on instance S3 of Sailors is shown in
Figures 1 and 2. The only difference is that the tuple for Horatio appears twice if DISTINCT is omitted;
this is because there are two sailors called Horatio and age 35.
Figure1: Query with DISTINCT keyword Figure 2: Query without DISTINCT keyword
SELECT *
FROM Sailors;
This query will retrieve all the column in the Sailors table.
Find the age of the youngest sailor who is eligible to vote (i.e., is at least 18 years old) for each rating level
with at least two such sailors.
SELECT S.rating, MIN (S.age) AS minage
FROM Sailors S
WHERE S.age >= 18
CONCURRENT EXECUTIONS
Concurrency in Database Management Systems (DBMS) is a critical concept that enables multiple
transactions to be executed simultaneously without compromising data integrity and consistency. This
capability is essential in environments where numerous users or applications need to access and modify the
database concurrently. Multiple transactions are allowed to run concurrently in the system.
Advantages are:
1) Increased processor and disk utilization, leading to better transaction throughput e.g. one transaction can
be using the CPU while another is reading from or writing to the disk.
2) Reduced average response time for transactions: short transactions need not wait behind long ones.
Concurrency control schemes – mechanisms to achieve isolation
Concurrency control schemes is, to control the interaction among the concurrent transactions in order to
prevent them from destroying the consistency of the database.
Concurrency control is vital for several reasons:
1) Database Consistency: It ensures that the database remains consistent even when multiple
transactions are executed simultaneously. Without proper control, conflicting updates could lead
to an inconsistent state.
2) Avoiding Conflicts: Concurrency control prevents lost updates, where one transaction's changes
may overwrite another's without proper coordination. This is crucial in scenarios like banking,
where simultaneous withdrawals could lead to incorrect balances.
3) Dirty Reads Prevention: It stops transactions from reading uncommitted changes made by
others, which can lead to inaccurate data being processed.
4) System Efficiency: By managing concurrent access, DBMS can enhance throughput and
optimize resource utilization, allowing for faster transaction processing.
Common Problems in Concurrency
While concurrency improves performance, it also introduces several challenges:
1) Lost Updates: Occurs when two transactions read the same data and one updates it,
potentially overwriting the other’s changes.
2) Dirty Reads: Happens when a transaction reads data modified by another transaction that has
not yet committed, leading to potential inaccuracies.
3) Phantom Reads: Arises when a transaction retrieves a set of records and another transaction
modifies the dataset before the first transaction completes, resulting in different results upon
re-querying.
Concurrency Control Techniques
To address these challenges, various concurrency control techniques are employed:
1) Two-Phase Locking (2PL): This protocol divides transactions into two phases—growing (where
locks are acquired) and shrinking (where locks are released). It ensures serializability but can lead
to deadlocks if not managed properly.
2) Timestamp Ordering Protocol: Transactions are ordered based on their timestamps. Older
transactions have higher priority, which helps maintain consistency by ensuring that operations
occur in a predetermined order.
3) Multi-Version Concurrency Control (MVCC): This technique allows multiple versions of a
data item to exist simultaneously. It enables readers to access a snapshot of the database while
writers make changes, thus reducing conflicts between read and write operations.
4) Validation Concurrency Control: This method checks whether a transaction can be committed
only at the end of its execution based on the state of the database at that time, ensuring that no
conflicting operations have occurred during its execution
Schedule
Schedule is process of grouping transactions into one and executing them in a predefined order. It is a
sequence of execution of operation from various transactions. Schedule is required in database because
when multiple transactions execute in parallel, they may affect the result of each other. So, to resolve this
the order of the transactions are changed by creating a schedule.
Types of Schedules:
Serial Schedule: A schedule in which the transactions are defined to execute one after another is called
serial schedule.
Non- Serial Schedule: A schedule in which the transactions are defined to execute in any order is called
non-serial schedule.
Recoverable and Non-Recoverable Schedule
Schedules in which transactions commit only after all transactions whose changes they commit are called
recoverable schedule.
If some transaction Tj is reading value updated or written by some other transaction T i then, the commit
of Tj must occur after the commit of Ti.
Schedule S1 Schedule S2
T1 T2 T1 T2
R(X)
R(X)
X=X+10
X=X+10
W(X)
W(X)
COMMIT
R(X) R(X)
Rollback X=X-5 X=X-5
COMMIT W(X) W(X)
COMMIT COMMIT