SlideShare a Scribd company logo
1 of 26
Download to read offline
1
Lecture 08:
Transaction management
overview
www.cl.cam.ac.uk/Teaching/current/Databases/
2
Today’s lecture
• Why do we want concurrent execution of
user programs?
• What properties might we wish for?
• What’s a transaction?
• What are the problems when interleaving
transactions?
• How might we overcome these?
3
Transactions
• Concurrent execution of user programs is
essential for good DBMS performance
– Disk access is frequent and slow 
– Want to keep the CPU busy 
• A user’s program may carry out all sorts of
operations on the data, but the DBMS is
only concerned about what data is read
from/written to the database
4
Transactions cont.
• Thus a transaction is the DBMS’s abstract view
of a user program: a series of reads/writes of
database objects
• Users submit transactions, and can think of each
transaction as executing by itself
– The concurrency is achieved by the DBMS, which
interleaves actions of the various transactions
• Issues:
– Interleaving transactions, and
– Crashes!
5
Goal: The ACID properties
• Atomicity: Either all actions are carried out, or
none are
• Consistency: If each transaction is consistent,
and the database is initially consistent, then it is
left consistent
• Isolation: Transactions are isolated, or
protected, from the effects of other scheduled
transactions
• Durability: If a transactions completes
successfully, then its effects persist
6
AAtomicity
• A transaction can
– Commit after completing its actions, or
– Abort because of
• Internal DBMS decision: restart
• System crash: power, disk failure, …
• Unexpected situation: unable to access disk, data value, …
• A transaction interrupted in the middle could leave the
database inconsistent
• DBMS needs to remove the effects of partial
transactions to ensure atomicity: either all a
transaction’s actions are performed or none
7
AAtomicity cont.
• A DBMS ensures atomicity by undoing
the actions of partial transactions
• To enable this, the DBMS maintains a
record, called a log, of all writes to the
database
• The component of a DBMS responsible for
this is called the recovery manager
8
Consistency
• Users are responsible for ensuring transaction
consistency
– when run to completion against a consistent database instance,
the transaction leaves the database consistent
• For example, consistency criterion that my inter-account-
transfer transaction does not change the total amount of
money in the accounts!
• Database consistency is the property that every
transaction sees a consistent database instance. It
follows from transaction atomicity, isolation and
transaction consistency
Integrity
Constraints!
9
Isolation
• Guarantee that even though transactions may
be interleaved, the net effect is identical to
executing the transactions serially
• For example, if transactions T1 and T2 are
executed concurrently, the net effect is
equivalent to executing
– T1 followed by T2, or
– T2 followed by T1
• NOTE: The DBMS provides no guarantee of
effective order of execution
10
Durability
• DBMS uses the log to ensure durability
• If the system crashed before the changes
made by a completed transaction are
written to disk, the log is used to
remember and restore these changes
when the system is restarted
• Again, this is handled by the recovery
manager
11
Transactions and
schedules
• A transaction is seen by the DBMS as a
series, or list, of actions
– Includes read and write of objects
– We’ll write this as R(o) and W(o) (sometimes
RT(o) and WT(o) )
• For example
T1: [R(a), W(a), R(c), W(c)]
T2: [R(b), W(b)]
• In addition, a transaction should specify as
its final action either commit, or abort
12
Schedules
• A schedule is a list of actions from a set of
transactions
– A well-formed schedule is one where the actions of a
particular transaction T are in the same order as they
appear in T
• For example
– [RT1(a), WT1(a), RT2(b), WT2(b), RT1(c), WT1(c)] is a well-
formed schedule
– [RT1(c), WT1(c), RT2(b), WT2(b), RT1(a), WT1(a)] is not a well-
formed schedule
13
Schedules cont.
• A complete schedule is one that contains
an abort or commit action for every
transaction that occurs in the schedule
• A serial schedule is one where the
actions of different transactions are not
interleaved
14
Serialisability
• A serialisable schedule is a schedule
whose effect on any consistent database
instance is identical to that of some
complete serial schedule
• NOTE:
– All different results assumed to be acceptable
– It’s more complicated when we have
transactions that abort
– We’ll assume that all ‘side-effects’ of a
transaction are written to the database
15
Anomalies with
interleaved execution
• Two actions on the same data object
conflict if at least one of them is a write
• We’ll now consider three ways in which a
schedule involving two consistency-
preserving transactions can leave a
consistent database inconsistent
16
WR conflicts
• Transaction T2 reads a database object
that has been modified by T1 which has
not committed
T1: R(a),W(a), R(b),W(b),C
T2: R(a),W(a),R(b),W(b),C
Debit €100
from a
Credit €100
to b
Read a and b
and add 6%
interest
“Dirty
read”
17
RW conflicts
• Transaction T2 could change the value of an
object that has been read by a transaction T1,
while T1 is still in progress
T1: R(a), R(a), W(a), C
T2: R(a),W(a),C
T1: R(a), W(a),C
T2: R(a), W(a),C A is 4 
Read A (5) Write 5+1=6
Read A (5) Write 5-1=4
“Unrepeatable
Read”
18
WW conflicts
• Transaction T2 could overwrite the value
of an object which has already been
modified by T1, while T1 is still in progress
T1: [W(Britney), W(gmb)] “Set both salaries at £1m”
T2: [W(gmb), W(Britney)] “Set both salaries at $1m”
• But:
T1: W(Britney), W(gmb)
T2: W(gmb), W(Britney)
gmb gets £1m
Britney gets $1m

