Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Advanced Database Concepts Transaction Management and Concurrency Control.

Similar presentations


Presentation on theme: "1 Advanced Database Concepts Transaction Management and Concurrency Control."— Presentation transcript:

1 1 Advanced Database Concepts Transaction Management and Concurrency Control

2 2 What is a Transaction? A logical unit of work that must be either entirely completed or aborted Successful transaction changes the database from one consistent state to another One in which all data integrity constraints are satisfied Most real-world database transactions are formed by two or more database requests The equivalent of a single SQL statement in an application program or transaction

3 3 The Relational Schema for the Ch09_SaleCo Database

4 4 Evaluating Transaction Results Improper or incomplete transactions can have a devastating effect on database integrity Some DBMSs provide means by which user can define enforceable constraints based on business rules Other integrity rules are enforced automatically by the DBMS when table structures are properly defined, thereby letting the DBMS validate some transactions

5 5 Transaction Properties (ACID) Atomicity Requires that all operations (SQL requests) of a transaction be completed Consistency Ensures that the concurrent execution of several transactions yields consistent results Isolation Data used during execution of a transaction cannot be used by second transaction until first one is completed Durability Indicates permanence of database’s consistent state

6 6 Transaction Management with SQL Transaction support is provided by following SQL statements: BEGIN TRANSACTION COMMIT ROLLBACK

7 7 The Transaction Log Stores A record for the beginning of transaction For each transaction component (SQL statement) Type of operation being performed (update, delete, insert) Names of objects affected by the transaction (the name of the table) “Before” and “after” values for updated fields Pointers to previous and next transaction log entries for the same transaction The ending (COMMIT) of the transaction

8 8 A Transaction Log

9 9 Concurrency Control Coordination of simultaneous transaction execution in a multiprocessing database system Objective is to ensure transaction serializability in a multiuser database environment Serial Vs Interleaved Execution

10 10 Concurrency Control Simultaneous execution of transactions over a shared database can create several data integrity and consistency problems Lost Updates Dirty Read/Uncommitted Data Read Inconsistent Retrievals

11 11 Normal Execution of Two Transactions

12 12 Lost Updates

13 13 Correct Execution of Two Transactions

14 14 An Uncommitted Data Problem

15 15 Retrieval During Update

16 16 Transaction Results: Data Entry Correction

17 17 Inconsistent Retrievals

18 18 Read/Write Conflict Scenarios: Conflicting Operations Matrix

19 19 Serializability & Precedence Graph

20 20 Concurrency Control with Locking Methods Lock Guarantees exclusive use of a data item to a current transaction Required to prevent another transaction from reading inconsistent data Lock manager Responsible for assigning and policing the locks used by the transactions

21 21 Lock Granularity Indicates the level of lock use Locking can take place at following levels: Database Table Page Row Field (attribute)

22 22 Lock Granularity ( continued ) Database-level lock Entire database is locked Table-level lock Entire table is locked Page-level lock Entire diskpage is locked

23 23 Lock Granularity ( continued ) Row-level lock Allows concurrent transactions to access different rows of the same table, even if the rows are located on the same page Field-level lock Allows concurrent transactions to access the same row, as long as they require the use of different fields (attributes) within that row

24 24 Lock Types Exclusive lock Access is specifically reserved for the transaction that locked the object Must be used when the potential for conflict exists Shared lock Concurrent transactions are granted Read access on the basis of a common lock

25 25 Summary Transaction Sequence of database operations that access the database Represents real-world events Must be a logical unit of work No portion of the transaction can exist by itself Takes a database from one consistent state to another One in which all data integrity constraints are satisfied

26 26 Summary ( continued ) SQL provides support for transactions through the use of two statements: COMMIT and ROLLBACK Concurrency control coordinates the simultaneous execution of transactions Lock guarantees unique access to a data item by a transaction


Download ppt "1 Advanced Database Concepts Transaction Management and Concurrency Control."

Similar presentations


Ads by Google