Documente Academic
Documente Profesional
Documente Cultură
Transaction ?
End Users
DataBase
communication End User view point: A request/reply unit System view point:A sequence of operations( Read, write, etc)
Transactions
It is a unit of program execution that accesses & possibly updates various data items. A transaction is a logical unit of work that performs some useful function for a user.
DataBase in consistent state Before Transaction DataBase in consistent state After Transaction
Properties
Atomicity Consistency Isolation Durability
Boundary
BEGIN TRANSACTION Statement to execute the transaction COMMIT/ROLLBACK TRANSACTION
OnOn-line Transaction
A software system that reflects the transactions of a real life system in their entirety is called a Transaction Processing (TP) system. A TP system that provides on-line (where the user is in touch with the system through a terminal or a PC) or instantaneous access is called an On-line TP system or OLTP system.
Features
Concurrent transactions initiated spatially distributed terminals. from
Processors distributed geographically execute the programs initiated by these transactions. One or more databases which may be spatially distributed and used by the transactions.
Responsibilities
Recover database in case of transaction failure Secured control access to the system
Requirements of OLTP
Security Integrity Concurrency Recovery
Security
Protection of data against unauthorized disclosure, alteration or destruction.
Integrity
Integrity refers to business rules of the enterprise
measure of correctness validity of individual items interrelationship between data items in the DataBase at a given point of time interrelationship between data items across all points of time (before start or after completion or cancellation of a transaction);
Check Constraint
Constraint: employee location should be only one of BANGALORE, BOMBAY, DELHI CREATE TABLE EMPLOYEE ( EMP_NO integer NOT NULL, EMP_NAME varchar (15) , EMP_AGE integer, EMP_LOC varchar(15), CHECK ( EMP_LOC in ( BANGALORE, BOMBAY,DELHI)));
Entity Integrity
Entity integrity refers to the fact that theres only one physical entity corresponding to a particular attribute. This attribute is the Primary key.
Referential Integrity
Every employee of any organization must belong to a valid department. Thus, the dept_no field (defined as a foreign key) in the EMPLOYEE table must be a valid key in the DEPARTMENT table. This is called Referential Integrity.
Example of deleting...
Primary key (Order_Num), Foreign key (Cust) REFERENCES Customers ON DELETE CASCADE, Foreign key (Rep) REFERENCES SalesReps ON DELETE SET NULL, ON UPDATE CASCADE, Foreign key (Mfr, Product) REFERENCES Products ON DELETE RESTRICT )
Concurrency
A=1000 B=2000
T1
Serial execution
Serial means executing a set of transactions one after another with no interaction among them at all. Due to the multiprogramming facility the transactions do not get executed serially but execute in an interleaved manner but produce the same result as serial execution of transactions. But How?
b2=b2+temp Write(B,b2)
A=20
Lost update
Transacn T2 t1 t2 t3 t4 t5 t6 t7 t8
A=20
Dirty Read
Transacn T2 t1 t2 t3 t4 t5 t6 t7 t8
Rollback
A = 200 B = 100
Incorrect Summary
T2
t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 Read(A, b1) Sum = Sum + b1
T1
Read (A, a1) a1 = a1-100 Write (A, a1) Read(B, a2) a2 = a2 +100 Write (B, a2) Commit
Phantom record
t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13
T2 Sum = 0
Insert Commit
Concurrent Transactions
Concurrency control techniques : to achieve Serializability Locking Timestamping
Serializability
A given interleaved execution of some set of transactions is said to be serializable if and only if it produces the same result as some serial execution of those transactions
Serializability is mandatory in the design of any OLTP system and the objective of any OLTP is to ensure serializability in the execution of interleaved (concurrent) transactions.
Locking
Locking mechanism records the allocation of a resource in a system table called Lock table. Whenever, a request for accessing a resource is issued, the system checks the Lock table for its availability.
Granularity of locking
Various resources : Field/Column Data row or a tuple Table Database
Locks
Shared Locks Exclusive Locks
Deadlock
Occurs when two or more separate processes compete for resources held by one another.
T1
T2
Deadlock
T1 lock-X(r1) update r1 t1 t2 t3 t4 t5 t4 t5 t6 T2 lock-X(r2) update r2
lock-X(r2) update r2
lock-X(r1) update r1