Docsity
Trusted Seller

Appunti Data Management Sapienza Lenzerini, Appunti di Basi di Dati

Toggle sidebar
bg1
Data Management Notes
Luca Tomei
Academic Year 2020-2021
Contents
1 Introduction W1
1.1 Reviewon”RA” ................................................ 1
1.2 SQL ....................................................... 2
2 Architecture of a DBMS W3
2.1 ArchitectureofBufferManager........................................ 3
2.1.1 BufferPool ............................................... 4
2.1.2 BufferManager............................................. 4
2.1.3 FIX ................................................... 4
2.1.4 ReplacementPolicy .......................................... 4
2.1.5 Unfix .................................................. 4
2.1.6 Use ................................................... 4
2.1.7 Force .................................................. 4
2.1.8 Flush .................................................. 5
3 Transaction management W6
3.1 Transactions .................................................. 6
3.1.1 Isolation................................................. 6
3.1.2 ACIDproperties ............................................ 6
3.1.3 Schedules ................................................ 6
3.1.4 Serializability.............................................. 6
3.1.5 Scheduler ................................................ 7
3.2 View-Equivalence & View-Serializability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.3 Conflict Equivalence & Conflict Serializability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.3.1 Topologicalorderofagraph...................................... 10
3.3.2 Algorithm for Conflict-Serializability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.3.3 Comparison with view-serializability: Two Theorems . . . . . . . . . . . . . . . . . . . . . . . . 11
3.3.4 Order preserving conflict serializability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.3.5 Commit-order preserving conflict serializability . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.4 Concurrency control through locks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.4.1 TwoPhaseLocking .......................................... 13
3.4.2 Exercises ................................................ 13
3.4.3 SharedLocks .............................................. 14
3.4.4 Techniques for deadlo ck management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.5 RecoverabilityofTransactions......................................... 15
3.5.1 CascadingRollback .......................................... 15
3.5.2 RecoverableSchedules ......................................... 15
3.5.3 ACR................................................... 16
3.5.4 StrictSchedules............................................. 16
3.5.5 RigorousSchedules........................................... 16
3.6 Recoverabilityand2PL ............................................ 16
3.6.1 Strict2PLProtocol .......................................... 16
3.6.2 StrongStrict2PLProtocol ...................................... 16
3.7 Concurrency control through timestamps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e

Anteprima parziale del testo

Scarica Appunti Data Management Sapienza Lenzerini e più Appunti in PDF di Basi di Dati solo su Docsity!

Data Management Notes

1 Introduction W

1 Introduction W

1.1 Review on ”RA”

Exercise: We have these 2 relations:

Graduated(gcode, mark, school) School(scode, city)

  1. Find the cities where there is at least one school with a student who graduated with 100.
휎푠푐ℎ표표푙.푠푐표푑푒=푔푟 푎푑푢푎푡푒푑.푠푐ℎ표표푙 (퐺푟푎푑푢푎푡푒푑 × 푆푐ℎ표표푙)

But instead we can write:

Π푐푖푡푖푒푠

What is the difference? Prove that they are equivalent.

PROOF

Suppose we have Graduated(gcode, mark, school) and School(scode, city). We need to prove that these 2 queries are equivalent:

(a) Π푐푖푡푖푒푠

휎푠푐ℎ표표푙.푠푐표푑푒=푔푟 푎푑푢푎푡푒푑.푠푐ℎ표표푙 (퐺푟푎푑푢푎푡푒푑 × 푆푐ℎ표표푙)

and

(b) Π푐푖푡푖푒푠

Selection operation is commutative, so: 휎퐴휎퐵(푅) = 휎퐵 휎퐴(푅). A selection whose condition is a con- junction is equivalent to a sequence of selections with those same individual conditions: 휎퐴∧퐵(푅) = 휎 1 (휎퐵(푅)) = 휎퐵(휎퐴(푅)). Let 휎퐴 be: 휎퐴 = 휎퐵∧퐶 = 휎푚푎푟 푘 = 100 ︸ ︷︷ ︸ 퐵