“Blind
Write”
19
Serialisability and aborts
• Things are more complicated when
transactions can abort
T1:R(a), W(a), AbortAbort
T2: R(a),W(a),R(b),W(b),C
Deduct €100
from a
Add 6% interest
to a and b
Can’t undo T2
It’s committed 
20
Strict two-phase locking
• DBMS enforces the following locking protocol:
– Each transaction must obtain an S (shared) lock
before reading, and an X (exclusive) lock before
writing
– All locks held by a transaction are released when the
transaction completes
– If a transaction holds an X lock on an object, no other
transaction can get a lock (S or X) on that object
• Strict 2PL allows only serialisable schedules
21
More refined locks
• Some updates that seem at first sight to require
a write (X) lock, can be given something weaker
– Example: Consider a seat count object in a flights
database
– There are two transactions that wish to book a flight –
get X lock on seat count
– Does it matter in what order they decrement the
count?
• They are commutative actions!
• Do they need a write lock?
22
Aborting
• If a transaction Ti is aborted, then all actions
must be undone
– Also, if Tj reads object last written by Ti, then Tj must
be aborted!
• Most systems avoid cascading aborts by
releasing locks only at commit time (strict
protocols)
– If Ti writes an object, then Tj can only read this after
Ti finishes
• In order to undo changes, the DBMS maintains a
log which records every write
23
The log
• The following facts are recorded in the log
– “Ti writes an object”: store new and old values
– “Ti commits/aborts”: store just a record
• Log records are chained together by
transaction id, so it’s easy to undo a
specific transaction
• Log is often duplexed and archived on
stable storage (it’s important!)
24
Connection to Normalization
• The more redundancy in a database, the more
locking is required for (update) transactions.
– Extreme case: so much redundancy that all update
transactions are forced to execute serially.
• In general, less redundancy allows for greater
concurrency and greater transaction throughput.
!!! This is what normalization is all about !!!
25
The Fundamental Tradeoff of
Database Performance Tuning
• De-normalized data can often result in
faster query response
• Normalized data leads to better
transaction throughput
What is more important in your database --- query response
or transaction throughput? The answer will vary.
What do the extreme ends of the spectrum look like?
Yes, indexing data can speed up transactions, but this just proves
the point --- an index IS redundant data. General rule of thumb:
indexing will slow down transactions!
26
Summary
You should now understand:
• Transactions and the ACID properties
• Schedules and serialisable schedules
• Potential anomalies with interleaving
• Strict 2-phase locking
• Problems with transactions that can abort
• Logs
Next lecture: OLAP. How to build “read
only” databases by forgetting about
normal forms!

