Docsity

Introduction to Transaction Management in Database Systems, Lecture notes of Database Management Systems (DBMS)

Partial preview of the text

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

Introduction to Transaction Management

Oct 2017

✥ What is a transaction? ✥ What properties transactions have? ✥ Why do we want to interleave transactions? ✥ How does the DMBS deal with transactions? ✥ How do we use transactions from SQL?

Overview

✥ The DBMS must ensure 4 important properties of transactions:

  1. Transactions should be atomic. Either they happen or they don’t happen at all.
  2. Each transaction, run by itself, alone, should preserve the consistency of the database. The DBMS assumes that consistency holds for each transaction.
  3. Isolation : Transactions are isolated from the effect of other transactions that might be executed concurrently
  4. Durability : Once the user is notified that the transaction was successful, its effects should persist even if the system crashes.

ACID

✥ Users are responsible for the consistency of their transactions ✥ Each transaction must leave the database in a consistent state if the database is consistent when the transaction begins. ✥ The DBMS will enforce ICs and other constraints ✥ Beyond this, the database does not really understand the semantics of the data. (e.g., it does not understand how the interest on a bank account is computed). ✥ Database consistency is the property that every transaction sees a consistent database instance

Consistency

✥ If a transaction ends, we say its commits , otherwise it aborts ✥ Transactions can be incomplete for three reasons:

  1. It can be aborted by the DBMS
  2. A system crash
  3. The transaction aborts itself ✥ When a transaction does not commit, its partial effects should be undone ✥ Users can then forget about dealing with incomplete transactions ✥ But if it is committed it should be durable

Atomicity

✥ The DBMS uses a log to ensure that incomplete transactions can be undone, if necessary

Atomicity

Schedules

✥ A schedule is a potential execution sequence of a set of transactions ✥ It describes actions as seen by the DBMS: T 1 T 2 R(A) W(A) R(C) W(C) Commit R(B) W(B) Abort ✥ If the actions are not interleaved, it is called a serial schedule.

Schedules...

T 1 T 2 R (A ) W (A ) R (A ) W (A ) R (B ) W (B ) R(B) W(B) Com mit

Com mit

T^1 T^2 R(A) W(A) R(A) R(B) W(B) W(A) R(B) W(B) Commit Commit

T 1 T 2 R(A) W(A) R(B) W(B) Commit R(A) W (A) R(B) W(B) Commit

✥ Note: SQL programmers can instruct the database to use non-serializable schedules.

✥ Concurrency can leave to an inconsistent state ✥ Two actions in the same object conflict it at least one is a write ✥ 3 types of anomalies (assume transactions T 1 , T 2 )

✥ T 2 reads data that has not been committed yet T 1 T 2 R(A) W(A)

WR Conflict

R (B) W (B) Commit

R(A) W(A)

WW Conflicts: Overwriting Uncommitted

Data

✥ T 2 overwrites the value of an object A, already modified by T 1 , while T 1 is still in progress T 1 T 2 W(A)

10–14 Introduction to Transaction Management (1.1.0)

W(B) Com mit

W(A) W