Sei sulla pagina 1di 22

What we Learn in this Presentation

• Transaction and its Termination Conditions


• ACID Properties
• Types of Transactions
• Transaction Operations
• States of Transactions
• Schedule & Conflicts
• Serializability

Reference:
o Database Systems by Thomas Connolly [6th Edition]
o Principles of Distributed Database Systems by M. Tamer [3rd Edition]
o Database Management Systems by Ramakrishnan [3rd Edition]
o Introduction To Transaction Management [Slides] by Arturas Mazeika
o http://ecomputernotes.com/database-system/rdbms/transaction
Transaction
Processing System
TRANSACTION

An action or series of actions, carried out by a


single user or application program that reads or
updates the contents of the database is known
as Transaction.
Begin_transaction Salary_Increment
begin
UPDATE EMPLOYEE
EXEC SQL Update EMPLOYEE
SET Salary = Salary * 1.1
SET Salary = Salary * 1.1
WHERE Emp_G_No =< 15
WHERE Emp_G_No =< 15
end

It is a single SQL statement that does Select, Update, Insert or Delete of rows.
QUERY It is not necessary that data modification to be made permanent in database.

It is a consecutive sequence of SQL statements that have the “ACID” properties.


TRANSACTION All of the data modifications made during the transaction become a permanent
part of the database.
Termination Conditions of TRANSACTION
A transaction always terminates. Either Commit or Abort

It means that transaction is successfully executed and all the data modifications become the permanent
COMMIT part of the database.

ABORT It means that transaction is not successfully executed and all the data modifications are erased.
ACID Properties of TRANSACTION
A transaction is a single unit of operation that is either executed entirely or none of
ATOMICITY the statement of transaction is executed. It is also called “All or Nothing” property.

A transaction must transform the database from one consistent state to another
CONSISTENCY consistent state. It means that transaction must be correct and data integrity should
be maintained.

Two or more transactions execute independently of one another. An executing


ISOLATION transaction cannot reveal its results to other transaction before it is committed.

The effects of a successfully executed transaction are permanently recorded in the


DURABILITY database and cannot be erased from the database.
Types of TRANSACTION

Transactions have been classified according


to number of criteria.
I. Duration of Transaction
II. Organization Read & Write Action
III. Structure of Transaction
Types of TRANSACTION
( I. Duration of Transaction )

A transaction with very short execution/response times and access relatively small
Short-Life portion of the database. It is also called Online Transaction.
Examples: Banking transactions, Airline Reservation Transactions, etc.

A transaction with longer execution/response times and access a larger portion of the
Long-Life database. It is also called Batch Transaction.
Examples: Statistical Applications, Image Processing, etc.
Types of TRANSACTION
( II. Organization Read & Write Action )
A transaction in which order of read and write action is not specified.
General T : {R(x), W(z), R(y), W(y), W(x), C}

A transaction in which all read actions are performed before any write action.
Two-Step T : {R(x), R(y), W(y), W(x), W(z) C}

A transaction in which restriction is applied that a data item cannot be updated until it
Restricted is read. T : {R(x), R(y), W(y), W(x), R(z), W(z) C}

Restricted A transaction which is made up of both two-step and restricted.


T : {R(x), R(y), R(z), W(y), W(x), W(z) C}
Two-Step
A transaction in which restricted class with the further restriction that each < R,W > pair
Action be executed atomically. T : { [R(x),W(x)], [R(y),W(y)], [R(z),W(z)], C}
Types of TRANSACTION
( III. Structure of Transaction )
A transaction which have only a single start point and a single termination point.
Flat Begin_Transaction Salary_Increment begin ...... end

A transaction which includes other transactions with their own start and end point.
Begin_Transaction ABC begin Begin_Transaction XYZ begin . . . end end
Nested
Closed-Nested : Sub-transactions begin after their parent and finish before them.
Open-Nested : Sub-transactions can execute and commit independently

A collection of tasks organized to accomplish some business process.


There are three types of workflows :
Human-Oriented : It involves humans in performing the tasks.
Workflow System-Oriented : It consists of computation-intensive and specialized tasks that can
be executed by a computer.
Transactional : It range in between human-oriented and system-oriented workflows
and have characteristics of both.
TRANSACTION Operations
Begin_Transaction It indicates the beginning of new transaction.

To read a data item,


1) Find the address of disk block that contains item.
Read 2) Copy that disk block into a buffer in main memory.
3) Then copy that data item into a program variable.

To write a data item,


1) Find the address of disk block that contains item.
2) Copy that disk block into a buffer in main memory.
Write 3) Then copy the data item from a program variable into its correct location in
buffer.
4) Store the updated block from the buffer back to disk.

End It indicates the end limit of transaction execution.


TRANSACTION Operations
It means that transaction is successfully executed and all the data modifications
Commit become the permanent part of the database.