More Related Content

What's hot

Transaction slide
Transaction slideTransaction slide
Transaction slideshawon roy
 
Ch17 introduction to transaction processing concepts and theory
Ch17 introduction to transaction processing concepts and theoryCh17 introduction to transaction processing concepts and theory
Ch17 introduction to transaction processing concepts and theorymeenatchi selvaraj
 
Transactions and Concurrency Control
Transactions and Concurrency ControlTransactions and Concurrency Control
Transactions and Concurrency ControlDilum Bandara
 
Transaction
TransactionTransaction
TransactionAmin Omi
 
Recovery in Multi database Systems
Recovery in Multi database SystemsRecovery in Multi database Systems
Recovery in Multi database SystemsMoutasm Tamimi
 
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...Gyanmanjari Institute Of Technology
 
Optimistic Algorithm and Concurrency Control Algorithm
Optimistic Algorithm and Concurrency Control AlgorithmOptimistic Algorithm and Concurrency Control Algorithm
Optimistic Algorithm and Concurrency Control AlgorithmShounak Katyayan
 
4. concurrency control
4. concurrency control4. concurrency control
4. concurrency controlAbDul ThaYyal
 
Transactions (Distributed computing)
Transactions (Distributed computing)Transactions (Distributed computing)
Transactions (Distributed computing)Sri Prasanna
 
Presentation on Transaction
Presentation on TransactionPresentation on Transaction
Presentation on TransactionRahul Prajapati
 
Chapter 9 introduction to transaction processing
Chapter 9 introduction to transaction processingChapter 9 introduction to transaction processing
Chapter 9 introduction to transaction processingJafar Nesargi
 
Transaction states and properties
Transaction states and propertiesTransaction states and properties
Transaction states and propertiesChetan Mahawar
 
DBMS-chap 2-Concurrency Control
DBMS-chap 2-Concurrency ControlDBMS-chap 2-Concurrency Control
DBMS-chap 2-Concurrency ControlMukesh Tekwani
 

What's hot (20)

Transaction slide
Transaction slideTransaction slide
Transaction slide
 
Ch17 introduction to transaction processing concepts and theory
Ch17 introduction to transaction processing concepts and theoryCh17 introduction to transaction processing concepts and theory
Ch17 introduction to transaction processing concepts and theory
 
Transactions and Concurrency Control
Transactions and Concurrency ControlTransactions and Concurrency Control
Transactions and Concurrency Control
 
Transaction
TransactionTransaction
Transaction
 
Bab8 transaction
Bab8 transactionBab8 transaction
Bab8 transaction
 
Recovery in Multi database Systems
Recovery in Multi database SystemsRecovery in Multi database Systems
Recovery in Multi database Systems
 
Dbms
DbmsDbms
Dbms
 
24904 lecture11
24904 lecture1124904 lecture11
24904 lecture11
 
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...
 
Optimistic Algorithm and Concurrency Control Algorithm
Optimistic Algorithm and Concurrency Control AlgorithmOptimistic Algorithm and Concurrency Control Algorithm
Optimistic Algorithm and Concurrency Control Algorithm
 
Transaction states PPT
Transaction states PPTTransaction states PPT
Transaction states PPT
 
4. concurrency control
4. concurrency control4. concurrency control
4. concurrency control
 
Tybsc cs dbms2 notes
Tybsc cs dbms2 notesTybsc cs dbms2 notes
Tybsc cs dbms2 notes
 
Transactions (Distributed computing)
Transactions (Distributed computing)Transactions (Distributed computing)
Transactions (Distributed computing)
 
Distributed Transaction
Distributed TransactionDistributed Transaction
Distributed Transaction
 
Presentation on Transaction
Presentation on TransactionPresentation on Transaction
Presentation on Transaction
 
Chapter 9 introduction to transaction processing
Chapter 9 introduction to transaction processingChapter 9 introduction to transaction processing
Chapter 9 introduction to transaction processing
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
Transaction states and properties
Transaction states and propertiesTransaction states and properties
Transaction states and properties
 