퐶

. From the properties of

selection we have that: 휎퐴 = 휎퐵∧퐶 = 휎퐵(휎퐶 (푅)) = 휎퐶 (휎퐵(푅)) Let 푅 be (퐺푟푎푑푢푎푡푒푑 × 푆푐ℎ표표푙), so if I first apply 휎퐶 to 푅 and then 휎퐵 it is the same as applying 휎퐵 first and then 휎퐶.

The sequences of the two operations are:

First:

PROJ
SEL
JOIN

Graduated School

Second:

PROJ
JOIN
SEL

Graduated

School

The second method is better on performance because we compute a join after some tuple and the circled nodes have been removed.

Data Management Notes

2 Architecture of a DBMS W

2 Architecture of a DBMS W

Databases are a set of database files where each file is constituted by a set of pages, stored in physical blocks. If we want to use a page we need to bring it in main memory. The size of a block (and of a page) is the size of portion of storage that can be transferred to main memory and vice versa. The buffer pool is a non-persistent memory space dedicated to the DBMS to process pages. Th buffer management is responsible of the transfer of the pages between ram and disk. The buffer pool is used by the system /recovery manager) and shared by all transactions.

2.1 Architecture of Buffer Manager

Data Management Notes

2 Architecture of a DBMS W

2.1.1 Buffer Pool

Organized in frames, that are main memory pages, whose size is that of a block. Buffer pool is in RAM so its management is more efficient with respect to secondary storage. Is managed with the same principles of the cache (locality, block replacement, ...).

2.1.2 Buffer Manager

It uses ”page table” data structure that associates to each page an ID (PID) appearing in the buffer. It uses 5 primitives: FIX, UNFIX, USE, FORCE and FLUSH.

2.1.3 FIX

External module issues a ”Fix” in order to ask the buffer manager to load a specific page into a frame of the buffer. For each frame, the BM maintains:

  • The info about which page it contains
  • The PIN-Count = How many transactions use the page contained in the frame (initial = 0)
  • The Dirty Bit: TRUE if the content of the frame has been modified, FALSE otherwise (initially = FALSE).

What happens when a Fix is issued:

1 BM checks if a frame already contains the page with requested PID 2 If YES, PIN-COUNT ++ (of that fram) 3 If NOT, then

3.1 BM chooses a frame 퐹′^ according to certain replacement policy. 3.2 If the dirty-bit of 퐹′^ is TRUE, then the page contained in F’ is written back to secondary storage.

3.3 Page 푃 is read from secondary storage and loaded into 퐹′. Then PIN-COUNT of 퐹′^ = 0 and dirty-bit = FALSE

4 BM returns the address of 퐹′^ to the module issuer.

2.1.4 Replacement Policy

The victim is chosen among those with pin-count=0. If no frame has pin-count = 0, the request is put in a queue or the transaction is aborted. Otherwise, two policies can be used: LRU & Clock Replacement.

1 LRU: Least Recent Used, done with a queue containing the frames with pin = 0. 2 Clock Replacement: Using a pointer called current, we cycle through the frames. Each frame has a bit called referenced that says if the page contained in the frame has been used recently. Referenced is set to TRUE when pin-count = 0. If the pointed frame has pin-count = 0, we split that (page used often). If the frame has pin-count = 0 and referenced = TRUE, we set it to FALSE because time has passed since the last used of the page contained in the frame, then we split the frame. Finally, if pin-count = 0 and referenced = FALSE, the frame is chosen as victim.

2.1.5 Unfix

The transaction certifies that is does not need to the content of a page anymore pin-counter decremented.

2.1.6 Use

The transaction modifies the content of a frame dirty-bit set to TRUE

2.1.7 Force

Synchronous (i.e. the transaction waits for the successful competition of the operation) transfer to secondary storage of the page contained in the frame.

Data Management Notes

4 Recovery Management W

3 Transaction management W

3.1 Transactions

