1 of 41

CSE 414 Section 6:

Transactions and Serializability

November 5th, 2026

2 of 41

Announcements

  • HW4 due Monday, Nov 9th @ 11:59pm
  • Midterm tomorrow during lecture time – Covers everything from beginning of the class up to Relational Algebra

​

3 of 41

HW 4 Q3: What is “Closed”?

  • A set of attributes X is called “closed” (given set of FDs) if X⁺ = X.
  • Example: Suppose the only closed sets of a relation R(A, B, C) are {}, {A}, {B, C}, and {A, B, C}. Find FDs to satisfy this condition.
  • One solution: A → A (trivial FD), B → C, C → B
    • {A}⁺ = {A}
    • {B}⁺ = {BC}
    • {C}⁺ = {BC}
    • {AC}⁺ = {ABC}
    • Empty set: {}⁺ = {}

​

4 of 41

Motivation for Transactions

5 of 41

ACID

Atomic�Consistent�Isolated�Durable

Everything a concurrent database user wants…

6 of 41

How do ACID properties help us?

  • Ensure that a transaction maintains database integrity
  • ACID compliance matters to important databases ($$$)
  • In this section: delve into the DB Internals required to guarantee ACID

7 of 41

Atomicity

What? “Atom” - a transaction is indivisible; data operations inside the transaction work in an all or nothing fashion

How? Transaction commit and rollback

Example: Transfer of funds from one account to another involves an atomic transaction that includes operations of debit and credit

8 of 41

Consistency

What? Only data operations that comply with database validity constraints are allowed.

Once a transaction is completed, it must not leave the database incomplete or inconsistent.

How? Enforcement of consistency rules upon data entry/updation

Example: A database having both first and last name fields will not accept if you enter only one of those - must enter both for the transaction to be complete

9 of 41

Isolation

What? The appearance of a transaction happening by itself irrespective of what other transactions are happening concurrently

How? User views the database that was present right before the view request is made and any further transactions that are in process after it are ignored

Example: A teller looking up a balance must be isolated from a concurrent transaction involving a withdrawal from the same account

10 of 41

Durability

What? Once a transaction is complete the information as changed will survive failures of any kind

How? Creation of data “mirrors”

Example: Trying to make an update that leads to a system failure should not tamper with any of the previous data and transactions

11 of 41

Txn Perspective

A database is a collection of "elements" that can be written to or read from.

Operation - A read or write to an element (later: or an insert or delete)

  • example of read (R): SELECT
  • example of write(W): UPDATE

Example: What operation does the following SQL query contain?�SELECT cases FROM Country WHERE cname = ‘France’;

​

12 of 41

Txn Perspective

A database is a collection of "elements" that can be written to or read from.

Operation - A read or write to an element (later: or an insert or delete)

​

Example: What operation does the following SQL query contain?�SELECT cases FROM Country WHERE cname = ‘France’;

Answer: R(France)

13 of 41

Practice - convert SQL to operations

Txn 1:

1a) x = SELECT cases FROM Country WHERE cname = ‘France’;

1b) x = x + 200;

1c) UPDATE Country SET cases = `x` WHERE cname = ‘France’;

​

Txn 2:

2a) y = SELECT cases FROM Country WHERE cname = ‘Spain’;

2b) y = y / 5;

2c) z = SELECT cases FROM Country WHERE cname = ‘France’;

2d) UPDATE Country SET cases = `y + z` WHERE cname = ‘France’;

14 of 41

Practice - convert SQL to operations

Txn 1:

1a) x = SELECT cases FROM Country WHERE cname = ‘France’;

1b) x = x + 200;

1c) UPDATE Country SET cases = `x` WHERE cname = ‘France’;

​

Txn 2:

2a) y = SELECT cases FROM Country WHERE cname = ‘Spain’;

2b) y = y / 5;

2c) z = SELECT cases FROM Country WHERE cname = ‘France’;

2d) UPDATE Country SET cases = `y + z` WHERE cname = ‘France’;

1a) R(France)

1b)

1c) W(France)

​

​

2a) R(Spain)

2b)

2c) R(France)

2d) W(France)

15 of 41

Definitions

Operation -

Transaction -

Schedule -

Serial schedule -�

Serializable schedule - �

16 of 41

Definitions

Operation - read or write of an element (later: insert or delete)

Transaction - series of operations meant to have the ACID guarantees

Schedule - ordering of the operations of some txns

Serial schedule - schedule where each txn is executed one after another.� No interleaving

Serializable schedule - a schedule that is behaviorally equivalent � to a serial schedule

17 of 41

Definitions

Non-conflicting swap - �

Conflicting swap -

Conflict serializable schedule - �

​

18 of 41

Definitions

Non-conflicting swap - a pair of adjacent operations in a schedule � that can be reversed without affecting the schedule's behavior

Conflicting swap - (any two ops in same txn), RW, WR, WW

Conflict serializable schedule - a schedule that can be transformed � into a serial schedule via a series of non-conflicting swaps

​

19 of 41

Conflict Serializability

Checking for conflict serializability -> precedence graph and cycle checking

20 of 41

Conflict Serializability

Checking for conflict serializability -> precedence graph and cycle checking

21 of 41

Serializability

“Conflict serializable” is a stronger constraint than “serializable”