DBMS-chap 2-Concurrency Control
DBMS-chap 2-Concurrency ControlDBMS-chap 2-Concurrency Control
DBMS-chap 2-Concurrency Control
 

Viewers also liked

Java tutorials
Java tutorialsJava tutorials
Java tutorialssaryu2011
 
Ipv4 tutorial
Ipv4 tutorialIpv4 tutorial
Ipv4 tutorialsaryu2011
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorialsaryu2011
 
Java review00
Java review00Java review00
Java review00saryu2011
 
Ipv6 tutorial
Ipv6 tutorialIpv6 tutorial
Ipv6 tutorialsaryu2011
 
How to Build a Dynamic Social Media Plan
How to Build a Dynamic Social Media PlanHow to Build a Dynamic Social Media Plan
How to Build a Dynamic Social Media PlanPost Planner
 

Viewers also liked (7)

Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
Ipv4 tutorial
Ipv4 tutorialIpv4 tutorial
Ipv4 tutorial
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
Java review00
Java review00Java review00
Java review00
 
Ipv6 tutorial
Ipv6 tutorialIpv6 tutorial
Ipv6 tutorial
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
How to Build a Dynamic Social Media Plan
How to Build a Dynamic Social Media PlanHow to Build a Dynamic Social Media Plan
How to Build a Dynamic Social Media Plan
 

Similar to Lec08

7. transaction mang
7. transaction mang7. transaction mang
7. transaction mangkhoahuy82
 
FALLSEM2023-24_BCSE302L_TH_VL2023240100957_2023-06-21_Reference-Material-I.pptx
FALLSEM2023-24_BCSE302L_TH_VL2023240100957_2023-06-21_Reference-Material-I.pptxFALLSEM2023-24_BCSE302L_TH_VL2023240100957_2023-06-21_Reference-Material-I.pptx
FALLSEM2023-24_BCSE302L_TH_VL2023240100957_2023-06-21_Reference-Material-I.pptxhritikraj888
 
Concepts of Data Base Management Systems
Concepts of Data Base Management SystemsConcepts of Data Base Management Systems
Concepts of Data Base Management SystemsDinesh Devireddy
 
Distributed Database Design and Relational Query Language
Distributed Database Design and Relational Query LanguageDistributed Database Design and Relational Query Language
Distributed Database Design and Relational Query LanguageAAKANKSHA JAIN
 
Dartabase Transaction.pptx
Dartabase Transaction.pptxDartabase Transaction.pptx
Dartabase Transaction.pptxBibus Poudel
 
DBMS_Transaction processing – Schedule –Serializable Schedule – Concurrency C...
DBMS_Transaction processing – Schedule –Serializable Schedule – Concurrency C...DBMS_Transaction processing – Schedule –Serializable Schedule – Concurrency C...
DBMS_Transaction processing – Schedule –Serializable Schedule – Concurrency C...DrThenmozhiKarunanit
 
Unit 4 chapter - 8 Transaction processing Concepts (1).pptx
Unit 4 chapter - 8 Transaction processing Concepts (1).pptxUnit 4 chapter - 8 Transaction processing Concepts (1).pptx
Unit 4 chapter - 8 Transaction processing Concepts (1).pptxKoteswari Kasireddy
 
TRANSACTION MANAGEMENT AND TIME STAMP PROTOCOLS AND BACKUP RECOVERY
TRANSACTION MANAGEMENT AND TIME STAMP PROTOCOLS AND BACKUP RECOVERYTRANSACTION MANAGEMENT AND TIME STAMP PROTOCOLS AND BACKUP RECOVERY
TRANSACTION MANAGEMENT AND TIME STAMP PROTOCOLS AND BACKUP RECOVERYRohit Kumar
 
Chapter-10 Transaction Processing and Error Recovery
Chapter-10 Transaction Processing and Error RecoveryChapter-10 Transaction Processing and Error Recovery
Chapter-10 Transaction Processing and Error RecoveryKunal Anand
 
