Transactions generalities 1 Transactions - generalities
Transactions generalities 2 Transactions - example Parts P_id, P_name, Colour, Weight, Total_qty Contracted S_id, P_id, Qty Update add a new contract between S4 for 200 pieces of P1
Transactions generalities 3 Example extension
Transactions generalities 4 Transaction logical unit of work sequence of database operations transforms a consistent state of a db into another consistent state between operations the db can be inconsistent
Transactions generalities 5 Pseudo-code BEGIN TRANSACTION; INSERT (S4, P1, 200) INTO Contracted; IF any error occurred THEN GO TO undo; UPDATE Parts WHERE P_id =P1 SET Total_qty = Total_qty + 200; IF any error occurred THEN GO TO undo; COMMIT TRANSACTION; GO TO finish; undo: ROLLBACK TRANSACTION; finish: RETURN;
Transactions generalities 6 SQL support COMMIT and ROLLBACK No BEGIN TRANSACTION (in SQL2 and Oracle) all data definition and data manipulation statements are transaction initiating PostgreSQL provides BEGIN [TRANSACTION]
Transactions generalities 7 Transaction processing do not allow for one operation to be performed and the other ones not the system should guarantee that all constituent operations will be executed not possible! hence the following principle: principle of transaction processing support if some operations are executed and then a failure occurs (before the planned termination) then those operations will be undone
Transactions generalities 8 Transaction manager COMMIT TRANSACTION a logical unit of work was successfully completed all the updates can be made permanent ROLLBACK TRANSACTION unsuccessful end of transaction all the attempted updates must be rolled back
Transactions generalities 9 COMMIT and ROLLBACK points BEGIN TRANSACTION COMMIT time COMMIT idle transaction time same point as far as the DB state is concerned BEGIN TRANSACTION ROLLBACK time COMMIT idle transaction time same state of DB
Transactions generalities 10 At the COMMIT point all updates, since the previous commit, are made permanent (will not be undone) all database positioning and all tuple locks are lost
Transactions generalities 11 ACID properties of transactions Atomicity all or nothing Consistency preserve database consistency Isolation transactions are isolated from one another Durability committed transaction updates are performed
Transactions generalities 12 Pointers ahead recovery concurrency