ADSI Notes - Diogo Lopes

Search

Search IconIcon to open search

Lecture 6 - Transactions and concurrency

Last updated Mar 17, 2023

Slides

# “We want performance”

# Transaction Concept

# Main issues

Focus on READ and WRITE

If fails in the middle -> ROLLBACK

# ACID

# Transaction State

Schedule: a sequences of instructions that specify the
chronological order in which instructions of concurrent
transactions are executed

Serial Mode: One transaction at the time (1 after the other) Schedule 1 is T1 and T2 in Serial Mode This one is Schedule 3

We can switch the order of blocks if they operate in diff objs

Basic Assumption – Each transaction preserves database
consistency. We focus on a particular form of schedule equivalence called
conflict serializability

# Conflicting Instructions

  1. Ti : read(Q) Tj : read(Q) No conflict
  2. Ti : read(Q) Tj : write(Q) Conflict
  3. Ti : write(Q) Tj : read(Q) Conflict
  4. Ti : write(Q) Tj : write(Q) Conflict

Forces temporal order: usually the older transaction executes first

# Conflict equivalent

If a schedule S can be transformed into a schedule S’ by a series
of swaps of non-conflicting instructions, we say that S and S’ are
conflict equivalent.

# Conflict serializable

We say that a schedule S is conflict serializable if it is conflict
equivalent to a serial schedule.

(Does not follow the “Precedence Graph”) We are unable to swap instructions in the above schedule to obtain either
the serial schedule < T3 , T4 >, or the serial schedule < T4 , T3 >.

# Recoverable Schedules

# Cascading rollback

(the schedule is recoverable)

# Cascadeless schedules

# Levels of Consistency in SQL

Analysis Queries can benefit for “Read Uncommited” as it is the fastest (and full parallel)

In SQL Server the default is READ COMMITTED (preferes a performance approach)

Some systems have additional isolation levels

# Implementation of Isolation Levels

(Locking, Timestamps, Multiple versions of each data item)

# Locking

  1. Exclusive (X) mode. Data item can be both read as well as
    written. X-lock is requested using lock-X instruction.
  2. Shared (S) mode. Data item can only be read. S-lock is
    requested using lock-S instruction.

Bad Lock example:

You should not release a lock inside a transaction

# 2-Phase Locking

A protocol which ensures conflict-serializable schedules

Does not PREVENT DEADLOCKS

Lecture 5 Query Optimization | Lecture 7 Transactions and concurrency pt2