Transaction Processing Concept
Transaction Processing ConceptTransaction Processing Concept
Transaction Processing ConceptNishant Munjal
 
dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...
dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...
dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...DrCViji
 
Introduction to transaction management
Introduction to transaction managementIntroduction to transaction management
Introduction to transaction managementDr. C.V. Suresh Babu
 
What is Database Backup? The 3 Important Recovery Techniques from transaction...
What is Database Backup? The 3 Important Recovery Techniques from transaction...What is Database Backup? The 3 Important Recovery Techniques from transaction...
What is Database Backup? The 3 Important Recovery Techniques from transaction...Raj vardhan
 

Similar to Lec08 (20)

7. transaction mang
7. transaction mang7. transaction mang
7. transaction mang
 
FALLSEM2023-24_BCSE302L_TH_VL2023240100957_2023-06-21_Reference-Material-I.pptx
FALLSEM2023-24_BCSE302L_TH_VL2023240100957_2023-06-21_Reference-Material-I.pptxFALLSEM2023-24_BCSE302L_TH_VL2023240100957_2023-06-21_Reference-Material-I.pptx
FALLSEM2023-24_BCSE302L_TH_VL2023240100957_2023-06-21_Reference-Material-I.pptx
 
transaction_processing.ppt
transaction_processing.ppttransaction_processing.ppt
transaction_processing.ppt
 
Concepts of Data Base Management Systems
Concepts of Data Base Management SystemsConcepts of Data Base Management Systems
Concepts of Data Base Management Systems
 
Unit 4 dbms
Unit 4 dbmsUnit 4 dbms
Unit 4 dbms
 
Distributed Database Design and Relational Query Language
Distributed Database Design and Relational Query LanguageDistributed Database Design and Relational Query Language
Distributed Database Design and Relational Query Language
 
Transactions
TransactionsTransactions
Transactions
 
Unit 06 dbms
Unit 06 dbmsUnit 06 dbms
Unit 06 dbms
 
Dartabase Transaction.pptx
Dartabase Transaction.pptxDartabase Transaction.pptx
Dartabase Transaction.pptx
 
DBMS_Transaction processing – Schedule –Serializable Schedule – Concurrency C...
DBMS_Transaction processing – Schedule –Serializable Schedule – Concurrency C...DBMS_Transaction processing – Schedule –Serializable Schedule – Concurrency C...
DBMS_Transaction processing – Schedule –Serializable Schedule – Concurrency C...
 
Unit 4 chapter - 8 Transaction processing Concepts (1).pptx
Unit 4 chapter - 8 Transaction processing Concepts (1).pptxUnit 4 chapter - 8 Transaction processing Concepts (1).pptx
Unit 4 chapter - 8 Transaction processing Concepts (1).pptx
 
TRANSACTION MANAGEMENT AND TIME STAMP PROTOCOLS AND BACKUP RECOVERY
TRANSACTION MANAGEMENT AND TIME STAMP PROTOCOLS AND BACKUP RECOVERYTRANSACTION MANAGEMENT AND TIME STAMP PROTOCOLS AND BACKUP RECOVERY
TRANSACTION MANAGEMENT AND TIME STAMP PROTOCOLS AND BACKUP RECOVERY
 
DBMS 4.pdf
DBMS 4.pdfDBMS 4.pdf
DBMS 4.pdf
 
Chapter-10 Transaction Processing and Error Recovery
Chapter-10 Transaction Processing and Error RecoveryChapter-10 Transaction Processing and Error Recovery
Chapter-10 Transaction Processing and Error Recovery
 
Tranasaction management
Tranasaction managementTranasaction management
Tranasaction management
 
Transaction Processing Concept
Transaction Processing ConceptTransaction Processing Concept
Transaction Processing Concept
 
DBMS UNIT IV.pptx
DBMS UNIT IV.pptxDBMS UNIT IV.pptx
DBMS UNIT IV.pptx
 
dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...
dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...
dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...
 
Introduction to transaction management
Introduction to transaction managementIntroduction to transaction management
Introduction to transaction management
 
