Docsity

transactions in Database, Lecture notes of Database Management Systems (DBMS)

Partial preview of the text

Download transactions in Database and more Lecture notes Database Management Systems (DBMS) in PDF only on Docsity!

TRANSACTIONS

WHY TRANSACTIONS?

Database systems are normally being accessed by many users or processes at the same time.

Unlike OS, which support interaction of processes, a DMBS needs to keep processes from troublesome interactions.

TRANSACTIONS

Transaction = process involving database queries and/or modification.

Normally with some strong properties regarding concurrency.

Formed in SQL from single statements or explicit programmer control.

ACID TRANSACTIONS

ACID transactions are: ⚫ Atomic : Whole transaction or none is done. ⚫ Consistent : Database constraints preserved. ⚫ Isolated : It appears to the user as if only one process executes at a time. ⚫ Durable : Effects of a process survive a crash.

Optional: weaker forms of transactions are often supported as well.

ROLLBACK

The SQL statement ROLLBACK also causes the transaction to end, but by aborting. ⚫ No effects on the database.

Failures like division by 0 or a constraint violation can also cause rollback, even if the programmer does not request it.

EXAMPLE: INTERACTING PROCESSES

Consider a relation Sells(shop, item, price) Let Ahmad sells Sprite for Rs12.50 and Pizza Slize for Rs 35.00. Tania is querying Sells for the highest and lowest price Ahmad charges. Ahmad decides to stop selling Sprite and Pizza, but to sell Biryani at Rs75.00 per plate.

SHOP KEEPER’S PROGRAM

At about the same time, Ahmad executes the following steps: (del) and (ins). (del) DELETE FROM Sells WHERE shop = ’Ahmad’’s shop’; (ins) INSERT INTO Sells VALUES(’Ahmad’’s shop’, ’Biryani’, 75.00);

INTERLEAVING OF STATEMENTS

The statement (max) must come before (min), and

The statement (del) must come before (ins),

There are no other constraints on the order of these statements, unless we group Tania’s and/or Ahmad’s statements into transactions.

FIXING THE PROBLEM BY USING TRANSACTIONS

If we group Tania’s statements (max)(min) into one transaction, then she cannot see this inconsistency. She sees Ahmad’s prices at some fixed time. ⚫ Either before or after he changes prices, or in the middle, but the MAX and MIN are computed from the same prices.

ANOTHER PROBLEM: ROLLBACK

Suppose Ahmad executes (del)(ins), not as a transaction. But after executing these statements, he change his mind and issues a ROLLBACK statement. If Tania executes her statements after (ins) but before the rollback, she sees a value, 75.00, that never existed in the database.

TRANSACTION PROCESSING

Basic operations in a DB are read and write

⚫ read_item(X ): Reads a database item named X into a program variable. To simplify our notation, we assume that the program variable is also named X. ⚫ write_item(X ): Writes the value of program variable X into the database item named X.

SAMPLE TRANSACTIONS

ISSUES IN TRANSACTION PROCESSING

Temporary Update (or Dirty Read) Problem

ISSUES IN TRANSACTION PROCESSING

The Incorrect Summary Problem