Transaction is an abstraction of execution from a software that wants to access data (read/write). Syntactically, it starts with ”BEGIN”, ends with ”END” and confirms what it has done with ”COMMIT”. Concur- rency is a fundamental concept, we mus unsure it among transactions (for throughput purposes).

.................................................. .Example................................................... Example of concurrency problem: APP 1

  1. Find Seat
  2. BookSeat
APP 2

FindSeat

BookSeat

FindSeat finds the same seat so it will be a problem for APP2 to book it after APP1. This is because transactions are not isolated.

3.1.1 Isolation

Isolation of transactions means that it is executed like it was the only one in the system, i.e. without concurrent transactions

3.1.2 ACID properties

Properties of transactions are called ACID properties.

1 Atomicity: Either all or none of the transactions actions have their effect.

2 Consistency: Each transaction execution brings the DB to a correct state.

3 Isolation: Each transaction is independent from the others executed concurrently. 4 Durability: If a transaction execution succeed, then its effect is permanent stored in DB.

3.1.3 Schedules

Suppose we have a set of transactions {푇 1 , ..., 푇푁 }. A sequence 푆 of execution of actions of such transaction respecting the order within each transactions is called schedule. A schedule can be partial if does not contain all the actions of the transactions. A schedule is serial if the actions of different transactions in 푆 do not interleave.

3.1.4 Serializability

A schedule 푆 that is not serial is correct with respect to concurrency if it is serializable, i.e. there is a serial sched- ule 푆′^ constituted by the same transactions of 푆 s.t. ∀ initial state 퐼, the outcome of 푆 is the same as the outcome of 푆′.

”A schedule 푆 on {푇 1 , 푇푁 } is serializable if there exists a serial schedule on {푇 1 , ..., 푇푁 } that is equivalent to 푆”. What does equivalent mean? ∀ input → produces the same output.

푆′^ 퐸 ′

푆′′^ 퐸 ′′

Two finite states automatas are equivalent if ∀ input they produce the same output.

But if the input is infinite (all the possible inputs) → then it does not exist an algorithm that can check if two automatas are equivalent. The problem is called the ”Halting” problem and it is an undecidable problem. So the Serializable’s definition cannot be applied in pracrice because the equivalence cannot be checked. → The solution is to ”Relax” the notion of equivalence.

Data Management Notes

3 Transaction management W

Very often, software’s architecture is made as Tier III:

Presentation Layer

App. Layer

Actions

Transaction Manager

Transactions (푇 1 , 푇 2 , ..., 푇 3 ) are created in App. Layer.

         

User 1 wants to buy a ticket User 2 .. .. .. .. .. .. .. User 1 wants to give a score to the service of buying a ticket. If transaction manager receives transaction 푇 1 , 푇 2 , 푇 3 , it thinks they are correct because the app layer gave them to it. So it should be the App. Layer to think if there are problems with the order of the transactions, not the data layer. Inside the transaction manager there is the Scheduler.

3.1.5 Scheduler

1 It assigns an ID to the transactions. 2 It abstracts from operations in the local store. 3 It decides if a schedule is acceptable of not.

Defining different notion of serializability to solve the equivalence problem.

Preliminary Definitions

  • In a schedule 푆, we say that 푟푖 (푥) READS-FROM 푤 (^) 푗 (푥) if 푤 (^) 푗 (푥) precedes 푟푖 (푥) in 푆, and there is no action of type 푤푘 (푥) between 푤 (^) 푗 (푥) and 푟푖 (푥).
  • In a schedule 푆, we say that 푤푖 (푥) is a FINAL-WRITE if 푤푖 (푥) is the last write action on 푥 in 푆.

3.2 View-Equivalence & View-Serializability

Let 푆 1 and 푆 2 be two complete schedules on the same transactions. Then 푆 1 is View-Equivalent to 푆 2 if 푆 1 and 푆 2 have the same READS-FROM relation and the same FINAL-WRITE set. A complete schedule 푆 is View-Serializable if ∃ a serial schedule 푆′^ on the same transactions of 푆 that is view- equivalent to 푆.

