Transaction Processing and Query Optimization

download Transaction Processing and Query Optimization

of 20

Transcript of Transaction Processing and Query Optimization

  • 7/28/2019 Transaction Processing and Query Optimization

    1/20

  • 7/28/2019 Transaction Processing and Query Optimization

    2/20

    TRANSACTION PROCESSING

    User can store and retrieve data through varioussets of instruction. These sets of instructions doseveral read and write operations on database.These processes are denoted by a special term

    Transaction in DBMS .

    Transaction is the execution of user program inDBMS

    Transaction Management plays a crucial role in

    DBMS . Partial transaction let the database in anincosistency state, so they should be avoided .

    INTRODUCE :

  • 7/28/2019 Transaction Processing and Query Optimization

    3/20

    KEY NOTATIONS IN TRANSACTIONMANAGEMENT

    Object: The smallest Data item which is read orupdated by the Transaction .

    Transaction : is represented by the symbol T. It istermed as the execution of query in DBMS .

    Read Operation : Read operation on particularobject is notated by symbol R(object-name) .

    Write Operation : Write operation on particularobject is notated by symbol W (object-name) .

    Commit: Used to denote the successful completionof one Transaction .

    Abort: Used to denote the unsuccessful interruptedTransaction .

  • 7/28/2019 Transaction Processing and Query Optimization

    4/20

    CONCEPT OF TRANSACTIONMANAGEMENT

    Transaction Manager is responsible for schedulingthe Transactions and providing the safest path tocomplete the task

    To maintain the data in the phase of concurrentaccess and system failure, DBMS need to ensurefour important properties (called as ACIDproperties)

  • 7/28/2019 Transaction Processing and Query Optimization

    5/20

    ACID PROPERTIES OF DBMS

    ACID is an acronym for :

    A Atomicity

    C Consistency

    I Isolation

    D Durability

    Atomicity and Durability are closely related .

    Consistency and Isolation are closely related .

  • 7/28/2019 Transaction Processing and Query Optimization

    6/20

    ATOMICITY AND DURABILITY

    Atomicity :

    The meaning is the transaction cannot be subdivided,and hence, it must be processed in its entirety or not atall .

    Transactions can be incomplete for three kinds ofreasons :

    Transactions can be aborted, or terminated unsuccessfully .

    Due to system crash .

    Due to unexpected situations .

  • 7/28/2019 Transaction Processing and Query Optimization

    7/20

    ATOMICITY AND DURABILITY (CONT)

    Durability :

    If the System crashes before the changes made by acompleted Transaction are written to disk, then it shouldbe remembered and restored during the system restart

    phase . If the Transaction is interrupted in the middle way it

    leaves the database in the inconsistency state. Thesetypes of transactions are called as Partial Transactions .

    Partial Transactions should be avoided to gainconsistency of database . To undo the operations doneby the Partial Transactions DBMS maintains certain logfiles .

  • 7/28/2019 Transaction Processing and Query Optimization

    8/20

    CONSISTENCY AND ISOLATION

    Consistency :

    User who submits the transaction should make sure thetransaction will leave the database in a consistent state.

    Isolation : In DBMS system, there are many transaction may be

    executed simultaneously.

    These transactions should be isolated to each other .

    To enforce this concept DBMS has to maintain certainscheduling algorithms. One of the scheduling algorithmsused is Serial Scheduling .

  • 7/28/2019 Transaction Processing and Query Optimization

    9/20

    SERIAL SCHEDULING

    Transactions are executed one by one from thestart to finish .

    An important technique used in this serialscheduling is interleaved execution .

    Interleaved Execution :

    In DBMS to enforce concurrent Transactions, severalTransactions are ordered in a serial manner andexecuted on by one according to the schedule . So

    there will be the switching over of execution betweenthe Transactions .

  • 7/28/2019 Transaction Processing and Query Optimization

    10/20

    EXAMPLE :

  • 7/28/2019 Transaction Processing and Query Optimization

    11/20

    ANOMALIES DUE TO INTERLEAVEDTRANSACTIONS

    When the read and write operations donealternatively there is a possibility of some typeanomalies .

    These are classified into three categories :

    Write Read Conflicts (WR Conflicts)

    Read Write Conflicts (RW Conflicts)

    Write Write Conflicts (WW Conflicts)

  • 7/28/2019 Transaction Processing and Query Optimization

    12/20

    EXAMPLE : (WR CONFLICTS)

    Consider two Transactions T1 and T2, each ofwhich, run alone, preserves database consistency.T1 transfers $200 from A to B, and T2 incrementsboth A and B by 6% /

  • 7/28/2019 Transaction Processing and Query Optimization

    13/20

    EXAMPLE : (RW CONFLICTS)

    If A denotes an account. Consider two

    Transactions T1 and T2. Duty of T1 and T2 arereducing account A by $100.

  • 7/28/2019 Transaction Processing and Query Optimization

    14/20

    EXAMPLE : (WW CONFLICTS)

    Consider the two Transactions T1, T2. Consider thetwo objects A, B.

  • 7/28/2019 Transaction Processing and Query Optimization

    15/20

    LOCK-BASED CONCURRENCYCONTROL

    Concurrency Control is the control on the Databaseand Transactions which are executed concurrentlyto ensure that each Transaction completed healthy .

    Concurrency control is concerned with preventingloss of data integrity due to interference betweenusers in a multiuser environment.

    Need for Concurrency Control

    Lock-Based Concurrency Control

  • 7/28/2019 Transaction Processing and Query Optimization

    16/20

    KEY TERMS IN LOCK-BASEDCONCURRENCY CONTROL

    Database Object

    Database Object is the small data element, the value ofwhich one is altered during the execution of transactions

    Lock

    Lock is a small object associated with Database Objectwhich gives the information about the type of operationsallowed on a particular Database Object.

    With locking, any data that is retrieved by a user for

    updating must be locked, or denied to other users, untilthe update is complete.

  • 7/28/2019 Transaction Processing and Query Optimization

    17/20

    LOCKING PROTOCOL

    It is the set of rules to be followed by eachtransaction, to ensure that the net effect ofexecution of each Transaction in interleavedfashion will be same as, the result obtained when

    the Transactions executed in serial fashion . Generally locks can be classified into two :

    First one is related to what already told in the previousparagraph .

    Next one is the unwanted effect when we implement

    lock of the first type. The two types of Lock are :

    Strict Two-Phase Locking (Strict 2PL)

    Deadlock

  • 7/28/2019 Transaction Processing and Query Optimization

    18/20

    STRICT TWO-PHASE LOCKING (STRICT2PL)

    It provides few rules to the Transactions to accessthe Database Objects :

    Rule 1 : If a Transaction T wants to read, modify an

    object, it first requests a shared, exclusive lock on the

    Database Object respectively . Rule 2 : All Locks held by the Transaction will be

    released when it is completed .

  • 7/28/2019 Transaction Processing and Query Optimization

    19/20

    STRICT TWO-PHASE LOCKING (STRICT2PL) (CONT)

    Shared Lock :

    It is like a component which is sharable within all activetransactions .

    A database Object can be shared locked by more than one

    number of transaction . Condition : It should no be exclusively locked by any of the

    other Transactions .

    Exclusive Lock :

    It is like a component which cannot be sharable within all

    active transactions . It is dedicated to particular transaction; only that particular

    transaction can access and modify that object .

    Condition : It should not be exclusively locked by any one ofthe other Transactions .

  • 7/28/2019 Transaction Processing and Query Optimization

    20/20

    STRICT TWO-PHASE LOCKING (STRICT2PL) (CONT)

    DeadLock :

    Due to this neither one will be committed .