It means that transaction is not successfully executed and all the data modifications
Abort are erased.
States of TRANSACTION
Active An initial state where transactions stay while it is executing.

Partially
A state which occurs after the execution of final statement of transaction.
Committed

Failed A state which occurs when transaction can no longer proceed further.

A state which occurs when the transaction has been rolled back and the database
Aborted has been restored to its state prior to the start of execution.

Committed A state which occurs when transaction is successfully executed.


Desirable Properties of TRANSACTION
A transaction is a single unit of operation that is either executed entirely or none of
ATOMICITY the statement of transaction is executed. It is also called “All or Nothing” property.

A transaction must transform the database from one consistent state to another
CONSISTENCY consistent state. It means that transaction must be correct and data integrity should
be maintained.

Two or more transactions execute independently of one another. An executing


ISOLATION transaction cannot reveal its results to other transaction before it is committed.

The effects of a successfully executed transaction are permanently recorded in the


DURABILITY database and cannot be erased from the database.
Schedule & Conflicts

A sequence of the operations by a set of


concurrent transactions and maintains the order of
operations in each of the individual transactions is
known as Schedule.

T1 T2 T1 T2
Read (x) Read (x) Read (x)
Write (x) Write (x) Write (x)

Read (x)
Write (x)
Schedule & Conflicts
T1
T2
Read (x)
Write (x) Read (x)
Read (y) Write (x)

Serial Schedule: T1 T2
A schedule where the operations of each transactions Read (x)
are executed consecutively is known as Serial Schedule. Write (x)
Read (y)
Read (x)
Write (x)

Non-Serial Schedule: T1 T2
A schedule where the operations of each transactions Read (x)
are interleaved is known as Non-Serial Schedule. Write (x)
Read (x)
Read (y)
Write (x)
Schedule & Conflicts

Two operations CONFLICT if they belong to T1


T2
different transactions and access the same data Read (x)
Write (x) Read (x)
item and one of them is write. Write (x)
Read (y)

T1 T2 T1 T2 T1 T2
Read (x) Read (x) Read (x)
Write (x) Write (x) Write (x)
Read (x) Read (x) Read (y)
Write (x) Read (y) Read (x)
Read (y) Write (x) Write (x)
Schedule & Conflicts
WR Conflicts
A transaction T2 read a data item X that has been modified by transaction T1 T1 T2
which has not been committed. Such a read is also called Dirty Read. Read (x)
Write (x)
Read (x)
WW Conflicts Write (x)
A transaction T2 change the value of a data item X that has been modified by Read (y)
transaction T1 which has not been committed.
T1 T2
RW Conflicts Read (x)
Read (x)
A transaction T2 change the value of a data item X that has been read by
Write (x)
transaction T1 which has not been committed. Write (x)
Read (y)
Serializability

If a non-serial schedule produces the


same result as some serial schedule,
then it is called Serializable Schedule.

To find Non-Serial schedules that


allow transactions to execute
OBJECTIVE concurrently without interfering
with one another.
Serializability
VIEW SERIALIZABILITY or VIEW EQUIVALENCE
A two or more serializable schedule orders any conflicting operations in the same way
as some serial execution. This type of serializability is called Conflict Serializability.

T1 T2 T1 T2 T1 T2 T1 T2
Read (x) Read (x) Read (x) Read (x)
Write (x) Write (x) Write (x) Write (x)
Read (x) O Read (x) Read (y) Read (x)
Write (x) R Read (y) = Write (y) Write (x)
Read (y) Write (x) Read (x) Read (y)
Write (y) Write (y) Write (x) Write (y)
Read (y) Read (y) Read (y) Read (y)
Write (y) Write (y) Write (y) Write (y)
Serializability
VIEW SERIALIZABILITY or VIEW EQUIVALENCE
A two or more serializable schedules perform similar actions in a similar way with three conditions :
1) In S1 if T(n) reads data item X, then in S2 T(n) must read the data item X.
2) In S1 if T(n) reads data item X that has written by T(m), then in S2 T(n) also read data item X from T(m).
3) In S1 if last write operation was performed on data item X by T(n), then in S2 T(n) also perform the
same write operation.

T1 T2 T1 T2
Read (x) Read (x)
Read (x) Read (x)
Write (x) Write (x)
Read (x) Read (y)
Write (x) Read (x)
Read (y) Write (x)
Read (y) Read (y)
Write (y) Write (y)
Serializability
RESULT SERIALIZABILITY or RESULT EQUIVALENCE
A two or more serializable schedules produce the same results after execution.
This type of serializability is called Result Serializability.

T1 T2 T1 T2
Read (x) Read (x)
Write (x) Write (x)
Read (x) O Read (x)
Write (x) R Read (y)
Read (y) Write (x)
Write (y) Write (y)
Read (y) Read (y)
Write (y) Write (y)

Potrebbero piacerti anche