Example: Consider the following schedule

read1(A,t) read2(A,s) s:=100 write2(A,s) t=100 write1(A,t)

Is it serializable? Is it View-Serializable? 푇 1 and 푇 2 do the same thing on the DB, does not matter the initial state, they will write 100, so it is serializable. If we write it without local store:

R1(A) R2(A) W2(A) W1(A)

훼 → 푇 1 푇 2 → R1(A) W1(a) R2(A) W2(A). NO! 훽 → 푇 2 푇 1 → R2(A) W2(A) R1(A) W1(A). NO!

훼 and 훽 both changes the READ-FROM! So it is not View-Serializable. Remember that I need the local-store to check if it is serializable.

Data Management Notes

3 Transaction management W

Theorem: Conflict-Serializability

A schedule 푆 is conflict-serializable iff the prece- dence graph 푃(푆) associated to 푆 is acyclic. To prove the theorem:

  • we observe that if 푆 is a serial schedule, then the precedence graph 푃(푆) is acyclic (easy to prove)
  • we prove a preliminary lemma

Preliminary Lemma

If two schedule 푆 1 and 푆 2 are conflict-equiv ︸ ︷︷ ︸ 훼

then

훽

Lemma’s Proof

I have to prove that 훼 → 훽, so if I show that 훼∧! 훽 is impossible I’ve done (or! 훽 →! 훼) (or 훼 →! 훽 → ... →! 훼).

  1. I assume 훼
  2. I assume! 훽(푃(푆 1 ) 6 = 푃(푆 2 )). So there is at least one edge that is in 푃(푆 1 ) that does not appear in 푃(푆 2 ) or vice-versa. Remember that an edge appears in the graph if the actions are conflicting.

The green edge appears in 푃(푆 1 ), so 푝푖 (퐴) comes before 푞 (^) 푗 (퐴) because they are conflicting. If this edge does not appear in 푃(푆 2 ) (and remember that the schedules are on the same transactions) then I can assume that 푞 (^) 푗 (퐴) comes before 푝푖 (퐴), negating the assumption on 훼.

Now that the lemma has been proved, we prove the theorem.

Theorem’s Proof

In order to prove the Theorem, in addition to the Lemma’s proof, we need to prove the Exe2 (slide 41) that says: if 푆 is a serial schedule, then the precedence graph 푃(푆) is acyclic. Proof : In a serial schedule on the transaction 푇 1 , ..., 푇푁 , all the actions of each transaction cannot interleave with the action of other transactions. This means that even if there are some conflicting actions from 푇 1 to 푇 2 , the converse is impossible because no action of 푇 2 comes after some action of 푇 2. Theorem’s Proof : Lemma + Exe2: Starting from the definition of conflict-serializable we have demonstrated that if two schedules 푆 1 and 푆 2 are conf-equiv, then 푃(푆 1 ) = 푃(푆 2 ) ︸ ︷︷ ︸ LEMMA

and that

if 푆 is a serial schedule, than 푃(푆) is acyclic ︸ ︷︷ ︸ EXE