What is Database Backup? The 3 Important Recovery Techniques from transaction...
What is Database Backup? The 3 Important Recovery Techniques from transaction...What is Database Backup? The 3 Important Recovery Techniques from transaction...
What is Database Backup? The 3 Important Recovery Techniques from transaction...
 

Lec08

  • 2. 2 Today’s lecture • Why do we want concurrent execution of user programs? • What properties might we wish for? • What’s a transaction? • What are the problems when interleaving transactions? • How might we overcome these?
  • 3. 3 Transactions • Concurrent execution of user programs is essential for good DBMS performance – Disk access is frequent and slow  – Want to keep the CPU busy  • A user’s program may carry out all sorts of operations on the data, but the DBMS is only concerned about what data is read from/written to the database
  • 4. 4 Transactions cont. • Thus a transaction is the DBMS’s abstract view of a user program: a series of reads/writes of database objects • Users submit transactions, and can think of each transaction as executing by itself – The concurrency is achieved by the DBMS, which interleaves actions of the various transactions • Issues: – Interleaving transactions, and – Crashes!
  • 5. 5 Goal: The ACID properties • Atomicity: Either all actions are carried out, or none are • Consistency: If each transaction is consistent, and the database is initially consistent, then it is left consistent • Isolation: Transactions are isolated, or protected, from the effects of other scheduled transactions • Durability: If a transactions completes successfully, then its effects persist
  • 6. 6 AAtomicity • A transaction can – Commit after completing its actions, or – Abort because of • Internal DBMS decision: restart • System crash: power, disk failure, … • Unexpected situation: unable to access disk, data value, … • A transaction interrupted in the middle could leave the database inconsistent • DBMS needs to remove the effects of partial transactions to ensure atomicity: either all a transaction’s actions are performed or none
  • 7. 7 AAtomicity cont. • A DBMS ensures atomicity by undoing the actions of partial transactions • To enable this, the DBMS maintains a record, called a log, of all writes to the database • The component of a DBMS responsible for this is called the recovery manager
  • 8. 8 Consistency • Users are responsible for ensuring transaction consistency – when run to completion against a consistent database instance, the transaction leaves the database consistent • For example, consistency criterion that my inter-account- transfer transaction does not change the total amount of money in the accounts! • Database consistency is the property that every transaction sees a consistent database instance. It follows from transaction atomicity, isolation and transaction consistency Integrity Constraints!
  • 9. 9 Isolation • Guarantee that even though transactions may be interleaved, the net effect is identical to executing the transactions serially • For example, if transactions T1 and T2 are executed concurrently, the net effect is equivalent to executing – T1 followed by T2, or – T2 followed by T1 • NOTE: The DBMS provides no guarantee of effective order of execution
  • 10. 10 Durability • DBMS uses the log to ensure durability • If the system crashed before the changes made by a completed transaction are written to disk, the log is used to remember and restore these changes when the system is restarted • Again, this is handled by the recovery manager
  • 11. 11 Transactions and schedules • A transaction is seen by the DBMS as a series, or list, of actions – Includes read and write of objects – We’ll write this as R(o) and W(o) (sometimes RT(o) and WT(o) ) • For example T1: [R(a), W(a), R(c), W(c)] T2: [R(b), W(b)] • In addition, a transaction should specify as its final action either commit, or abort
  • 12. 12 Schedules • A schedule is a list of actions from a set of transactions – A well-formed schedule is one where the actions of a particular transaction T are in the same order as they appear in T • For example – [RT1(a), WT1(a), RT2(b), WT2(b), RT1(c), WT1(c)] is a well- formed schedule – [RT1(c), WT1(c), RT2(b), WT2(b), RT1(a), WT1(a)] is not a well- formed schedule
  • 13. 13 Schedules cont. • A complete schedule is one that contains an abort or commit action for every transaction that occurs in the schedule • A serial schedule is one where the actions of different transactions are not interleaved
  • 14. 14 Serialisability • A serialisable schedule is a schedule whose effect on any consistent database instance is identical to that of some complete serial schedule • NOTE: – All different results assumed to be acceptable – It’s more complicated when we have transactions that abort – We’ll assume that all ‘side-effects’ of a transaction are written to the database
  • 15. 15 Anomalies with interleaved execution • Two actions on the same data object conflict if at least one of them is a write • We’ll now consider three ways in which a schedule involving two consistency- preserving transactions can leave a consistent database inconsistent
  • 16. 16 WR conflicts • Transaction T2 reads a database object that has been modified by T1 which has not committed T1: R(a),W(a), R(b),W(b),C T2: R(a),W(a),R(b),W(b),C Debit €100 from a Credit €100 to b Read a and b and add 6% interest “Dirty read”
  • 17. 17 RW conflicts • Transaction T2 could change the value of an object that has been read by a transaction T1, while T1 is still in progress T1: R(a), R(a), W(a), C T2: R(a),W(a),C T1: R(a), W(a),C T2: R(a), W(a),C A is 4  Read A (5) Write 5+1=6 Read A (5) Write 5-1=4 “Unrepeatable Read”
  • 18. 18 WW conflicts • Transaction T2 could overwrite the value of an object which has already been modified by T1, while T1 is still in progress T1: [W(Britney), W(gmb)] “Set both salaries at £1m” T2: [W(gmb), W(Britney)] “Set both salaries at $1m” • But: T1: W(Britney), W(gmb) T2: W(gmb), W(Britney) gmb gets £1m Britney gets $1m  “Blind Write”
  • 19. 19 Serialisability and aborts • Things are more complicated when transactions can abort T1:R(a), W(a), AbortAbort T2: R(a),W(a),R(b),W(b),C Deduct €100 from a Add 6% interest to a and b Can’t undo T2 It’s committed 
  • 20. 20 Strict two-phase locking • DBMS enforces the following locking protocol: – Each transaction must obtain an S (shared) lock before reading, and an X (exclusive) lock before writing – All locks held by a transaction are released when the transaction completes – If a transaction holds an X lock on an object, no other transaction can get a lock (S or X) on that object • Strict 2PL allows only serialisable schedules
  • 21. 21 More refined locks • Some updates that seem at first sight to require a write (X) lock, can be given something weaker – Example: Consider a seat count object in a flights database – There are two transactions that wish to book a flight – get X lock on seat count – Does it matter in what order they decrement the count? • They are commutative actions! • Do they need a write lock?
  • 22. 22 Aborting • If a transaction Ti is aborted, then all actions must be undone – Also, if Tj reads object last written by Ti, then Tj must be aborted! • Most systems avoid cascading aborts by releasing locks only at commit time (strict protocols) – If Ti writes an object, then Tj can only read this after Ti finishes • In order to undo changes, the DBMS maintains a log which records every write
  • 23. 23 The log • The following facts are recorded in the log – “Ti writes an object”: store new and old values – “Ti commits/aborts”: store just a record • Log records are chained together by transaction id, so it’s easy to undo a specific transaction • Log is often duplexed and archived on stable storage (it’s important!)
  • 24. 24 Connection to Normalization • The more redundancy in a database, the more locking is required for (update) transactions. – Extreme case: so much redundancy that all update transactions are forced to execute serially. • In general, less redundancy allows for greater concurrency and greater transaction throughput. !!! This is what normalization is all about !!!
  • 25. 25 The Fundamental Tradeoff of Database Performance Tuning • De-normalized data can often result in faster query response • Normalized data leads to better transaction throughput What is more important in your database --- query response or transaction throughput? The answer will vary. What do the extreme ends of the spectrum look like? Yes, indexing data can speed up transactions, but this just proves the point --- an index IS redundant data. General rule of thumb: indexing will slow down transactions!
  • 26. 26 Summary You should now understand: • Transactions and the ACID properties • Schedules and serialisable schedules • Potential anomalies with interleaving • Strict 2-phase locking • Problems with transactions that can abort • Logs Next lecture: OLAP. How to build “read only” databases by forgetting about normal forms!