![Page 1: Introduction to Databases - Artificial Intelligenceopenclassroom.stanford.edu/.../TransactionsIntro.pdf · A transaction is a sequence of one or more SQL operations treated as a unit](https://reader035.vdocument.in/reader035/viewer/2022062917/5ed2ed9d82b1917a215e831a/html5/thumbnails/1.jpg)
Jennifer Widom
Transactions
Introduction
![Page 2: Introduction to Databases - Artificial Intelligenceopenclassroom.stanford.edu/.../TransactionsIntro.pdf · A transaction is a sequence of one or more SQL operations treated as a unit](https://reader035.vdocument.in/reader035/viewer/2022062917/5ed2ed9d82b1917a215e831a/html5/thumbnails/2.jpg)
Jennifer Widom
Transactions Motivated by two independent requirements
Concurrent database access
Resilience to system failures
![Page 3: Introduction to Databases - Artificial Intelligenceopenclassroom.stanford.edu/.../TransactionsIntro.pdf · A transaction is a sequence of one or more SQL operations treated as a unit](https://reader035.vdocument.in/reader035/viewer/2022062917/5ed2ed9d82b1917a215e831a/html5/thumbnails/3.jpg)
Jennifer Widom
Concurrent Database Access
DBMS
More software
Even more software Select… Update… Create Table… Drop Index… Help… Delete…
Data
Transactions
![Page 4: Introduction to Databases - Artificial Intelligenceopenclassroom.stanford.edu/.../TransactionsIntro.pdf · A transaction is a sequence of one or more SQL operations treated as a unit](https://reader035.vdocument.in/reader035/viewer/2022062917/5ed2ed9d82b1917a215e831a/html5/thumbnails/4.jpg)
Jennifer Widom
Concurrent Access: Attribute-level Inconsistency
Update College Set enrollment = enrollment + 1000 Where cName = ‘Stanford’
Update College Set enrollment = enrollment + 1500 Where cName = ‘Stanford’
concurrent with …
Transactions
![Page 5: Introduction to Databases - Artificial Intelligenceopenclassroom.stanford.edu/.../TransactionsIntro.pdf · A transaction is a sequence of one or more SQL operations treated as a unit](https://reader035.vdocument.in/reader035/viewer/2022062917/5ed2ed9d82b1917a215e831a/html5/thumbnails/5.jpg)
Jennifer Widom
Concurrent Access: Tuple-level Inconsistency
Update Apply Set major = ‘CS’ Where sID = 123
concurrent with …
Transactions
Update Apply Set decision = ‘Y’ Where sID = 123
![Page 6: Introduction to Databases - Artificial Intelligenceopenclassroom.stanford.edu/.../TransactionsIntro.pdf · A transaction is a sequence of one or more SQL operations treated as a unit](https://reader035.vdocument.in/reader035/viewer/2022062917/5ed2ed9d82b1917a215e831a/html5/thumbnails/6.jpg)
Jennifer Widom
Concurrent Access: Table-level Inconsistency
Update Apply Set decision = ‘Y’ Where sID In (Select sID From Student Where GPA > 3.9)
Update Student Set GPA = (1.1) GPA Where sizeHS > 2500
concurrent with …
Transactions
![Page 7: Introduction to Databases - Artificial Intelligenceopenclassroom.stanford.edu/.../TransactionsIntro.pdf · A transaction is a sequence of one or more SQL operations treated as a unit](https://reader035.vdocument.in/reader035/viewer/2022062917/5ed2ed9d82b1917a215e831a/html5/thumbnails/7.jpg)
Jennifer Widom
Concurrent Access: Multi-statement inconsistency
Insert Into Archive Select * From Apply Where decision = ‘N’;
Delete From Apply Where decision = ‘N’;
Select Count(*) From Apply; Select Count(*) From Archive;
concurrent with …
Transactions
![Page 8: Introduction to Databases - Artificial Intelligenceopenclassroom.stanford.edu/.../TransactionsIntro.pdf · A transaction is a sequence of one or more SQL operations treated as a unit](https://reader035.vdocument.in/reader035/viewer/2022062917/5ed2ed9d82b1917a215e831a/html5/thumbnails/8.jpg)
Jennifer Widom
Transactions Concurrency Goal
Execute sequence of SQL statements so they appear to be running in isolation
Simple solution: execute them in isolation
But want to enable concurrency whenever safe to do so
![Page 9: Introduction to Databases - Artificial Intelligenceopenclassroom.stanford.edu/.../TransactionsIntro.pdf · A transaction is a sequence of one or more SQL operations treated as a unit](https://reader035.vdocument.in/reader035/viewer/2022062917/5ed2ed9d82b1917a215e831a/html5/thumbnails/9.jpg)
Jennifer Widom
Resilience to System Failures
DBMS
Data
Transactions
Bulk Load
![Page 10: Introduction to Databases - Artificial Intelligenceopenclassroom.stanford.edu/.../TransactionsIntro.pdf · A transaction is a sequence of one or more SQL operations treated as a unit](https://reader035.vdocument.in/reader035/viewer/2022062917/5ed2ed9d82b1917a215e831a/html5/thumbnails/10.jpg)
Jennifer Widom
Resilience to System Failures
DBMS
Data
Transactions
Insert Into Archive Select * From Apply Where decision = ‘N’;
Delete From Apply Where decision = ‘N’;
![Page 11: Introduction to Databases - Artificial Intelligenceopenclassroom.stanford.edu/.../TransactionsIntro.pdf · A transaction is a sequence of one or more SQL operations treated as a unit](https://reader035.vdocument.in/reader035/viewer/2022062917/5ed2ed9d82b1917a215e831a/html5/thumbnails/11.jpg)
Jennifer Widom
Resilience to System Failures
DBMS
Data
Transactions
Lots of updates buffered in memory
![Page 12: Introduction to Databases - Artificial Intelligenceopenclassroom.stanford.edu/.../TransactionsIntro.pdf · A transaction is a sequence of one or more SQL operations treated as a unit](https://reader035.vdocument.in/reader035/viewer/2022062917/5ed2ed9d82b1917a215e831a/html5/thumbnails/12.jpg)
Jennifer Widom
Transactions System-Failure Goal
Guarantee all-or-nothing execution, regardless of failures
DBMS
Data
![Page 13: Introduction to Databases - Artificial Intelligenceopenclassroom.stanford.edu/.../TransactionsIntro.pdf · A transaction is a sequence of one or more SQL operations treated as a unit](https://reader035.vdocument.in/reader035/viewer/2022062917/5ed2ed9d82b1917a215e831a/html5/thumbnails/13.jpg)
Jennifer Widom
Transactions Solution for both concurrency and failures
A transaction is a sequence of one or more SQL operations treated as a unit
Transactions appear to run in isolation
If the system fails, each transaction’s changes are reflected either entirely or not at all
Transactions
![Page 14: Introduction to Databases - Artificial Intelligenceopenclassroom.stanford.edu/.../TransactionsIntro.pdf · A transaction is a sequence of one or more SQL operations treated as a unit](https://reader035.vdocument.in/reader035/viewer/2022062917/5ed2ed9d82b1917a215e831a/html5/thumbnails/14.jpg)
Jennifer Widom
Transactions Solution for both concurrency and failures
A transaction is a sequence of one or more SQL operations treated as a unit. SQL standard:
Transaction begins automatically on first SQL statement
On “commit” transaction ends and new one begins
Current transaction ends on session termination
“Autocommit” turns each statement into transaction
Transactions
![Page 15: Introduction to Databases - Artificial Intelligenceopenclassroom.stanford.edu/.../TransactionsIntro.pdf · A transaction is a sequence of one or more SQL operations treated as a unit](https://reader035.vdocument.in/reader035/viewer/2022062917/5ed2ed9d82b1917a215e831a/html5/thumbnails/15.jpg)
Jennifer Widom
Transactions Solution for both concurrency and failures
A transaction is a sequence of one or more SQL operations treated as a unit
Transactions