Conflict-serializ. says that: A schedule 푆 is conflict-serializable if there exists a serial schedule 푆′^ that is conf.-equiv to it. Let’s suppose we find a serial schedule 푆′^ that is conf-equiv to 푆. (This means that there are no actions 푎푖 of 푇푖 and 푏 (^) 푗 of 푇푗 s.t. 푎푖 and 푏 (^) 푗 are conflicting and the mutual position of the two actions in 푆 1 is different from their mutual position in 푆 2. So, for the first Lemma, 푆 and 푆′^ have the same precedence graph. 푃(푆) = 푃(푆′). And for the Exe2, 푃(푆′) is acyclic. So 푃(푆) too is acyclic.

Data Management Notes

3 Transaction management W

3.3.1 Topological order of a graph

Is a sequence of nodes of 퐺 s.t. if the edge 푇푖 → 푇푗 is in the graph 퐺, then 푇푖 appears before 푇푗 in the sequence 푆. Two propositions:

1 If the graph 퐺 is acyclic, then there exists at least one topological order of 퐺. Algorithm to find it: Pick a node without incoming edges, remove all of its outgoing edges, add the node to the sequence, pick another node and so on.

Apply The Algo

푆 = { 1 , 3 , 2 , 4 } → Top. Order 2 If 푆 is a Top. of 퐺, and there exists a oath from node 푛 1 to node 푛 2 in 퐺, then 푛 1 is before 푛 2 in 푆.

We need to prove the other direction of the Theorem: =⇒ Let 푆 be defined on the transaction 푇 1 , ..., 푇푁. Suppose that 푃(푆) is acyclic. Then, there exists at least one topological order of 푃(푆), i.e. a sequence of its nodes s.t. if 푇푖 → 푇푗 is in 푃(푆), then 푇푖 appears before 푇푗 in the sequence. To such a topological order of 푃(푆), it corresponds the serial schedule 푆′^ on 푇 1 , ..., 푇푁 s.t. if 푇푖 → 푇푗 is in the graph, then all actions of 푇푖 appears immediately before 푇푗 in 푆′. It is easy to see that such a schedule 푆′^ is conflict-equiv. to 푆. Indeed, if 푆′^ is not conf.-equiv. to 푆, then there is a pair of conflicting actions 푎ℎ and 푏푘 s.t. (푎ℎ <푆′^ 푏푘 ) & (푏푘 <푆 푎ℎ ). But (푏푘 <푆 푎ℎ ) means that the path 푇푘 → 푡ℎ is in the graph 푃(푆), and therefore 푇푘 appears before 푇ℎ in every top. order of 푃(푆). However, (푎ℎ <푆′^ 푏푘 ) means that 푇ℎ appears before 푇푘 in 푆′, and this contradicts the fact that 푆′^ corresponds to a top. order of 푃(푆).

3.3.2 Algorithm for Conflict-Serializability

  1. Build the precedence graph 푃(푆) of 푆;
  2. Check if 푃(푆) is acyclic;
  3. Return TRUE if 푃(푆) is acyclic, FALSE otherwise.

Exercise:

Top. Order = {1, 3, 2, 4} Yes, is conflict-serializable.

Data Management Notes

3 Transaction management W

Example:

푇 3 ︷ ︸︸ ︷ 푊 3 (푦) 퐶 3 푊 1 (푥) ︸︷︷︸ 푇 1

푇 2 ︷ ︸︸ ︷ 푅 2 (푥) 퐶 2 푊 1 (푦) 퐶 1 ︸ ︷︷ ︸ 푇 1

푆 ∈ 푂퐶푆푅 because in 푆′^ = { 3 , 2 , 1 } 푇 3 totally precedes 푇 2.

1 2 3

푆 /∈ COCSR because 푇 1 → 푇 2 but 퐶 2 comes before 퐶 1.

3.4 Concurrency control through locks

View-serial is not used ove to the complexity, conf-serial is not used ove to the size of 푃(푆) (it can be made of thousand on nodes!). So, what’s the solution? =⇒ Locks.

  • Lock (Exclusive): 퐼푖 (퐴)
  • Unlock: 푢푖 (퐴)

Rule 1

Every transaction should be well-formed. It’s well-formed if every action 푝푖 (퐴) of 푇푖 is contained in a ”critical section” i.e. in a sequence of actions delimited by a pair on lock-unlock on 퐴.

푇푖 : 퐼푖 (퐴)...푝푖 (퐴)...푢푖 (퐴)

Rule 2

The schedule is legal. 푆 with locks is legal is no transactions in it locks an element 퐴 when a different transaction has granted the lock on 퐴 and has not yet unlocked 퐴.

푆 : ...퐼푖 (퐴) ....... ...... ︸ ︷︷ ︸ No 퐼푗 (퐴)

The schedule manages the so called Lock Table, which contains all the requests coming from other transactions on an object 퐴 while 퐴 is locked by another transaction. Otherwise, if the Schedules would grant the lock on 퐴 while 퐴 is locked, the schedule become illegal. The scheduler ensures that the schedule remains well-formed too.

Are the locks sufficient for serializability? → No, isolation is not ensured (ghost update could appear for example). Solution: 2PL.

Data Management Notes

3 Transaction management W

3.4.1 Two Phase Locking

A schedule 푆 follow the 2PL protocol if each 푇푖 ∈ 푆, all lock operations precede all unlock operations.

푆 : ................ ︸ ︷︷ ︸ No unlock for 푇푖

No lock for 푇푖

This creates a plan divided in two sections over time:

But while 2PL avoid ghost update, it can happen that a deadlock appears.

3.4.2 Exercises

Exercise: 푟 1 (푥) 푤 2 (푥) 푤 3 (푦) 푤 1 (푧) 푤 3 (푧) follows 2PL protocol?

  • I have to be sure that I can add lock and unlock;
  • The sequence will start with

푙 = Lock 푤 = write 푢 = unlock

푙 1 (푥) 푟 1 (푥) 푙 2 (푧) 푢 1 (푥) 푙 2 (푥) 푤 2 (푥) 푢 2 (푥) 푙 3 (푦) 푤 3 (푦) 푤 1 (푧) 푢 1 (푧) 푙 3 (푧) 푤 3 (푧) 푢 3 (푦) 푢 3 (푧)

If to the sequence above we remove the lock and unlock operation, we obtain 푟 1 (푥) 푤 2 (푥) 푤 3 (푦) 푤 1 (푧) 푤 3 (푧) that is equal to the input =⇒ Is 2PL Schedule.

Important Notes

  • Schedule is in 2PL class if the scheduler produce as output the same sequence of the input
  • 2PL implies well-formed because in 2PL we assume that every transaction is well-formed

Exercise: 푟 1 (푥) 푤 2 (푥) 푤 3 (푦) 푤 3 (푧) 푤 1 (푧)

푙 1 (푥) 푟 1 (푥) ︸ ︷︷ ︸ 푇 1

푇 2 waits

푇 3

푇 2 continues

Sequence of output actions: 푆′ 2 : 푟 1 (푥) 푤 3 (푦) 푤 3 (푧) 푤 1 (푧) 푤 2 (푥) 6 = 푟 1 (푥) 푤 2 (푥) 푤 3 (푦) 푤 3 (푧) 푤 1 (푧) =⇒ Not in 2PL Class.

Data Management Notes

3 Transaction management W

  • Else, 푇푖 killed.

1 푆 suffers from deadlock −→ 푆 ∈ 2PL. TRUE 2 푆 does not suffer deadlock −→ 푆 ∈2PL. FALSE

3.5 Recoverability of Transactions

We never considered the rollback in the transactions. The notions of serializability that we have considered are not strong enough to guarantee ACID. This is because a new anomaly called ”Dirty-Read”. 푇 1 푇 2 BEGIN BEGIN 푅푒푎푑(퐴, 푥) 푥 = 푥 + 1 푊푟푖푡푒(퐴, 푥) 푅푒푎푑(퐴, 푥) 푥 = 푥 + 1 Rollback 푊푟푖푡푒(퐴, 푥) Commit

Problem: 푇 2 reads a value written by 푇 1 before 푇 1 commits or rollbacks. There- fore, 푇 2 reads a value that is not supposed to be there → Dirty Value!

3.5.1 Cascading Rollback

A rollback of a transaction 푇푖 can trigger the rollback if other transactions. If a transaction 푇푗 read from 푇푖 , we should kill 푇푗 (푇푗 should rollback). If 푇ℎ has read from 푇푗 it should be killed and so on.

3.5.2 Recoverable Schedules

A schedule 푆 is recoverable if no transaction is no transaction in 푆 commits before all other transactions it has ”READ-FROM”, commit.

Recoverability =⇒ No Dirty Reads

Example of recoverable schedule: 푆 : 푤 1 (퐴) 푤 1 (퐵) 푤 2 (퐴) 푟 2 (퐵) 푐 1 푐 2

In this case 푇 2 commit after 푇 1 =⇒ Recoverable.

Example of NON recoverable schedule: 푆 : 푤 1 (퐴) 푤 1 (퐵) 푤 2 (퐴) 푟 2 (퐵) 푟 3 (퐴) 푐 1 푐 3 푐 2

In this case 푇 2 reads from 푇 1 and 푇 3 reads from 푇 1 =⇒ 푇 3 commits after 푇 1 =⇒ Not recoverable.

Beware that recoverable schedules can still suffer from the cascading rollback!

Data Management Notes

3 Transaction management W

3.5.3 ACR

A schedule 푆 avoids cascading rollback if every trans. in 푆 read value that are written by transactions that have already committed. Example:

푆 = 푤 2 (퐴) 푤 1 (퐵) 푤 1 (퐴) 푐 1 푟 2 (퐵) 푐 2 → ACR blocks the dirty-read!

3.5.4 Strict Schedules

In a schedule 푆, a transaction 푇푖 writes on 푇푗 if there is a 푤 (^) 푗 (퐴) in 푆 followed by 푤푖 (퐴), and there is no write action on 퐴 in 푆 between these two actions. A schedule 푆 is strict if every transaction reads only values written by transactions that have already committed, and writes only on transactions that have already committed. String → ACR → Recoverable.

3.5.5 Rigorous Schedules

A schedule 푆 is rigorous if for each pair of conflicting actions 푎푖 and 푏 (^) 푗 appearing in 푆, with 푎푖 appearing before 푏 (^) 푗 , the commit command 푐푖 of 푇푖 appears in 푆 between 푎푖 and 푏 (^) 푗.

Rigorous → Strict → ACR → Recoverable.

Prove that every Rigorous Schedules is Serializable

We have a schedule 푆 and a serial schedule 푆′^ coherent with the sequence and the order of the commits of the transactions. 푇 1 푐 1 푇 2 푐 2 푇 3 푐 3 ...푇푁 푐푁. Goal: show that 푆′^ in conf. equiv. to 푆. Suppose that is not true: we have a pair of conflicting actions that appear in different order in the two schedules. 푆 : ...푎푖 ...푏 (^) 푗 ...; 푆′^ : ...푏 (^) 푗 ...푎푖 .... If 푆 is rigorous (our assumption) then, by definition, since 푎푖 and 푏 (^) 푗 are conflicting, we have a commit action in the middle: 푆 : ...푎푖 푐푖 ...푏 (^) 푗 푐 (^) 푗 .... But if we assume that 푆′^ has that configuration shown above, it means that 푇푗 comes before 푇푖. But this is impossible because we have defined 푆′^ to be the serial schedule that is coherent on the commits order. So , 푆′^ conf. equiv. to 푆, therefore 푆 = conf.-serializable → 푆 is serializable.

3.6 Recoverability and 2PL

A schedule S is said to be in the strict 2PL class if

  • 푆 is in 2PL, and
  • 푆 is strict.

3.6.1 Strict 2PL Protocol

A schedule 푆 follow the strict 2PL protocol if it follows the 2PL protocol, and all exclusive locks of every transaction 푇 are kept by 푇 until 푇 commits or rollbacks. (Every schedule following 푆 2 푃퐿 → Strict).

  • Every schedule following the strict 2PL protocol is strict;
  • Every schedule following the strict 2PL protocol is serializable.

3.6.2 Strong Strict 2PL Protocol

A schedule 푆 follows the Strong Strict 2PL Protocol if it follows 2PL protocol, and all locks of every transaction 푇 are kept by 푇 until 푇 commits or rollbacks. (Every schedule following SS2PL → Rigorous).

Data Management Notes