I.e. Any schedule that is conflict serializable must be serializable.

​

​

Serializable

Conflict

Serializable

Easy to check

Not easy to check

22 of 41

Serializability

S1: w1(Y); w2(Y); w1(X); w2(X); w3(X)

S2: w1(Y); w2(Y); w2(X); w1(X); w3(X)

Are these serializable? Conflict serializable?

23 of 41

Serializability

S1: w1(Y); w2(Y); w1(X); w2(X); w3(X)

S2: w1(Y); w2(Y); w2(X); w1(X); w3(X)

Conflict Serializable

Serializable (but not conflict serializable)

24 of 41

Worksheet

25 of 41

WS Problem B

T1

T2

T3

​

​

R(C)

​

​

W(D)

​

R(B)

​

​

W(C)

​

R(A)

​

​

W(B)

​

​

We can start with the serial order the problem requires. This means all transactions are completed sequentially. As long as we do valid swaps, we should have an equivalent schedule at the end!

26 of 41

WS Problem B

T1

T2

T3

​

​

R(C)

​

​

W(D)

​

R(B)

​

​

W(C)

​

R(A)

​

​

W(B)

​

​

We want to get T1 to commit before T3 starts! Let’s start with moving R1A

27 of 41

WS Problem B

T1

T2

T3

​

​

R(C)

​

​

W(D)

​

R(B)

​

​

W(C)

​

R(A)

​

​

W(B)

​

​

We want to get T1 to commit before T3 starts! Let’s start with moving R1A

28 of 41

WS Problem B

T1

T2

T3

R(A)

​

​

​

​

R(C)

​

​

W(D)

​

R(B)

​

​

W(C)

​

W(B)

​

​

Looks like T1 is the only transaction that has any action on A, so we can safely swap it to the top

29 of 41

WS Problem B

T1

T2

T3

R(A)

​

​

​

​

R(C)

​

​

W(D)

​

R(B)

​

​

W(C)

​

W(B)

​

​

Now let’s see what we can do with W1B

30 of 41

WS Problem B

T1

T2

T3

R(A)

​

​

​

​

R(C)

​

​

W(D)

​

R(B)

​

W(B)

​

​

​

W(C)

​

Uh oh, we can’t swap these! We need to move R2B to happen before T3 starts too.

31 of 41

WS Problem B

T1

T2

T3

R(A)

​

​

​

​

R(C)

​

​

W(D)

​

R(B)

​

W(B)

​

​

​

W(C)

​

We can safely swap R2B up since T3 does not have to do with the attribute B!

32 of 41

WS Problem B

T1

T2

T3

R(A)

​

​

​

R(B)

​

​

​

R(C)

​

​

W(D)

W(B)

​

​

​

W(C)

​

Now we can go back to W1B

33 of 41

WS Problem B

T1

T2

T3

R(A)

​

​

​

R(B)

​

​

​

R(C)

​

​

W(D)

W(B)

​

​

​

W(C)

​

Now we can go back to W1B. We can safely swap it up!

34 of 41

WS Problem B

T1

T2

T3

R(A)

​

​

​

R(B)

​

W(B)

​

​

​

​

R(C)

​

​

W(D)

​

W(C)

​

Now we can go back to W1B. We can safely swap it up!

35 of 41

WS Problem B

T1

T2

T3

R(A)

​

​

​

R(B)

​

W(B)

​

​

​

​

R(C)

​

​

W(D)

​

W(C)

​

Transaction 1 commits before transaction 3 starts (as specified in the problem). We’re done!

36 of 41

WS Problem B: Solution 1

T1

T2

T3

R(A)

​

​

​

R(B)

​

W(B)

​

​

​

​

R(C)

​

​

W(D)

​

W(C)

​

R1(A), R2(B), W1(B), Co1, R3(C), W3(D), Co3, W2(C), Co2

​

37 of 41

Some Alternate Solutions

38 of 41

WS Problem B: Solution 2

T1

T2

T3

​

R(B)

​

R(A)

​

​

W(B)

​

​

​

​

R(C)

​

​

W(D)

​

W(C)

​

R2(B), R1(A), W1(B), Co1, R3(C), W3(D), Co3, W2(C), Co2

​

39 of 41

WS Problem B: Solution 3

T1

T2

T3

R(A)

​

​

​

R(B)

​

W(B)

​

​

​

​

R(C)

​

W(C)

​

​

​

W(D)

R1(A), R2(B), W1(B), Co1, R3(C), W2(C), Co2, W3(D), Co3

​

40 of 41

WS Problem B: Solution 4

T1

T2

T3

​

R(B)

​

R(A)

​

​

W(B)

​

​

​

​

R(C)

​

W(C)

​

​

​

W(D)

R2(B), R1(A), W1(B), Co1, R3(C), W2(C), Co2, W3(D), Co3

​

41 of 41

Takeaways

  • You can always swap two reads (even if they are on the same element!)
  • Be careful about swapping writes
    • If they are writing on different attributes, like W1(A) and W2(B), then it’s ok to swap.
    • Otherwise, you can’t safely swap two writes on the same attribute (write conflict). For example, W1(A) and W2(A) can’t be swapped. Swapping writes within a given transaction would also be a conflict, like if a transaction had W1(A) followed by W1(A).