SlideShare a Scribd company logo
1 of 46
CMPG321
Advanced Databases
Admin & Information
(Monday 24 July 2023)
Lecturers
Vanderbijlpark Campus (VC)
Lecturer: Dr. Jaco Pretorius
Position: Lecturer and Subject Coordinator
Email: Jaco.Pretorius@nwu.ac.za
Telephone +27 16 910 4985
Building and Office: Building 8 - G35
Consultation Hours: Please see availability, per appointment
Potchefstroom Campus (PC)
Lecturer: Mr. Henri van Rensburg
Position: Lecturer
Email: Henri.vanRensburg@nwu.ac.za
Telephone +27 18 299 4275
Building and Office: Building G3 - G22
Consultation Hours: Please see availability, per appointment
Contact & Consultation
• Emails: any time during the week
• In person: after class /
during cosultation time (in office) /
per appointment
• Online: per appointment
• Module support: Mr. Given Mnisi
(givenmnisi6@gmail.com) and
•
Mr. Lesetja Mojapelo
(lesetjamojapelo@yahoo.com)
CMPG321
• Handboek / Textbook
• Database Systems, 13th Ed
- Design, Implementation and Management
• Author: Coronel, C., Morris, S.
• Any additional resources / material will be announced on
eFundi
CMPG321
• eFundi (http://efundi.nwu.ac.za)
• Elektroniese leeromgewing / Electronic learning environment
• Kennisgewings / Announcements
• Opdragte ontvang en indien / Assignments receive and submit
• Hulpbronne / Resources
• Studiegids as struktuur /
Study guide as structure
* Maak seker dat jy eFundi gereeld besoek! /
* Ensure you visit eFundi regularly!
CMPG321 - PC Timetable / Roster
1
07:30-9:15
2
9:30-10:45
3
11:00-12:45
4
13:00-14:15
5
14:30-15:45
6
16:00-17:45
Monday
CMPG321
E8-G01
Tuesday
Wednesday
CMPG321
E8-G37
(not used / optional)
CMPG321
E8-G01
Thursday
Friday
CMPG321
E8-G37
(not used / optional)
General Admin
• Resources on eFundi, general & additional
• Classes:
• Generally one contact class per week
• Please feel free to join the online class on Wednesdays /
watch the class recording afterwards
• If you don’t have access to eFundi, stay after class
• Class representative – ??? (email?)
• SQL Environment? Oracle, MySQL
CMPG321 –
ADVANCED DATABASES
Study Unit 1
(DS - Chapter 10)
Fakulteit Natuur- en Landbouwetenskappe
Faculty of Natural- and Agricultural Sciences
SU1 - Outcomes
Transaction management and concurrency control
• Discuss database transactions and their properties;
• Determine what concurrency control is and what role it plays in
maintaining the database's integrity;
• Illustrate what locking methods are and how they work;
• Describe how stamping methods are used for concurrency control;
• Describe how optimistic methods are used for concurrency control; and
• Discuss how database recovery management is used to maintain
database integrity.
Chapter 10
Transaction Management and Concurrency
Control
11
TRANSACTIONS:
SQL statements:
UPDATE ; DELETE
COMMIT ; ROLLBACK
12
What is a Transaction?
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permittedin a license distributedwith a certain product or service or otherwise on a password-protected website for classroom use.
13
Initial state
Update Transaction
Final state <Consistent state>
<Modifies database>
<Consistent state>
PROD_QOH = 200
PROD_QOH = PROD_QOH - 12
PROD_QOH = 188
Table: PRODUCT Field: PROD_QOH Initial value: 200
The product: Product update
14
Transactions
▪ Consider the following situation.
Sam is transferring R100 from his bank account to his
friend Jim’s.
– Sam’s account should be reduced by 100.
– Jim’s account should be increased by 100.
What should happen logically?
15
Transactions
▪ Consider the following situation.
Sam is transferring R100 from his bank account to his
friend Jim’s.
– Sam’s account should be reduced by 100.
– Jim’s account should be increased by 100.
16
Sam’s account should be reduced by 100.
Q1. Which of the following SQL statements is
correct for the above operation? Assume Sam’s
account number is ‘123’.
A. UPDATE account
SET balance = balance – 100;
B. UPDATE account
SET balance= balance – 100
WHERE acc_no = '123';
C. UPDATE account
SET acc_no = balance + 100;
D. UPDATE account
SET balance = balance + 100
WHERE acc_no = '123';
17
UPDATE
▪ Changes the value of existing data.
▪ For example, at the end of semester, change the
mark and grade from null to the actual mark and
grade.
UPDATE table
SET column = (subquery) [, column = value, ...]
[WHERE condition];
UPDATE enrolment
SET mark = 80,
grade =‘Distinction'
WHERE sno = 12345678
and ……
UPDATE enrolment
SET mark = 85
WHERE unit_code = (SELECT unit_code FROM unit WHERE
unit_name=‘Advanced Databases')
AND mark = 80;
18
DELETE
• Removing data from the database
DELETE FROM table
[WHERE condition];
DELETE FROM enrolment
WHERE sno=‘12345678'
AND
unit_code= (SELECT unit_code
FROM unit
WHERE unit_name='Introduction to Databases' )
AND
semester='1'
AND
year=‘2022';
19
Assume that Jim’s account number is '333'. The transfer of
money from Sam’s to Jim’s account will be written as the
following SQL transaction:
UPDATE account
SET balance= balance – 100
WHERE acc_no = '123';
UPDATE account
SET balance= balance + 100
WHERE acc_no = '333';
COMMIT;
SQL
statements
T
R
A
N
S
A
C
T
I
O
N
All statements need to be run as a single logical
unit operation.
20
What is a Transaction?
• A logical unit of work that must be entirely completed or aborted
• Consists of:
- SELECT statement
- Series of related UPDATE statements
- Series of INSERT statements
- Combination of SELECT, UPDATE, and INSERT statements
• Consistent database state: All data integrity constraints are satisfied
• Must begin with the database in a known consistent state to ensure consistency
• Most are formed by two or more database requests
• Database requests: equivalent of a single SQL statement in an application program or
transaction
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permittedin a license distributedwith a certain product or service or otherwise on a password-protected website for classroom use.
21
Evaluating Transaction Results
• Not all transactions update the database
• SQL code represents a transaction because it accesses the database
• Improper or incomplete transactions can have devastating effect on database
integrity
• Users can define enforceable constraints based on business rules
• Other integrity rules are automatically enforced by the DBMS
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permittedin a license distributedwith a certain product or service or otherwise on a password-protected website for classroom use.
22
Transaction Properties
▪ A transaction must have the following properties:
– Atomicity
• all database operations (SQL requests) of a transaction must
be entirely completed or entirely aborted
– Consistency
• it must take the database from one consistent state to another
– Isolation
• it must not interfere with other concurrent transactions
• data used during execution of a transaction cannot be used
by a second transaction until the first one is completed
– Durability
• once completed the changes the transaction made to the data
are durable, even in the event of system failure
▪ Serializability
– Ensures that the schedule for the concurrent execution of several
transactions should yield consistent results
23
Transaction Properties
• Atomicity
• All operations of a transaction must be completed; if not the transaction is aborted
• Consistency
• Permanence of database’s consistent state
• Isolation
• Data used during transaction cannot be used by second transaction until the first is
completed
• Durability
• Ensures that once transactions are committed they cannot be undone or lost
Serializability
• Ensures that the schedule for the concurrent execution of several transactions should
yield consistent results
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permittedin a license distributedwith a certain product or service or otherwise on a password-protected website for classroom use.
24
Q2. According to the atomicity property, the
transaction below is complete when statement
number _____ is completed.
UPDATE account
SET balance= balance – 100
WHERE acc_no = '123';
UPDATE account
SET balance= balance + 100
WHERE acc_no = '333';
COMMIT;
A. 1
B. 2
C. 3
D. None of the above.
1
2
3
25
Q3. Which transaction property is violated when a
transaction T2 (Jim checking the account balance)
is allowed to read the balance of Jim’s account
while the transaction T1 (the money transfer from
Sam’s to Jim’s) has not been completed?
A. Atomicity.
B. Isolation.
C. Consistency.
D. Durability.
26
Consistency - Example
▪ Assume that the server lost its power during the execution
of the money transfer transaction, only the first statement is
completed (taking the balance from Sam’s).
▪ Consistency properties ensure that Sam’s account will be
reset to the original balance because the money has not be
transferred to Jim’s account.
▪ ? - The last consistent state is when the money transfer
transaction has not been started.
27
Durability - Example
▪ Assume the server lost power after the commit statement
has been reached.
▪ The durability property ensures that the balance on both
Sam’s and Jim’s accounts reflect the completed money
transfer transaction.
28
Transaction Management with SQL
• SQL statements that provide transaction support:
• COMMIT
• ROLLBACK
• Transaction sequence must continue until one of four events
occur:
• COMMIT statement is reached
• ROLLBACK statement is reached
• End of program is reached
• Program is abnormally terminated
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permittedin a license distributedwith a certain product or service or otherwise on a password-protected website for classroom use.
29
The Transaction Log
•Keeps track of all transactions that update the database
• DBMS uses the information stored in a log for (a):
-Recovery requirement triggered by a ROLLBACK statement
-Program’s abnormal termination
-System failure
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permittedin a license distributedwith a certain product or service or otherwise on a password-protected website for classroom use.
30
The Transaction Log
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permittedin a license distributedwith a certain product or service or otherwise on a password-protected website for classroom use.
Recap: Transaction Management
DEF: A transaction symbolizes a logical unit of work performed within a
DBMS (or similar system) that must be entirely completed or aborted.
(treated in a coherent and reliable way independent of other
transactions. a Transaction generally represents any change in a
database.)
• Follows the ACID properties.
• Atomicity, Consistency, Isolation, Durability
• Transaction boundaries
• Start
• first SQL statement is executed (eg. Oracle)
• Some systems have a BEGIN WORK type
command
• End
• COMMIT or ROLLBACK
• This week: Concurrency Management Serializability
32
Transaction Properties
▪ A transaction must have the following properties:
– Atomicity
• all database operations (SQL requests) of a transaction must
be entirely completed or entirely aborted
– Consistency
• it must take the database from one consistent state to another
– Isolation
• it must not interfere with other concurrent transactions
• data used during execution of a transaction cannot be used
by a second transaction until the first one is completed
– Durability
• once completed the changes the transaction made to the data
are durable, even in the event of system failure
▪ Serializability
– Ensures that the schedule for the concurrent execution of several
transactions should yield consistent results
•Many of you who
studied Operating
Systems and Parallel
Processing (and similar
units) will notice
similarities with
operating system design
issues/theory.
Versioning??
Serial and Interleaved transactions.
T0 T1
Read(X)
X=X+1
Write(x)
Read(Y)
Y=Y*2
Write(Y)
Read(x)
X=X+2
Write(X)
T0 T1
Read(X)
Read(Y)
Y=Y*2
X=X+1
Write(x)
Write(Y)
Read(x)
X=X+2
Write(X)
Serial Interleaved (non Serial)
Time:
One of the fundamental properties of a Tx is ISOLATION
What will happen if several transaction execute concurrently?
Isolation may no longer be preserved…
Concurrency
Control – all
based on
Serializability
principle
Try to manage/ prevent
• Lost updates
• Uncommitteddata
• Inconsistent retrievals
36
Concurrency Control
• Coordination of the simultaneous transactions execution in a multiuser database system
• Objective: ensures serializability of transactions in a multiuser database environment
• Important because the simultaneous execution of transactions over a shared database can
create several data integrity and consistency problems
• Three main problems are lost updates, uncommitted data, and inconsistent retrievals
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permittedin a license distributedwith a certain product or service or otherwise on a password-protected website for classroom use.
37
Problems in Concurrency Control
• Lost update
• Occurs in two concurrent transactions when:
- Same data element is updated
- One of the updates is lost
• Uncommitted data
• Occurs when:
- Two transactions are executed concurrently
- First transaction is rolled back after the second transaction has already accessed uncommitted data
• Inconsistent retrievals
• Occurs when:
- A transaction accesses data before and after one or more other transactions finish working with such data
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permittedin a license distributedwith a certain product or service or otherwise on a password-protected website for classroom use.
The impact of interleaved transactions: Lost
Updates
39
The Scheduler
• Establishes the order in which the operations are executed within concurrent
transactions
• Interleaves the execution of database operations to ensure serializability and isolation
of transactions
• Bases actions on concurrent control algorithms / methods
• Determines appropriate order
• Creates serialization schedule
• Serializable schedule: interleaved execution of transactions yields the same results as
the serial execution of the transactions
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permittedin a license distributedwith a certain product or service or otherwise on a password-protected website for classroom use.
T0 T1
Read(X)
X=X+1
Write(x)
Read(Y)
Y=Y*2
Write(Y)
Read(x)
X=X+2
Write(X)
Time:
Writing schedules
• In Transaction Management, only the following operations
are considered: Read, Write, Commit, and Abort.
• Therefore, the Serial Schedule below can be written as:
S1: r0(X); w0(X); c0; r1(Y); w1(Y); r1(X); w1(X); c1;
• Note that r means read, w means write, and c means
commit. Other operations are omitted. 0 and 1 indicate the
transaction number.
• If transactions cannot be interleaved, there are two possible correct
schedules: one that has all operations in T0 before all operations in
T1, and a second schedule that has all operations in T1 before all
operations in T0 (these are known as serial schedules).
Serial Schedule 1: [r0(X); w0(X); c0]; [r1(Y); w1(Y); r1(X); w1(X); c1];
Serial Schedule 2: [r1(Y); w1(Y); r1(X); w1(X); c1]; [r0(X); w0(X); c0];
• If transactions can be interleaved, there may be many possible
interleavings (nonserial schedules)
Interleaved Schedule 1:
r0(X); r1(Y); w0(X); w1(Y); r1(X); c0; w1(X); c1;
Interleaved Schedule 2:
r0(X); r1(Y); w1(Y); r1(X); w1(X); c1; w0(X); c0;
“A given interleaved execution of some set of transactions is said to be serializable if and only if it
produces the same result as some serial execution of those same transactions”.
Question:
T0 T1
Read(X)
X=X+1
Write(X)
Read(Y)
Y=Y*2
Write(Y)
Read(X)
X=X+2
Write(X)
Serial
T0 T1
Read(X)
Read(Y)
Y=Y*2
Write(Y)
X=X+1
Write(X)
Read(X)
X=X+2
Write(X)
Interleaved
T0 T1
Read(X)
Read(Y)
Y=Y*2
Write(Y)
Read(X)
X=X+2
X=X+1
Write(X)
Write(X)
Interleaved
Serializability: A property in which the selected order of concurrent tx operations creates the same final database state that
Would have been produced if the tx’s had been excecuted in serial fasion
1) Suppose x = 10 and y = 20 – What is answer to schedule 1, 2 and 3?
2) Which one of 2 or 3 is serializable?
(1) (3)
(2)
“A given interleaved execution of some set of transactions is said to be serializable if and only if it
produces the same result as some serial execution of those same transactions”.
Question:
T0 T1
Read(X)
X=X+1
Write(X)
Read(Y)
Y=Y*2
Write(Y)
Read(X)
X=X+2
Write(X)
Serial
T0 T1
Read(X)
Read(Y)
Y=Y*2
Write(Y)
X=X+1
Write(X)
Read(X)
X=X+2
Write(X)
Interleaved
This is serializable
T0 T1
Read(X)
Read(Y)
Y=Y*2
Write(Y)
Read(X)
X=X+2
X=X+1
Write(X)
Write(X)
Interleaved
This is NOT serializable
Serializability: A property in which the selected order of concurrent tx operations creates the same final database state that
Would have been produced if the tx’s had been excecuted in serial fasion
1) Suppose x = 10 and y = 20 – What is answer to schedule 1, 2 and 3?
2) Which one of 2 or 3 is serializable?
(1) (3)
(2)
Let’s learn to understand serializability
Assume at the start: X = 10, Y = 20 (bold and underline used for clarity)
X=10+1
Y=20*2
X=11+2
X=10+1
Y=20*2 Y=20*2
X=11+2
X=10+1 X=10+2
Finally: X=???
X = 13
Y = 40
X = 13
Y = 40
X = ???
Y = 40
•“A given interleaved execution of some set
of transactions is said to be serializable if
and only if it produces the same result as
some serial execution of those same
transactions”.
•For interleaved schedules, we need to
determine whether the interleaved
schedules are correct, i.e., are serializable.
• “Serializable schedules are equivalent to
a serial schedule of the same
transactions”.
CMPG321
• Homework assignment
• Ensure you can sign onto eFundi and see the
“CMPG321 1-1 V 2023” page
• Go through all the information & resources available on eFundi
• Get the textbook
• Read through Chapter 10 -
Transactions and Concurrency Control
• Next week – Locks??
• Next Class: Monday 31 July @ 11:00

More Related Content

Similar to CMPG321_P_2023-07-24_SU1-CH10.pptx

Chapter 12 transactions and concurrency control
Chapter 12 transactions and concurrency controlChapter 12 transactions and concurrency control
Chapter 12 transactions and concurrency control
AbDul ThaYyal
 
Why & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to queryWhy & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to query
Antonios Chatzipavlis
 

Similar to CMPG321_P_2023-07-24_SU1-CH10.pptx (20)

Chapter 12 transactions and concurrency control
Chapter 12 transactions and concurrency controlChapter 12 transactions and concurrency control
Chapter 12 transactions and concurrency control
 
Tranasaction management
Tranasaction managementTranasaction management
Tranasaction management
 
Transaction Processing
Transaction ProcessingTransaction Processing
Transaction Processing
 
Geek Sync | How to Detect, Analyze, and Minimize SQL Server Blocking and Locking
Geek Sync | How to Detect, Analyze, and Minimize SQL Server Blocking and LockingGeek Sync | How to Detect, Analyze, and Minimize SQL Server Blocking and Locking
Geek Sync | How to Detect, Analyze, and Minimize SQL Server Blocking and Locking
 
Unit 4 dbms
Unit 4 dbmsUnit 4 dbms
Unit 4 dbms
 
Scalability truths and serverless architectures
Scalability truths and serverless architecturesScalability truths and serverless architectures
Scalability truths and serverless architectures
 
Transaction in MYSQL
Transaction in MYSQLTransaction in MYSQL
Transaction in MYSQL
 
MySQL Transactions
MySQL TransactionsMySQL Transactions
MySQL Transactions
 
Database Abstraction Layer and Transaction in Stored procedures
Database Abstraction Layer and Transaction in Stored proceduresDatabase Abstraction Layer and Transaction in Stored procedures
Database Abstraction Layer and Transaction in Stored procedures
 
DALmodule and sp transaction
DALmodule and sp transactionDALmodule and sp transaction
DALmodule and sp transaction
 
IAmLUG presentation: Domino Admin Best Practices - Hunting the Gremlins
IAmLUG presentation: Domino Admin Best Practices - Hunting the GremlinsIAmLUG presentation: Domino Admin Best Practices - Hunting the Gremlins
IAmLUG presentation: Domino Admin Best Practices - Hunting the Gremlins
 
Large Data Management Strategies
Large Data Management StrategiesLarge Data Management Strategies
Large Data Management Strategies
 
Unit iv -Transactions
Unit iv -TransactionsUnit iv -Transactions
Unit iv -Transactions
 
How to create SystemVerilog verification environment?
How to create SystemVerilog verification environment?How to create SystemVerilog verification environment?
How to create SystemVerilog verification environment?
 
Transaction management and concurrency
Transaction management and concurrencyTransaction management and concurrency
Transaction management and concurrency
 
Why & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to queryWhy & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to query
 
How to manage and monitor large sql server estates
How to manage and monitor large sql server estatesHow to manage and monitor large sql server estates
How to manage and monitor large sql server estates
 
E secure transaction project ppt(Design and implementation of e-secure trans...
E secure transaction project  ppt(Design and implementation of e-secure trans...E secure transaction project  ppt(Design and implementation of e-secure trans...
E secure transaction project ppt(Design and implementation of e-secure trans...
 
19.TRANSACTIONs.ppt
19.TRANSACTIONs.ppt19.TRANSACTIONs.ppt
19.TRANSACTIONs.ppt
 
3 transaction
3 transaction3 transaction
3 transaction
 

Recently uploaded

Probability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter LessonsProbability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter Lessons
JoseMangaJr1
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
amitlee9823
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
amitlee9823
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
MarinCaroMartnezBerg
 

Recently uploaded (20)

Probability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter LessonsProbability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter Lessons
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
ELKO dropshipping via API with DroFx.pptx
ELKO dropshipping via API with DroFx.pptxELKO dropshipping via API with DroFx.pptx
ELKO dropshipping via API with DroFx.pptx
 
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfAccredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptx
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptx
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Predicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science ProjectPredicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science Project
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics Program
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interaction
 

CMPG321_P_2023-07-24_SU1-CH10.pptx

  • 1. CMPG321 Advanced Databases Admin & Information (Monday 24 July 2023)
  • 2. Lecturers Vanderbijlpark Campus (VC) Lecturer: Dr. Jaco Pretorius Position: Lecturer and Subject Coordinator Email: Jaco.Pretorius@nwu.ac.za Telephone +27 16 910 4985 Building and Office: Building 8 - G35 Consultation Hours: Please see availability, per appointment Potchefstroom Campus (PC) Lecturer: Mr. Henri van Rensburg Position: Lecturer Email: Henri.vanRensburg@nwu.ac.za Telephone +27 18 299 4275 Building and Office: Building G3 - G22 Consultation Hours: Please see availability, per appointment
  • 3. Contact & Consultation • Emails: any time during the week • In person: after class / during cosultation time (in office) / per appointment • Online: per appointment • Module support: Mr. Given Mnisi (givenmnisi6@gmail.com) and • Mr. Lesetja Mojapelo (lesetjamojapelo@yahoo.com)
  • 4. CMPG321 • Handboek / Textbook • Database Systems, 13th Ed - Design, Implementation and Management • Author: Coronel, C., Morris, S. • Any additional resources / material will be announced on eFundi
  • 5. CMPG321 • eFundi (http://efundi.nwu.ac.za) • Elektroniese leeromgewing / Electronic learning environment • Kennisgewings / Announcements • Opdragte ontvang en indien / Assignments receive and submit • Hulpbronne / Resources • Studiegids as struktuur / Study guide as structure * Maak seker dat jy eFundi gereeld besoek! / * Ensure you visit eFundi regularly!
  • 6. CMPG321 - PC Timetable / Roster 1 07:30-9:15 2 9:30-10:45 3 11:00-12:45 4 13:00-14:15 5 14:30-15:45 6 16:00-17:45 Monday CMPG321 E8-G01 Tuesday Wednesday CMPG321 E8-G37 (not used / optional) CMPG321 E8-G01 Thursday Friday CMPG321 E8-G37 (not used / optional)
  • 7. General Admin • Resources on eFundi, general & additional • Classes: • Generally one contact class per week • Please feel free to join the online class on Wednesdays / watch the class recording afterwards • If you don’t have access to eFundi, stay after class • Class representative – ??? (email?) • SQL Environment? Oracle, MySQL
  • 8. CMPG321 – ADVANCED DATABASES Study Unit 1 (DS - Chapter 10) Fakulteit Natuur- en Landbouwetenskappe Faculty of Natural- and Agricultural Sciences
  • 9. SU1 - Outcomes Transaction management and concurrency control • Discuss database transactions and their properties; • Determine what concurrency control is and what role it plays in maintaining the database's integrity; • Illustrate what locking methods are and how they work; • Describe how stamping methods are used for concurrency control; • Describe how optimistic methods are used for concurrency control; and • Discuss how database recovery management is used to maintain database integrity.
  • 10. Chapter 10 Transaction Management and Concurrency Control
  • 11. 11 TRANSACTIONS: SQL statements: UPDATE ; DELETE COMMIT ; ROLLBACK
  • 12. 12 What is a Transaction? © 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permittedin a license distributedwith a certain product or service or otherwise on a password-protected website for classroom use.
  • 13. 13 Initial state Update Transaction Final state <Consistent state> <Modifies database> <Consistent state> PROD_QOH = 200 PROD_QOH = PROD_QOH - 12 PROD_QOH = 188 Table: PRODUCT Field: PROD_QOH Initial value: 200 The product: Product update
  • 14. 14 Transactions ▪ Consider the following situation. Sam is transferring R100 from his bank account to his friend Jim’s. – Sam’s account should be reduced by 100. – Jim’s account should be increased by 100. What should happen logically?
  • 15. 15 Transactions ▪ Consider the following situation. Sam is transferring R100 from his bank account to his friend Jim’s. – Sam’s account should be reduced by 100. – Jim’s account should be increased by 100.
  • 16. 16 Sam’s account should be reduced by 100. Q1. Which of the following SQL statements is correct for the above operation? Assume Sam’s account number is ‘123’. A. UPDATE account SET balance = balance – 100; B. UPDATE account SET balance= balance – 100 WHERE acc_no = '123'; C. UPDATE account SET acc_no = balance + 100; D. UPDATE account SET balance = balance + 100 WHERE acc_no = '123';
  • 17. 17 UPDATE ▪ Changes the value of existing data. ▪ For example, at the end of semester, change the mark and grade from null to the actual mark and grade. UPDATE table SET column = (subquery) [, column = value, ...] [WHERE condition]; UPDATE enrolment SET mark = 80, grade =‘Distinction' WHERE sno = 12345678 and …… UPDATE enrolment SET mark = 85 WHERE unit_code = (SELECT unit_code FROM unit WHERE unit_name=‘Advanced Databases') AND mark = 80;
  • 18. 18 DELETE • Removing data from the database DELETE FROM table [WHERE condition]; DELETE FROM enrolment WHERE sno=‘12345678' AND unit_code= (SELECT unit_code FROM unit WHERE unit_name='Introduction to Databases' ) AND semester='1' AND year=‘2022';
  • 19. 19 Assume that Jim’s account number is '333'. The transfer of money from Sam’s to Jim’s account will be written as the following SQL transaction: UPDATE account SET balance= balance – 100 WHERE acc_no = '123'; UPDATE account SET balance= balance + 100 WHERE acc_no = '333'; COMMIT; SQL statements T R A N S A C T I O N All statements need to be run as a single logical unit operation.
  • 20. 20 What is a Transaction? • A logical unit of work that must be entirely completed or aborted • Consists of: - SELECT statement - Series of related UPDATE statements - Series of INSERT statements - Combination of SELECT, UPDATE, and INSERT statements • Consistent database state: All data integrity constraints are satisfied • Must begin with the database in a known consistent state to ensure consistency • Most are formed by two or more database requests • Database requests: equivalent of a single SQL statement in an application program or transaction © 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permittedin a license distributedwith a certain product or service or otherwise on a password-protected website for classroom use.
  • 21. 21 Evaluating Transaction Results • Not all transactions update the database • SQL code represents a transaction because it accesses the database • Improper or incomplete transactions can have devastating effect on database integrity • Users can define enforceable constraints based on business rules • Other integrity rules are automatically enforced by the DBMS © 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permittedin a license distributedwith a certain product or service or otherwise on a password-protected website for classroom use.
  • 22. 22 Transaction Properties ▪ A transaction must have the following properties: – Atomicity • all database operations (SQL requests) of a transaction must be entirely completed or entirely aborted – Consistency • it must take the database from one consistent state to another – Isolation • it must not interfere with other concurrent transactions • data used during execution of a transaction cannot be used by a second transaction until the first one is completed – Durability • once completed the changes the transaction made to the data are durable, even in the event of system failure ▪ Serializability – Ensures that the schedule for the concurrent execution of several transactions should yield consistent results
  • 23. 23 Transaction Properties • Atomicity • All operations of a transaction must be completed; if not the transaction is aborted • Consistency • Permanence of database’s consistent state • Isolation • Data used during transaction cannot be used by second transaction until the first is completed • Durability • Ensures that once transactions are committed they cannot be undone or lost Serializability • Ensures that the schedule for the concurrent execution of several transactions should yield consistent results © 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permittedin a license distributedwith a certain product or service or otherwise on a password-protected website for classroom use.
  • 24. 24 Q2. According to the atomicity property, the transaction below is complete when statement number _____ is completed. UPDATE account SET balance= balance – 100 WHERE acc_no = '123'; UPDATE account SET balance= balance + 100 WHERE acc_no = '333'; COMMIT; A. 1 B. 2 C. 3 D. None of the above. 1 2 3
  • 25. 25 Q3. Which transaction property is violated when a transaction T2 (Jim checking the account balance) is allowed to read the balance of Jim’s account while the transaction T1 (the money transfer from Sam’s to Jim’s) has not been completed? A. Atomicity. B. Isolation. C. Consistency. D. Durability.
  • 26. 26 Consistency - Example ▪ Assume that the server lost its power during the execution of the money transfer transaction, only the first statement is completed (taking the balance from Sam’s). ▪ Consistency properties ensure that Sam’s account will be reset to the original balance because the money has not be transferred to Jim’s account. ▪ ? - The last consistent state is when the money transfer transaction has not been started.
  • 27. 27 Durability - Example ▪ Assume the server lost power after the commit statement has been reached. ▪ The durability property ensures that the balance on both Sam’s and Jim’s accounts reflect the completed money transfer transaction.
  • 28. 28 Transaction Management with SQL • SQL statements that provide transaction support: • COMMIT • ROLLBACK • Transaction sequence must continue until one of four events occur: • COMMIT statement is reached • ROLLBACK statement is reached • End of program is reached • Program is abnormally terminated © 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permittedin a license distributedwith a certain product or service or otherwise on a password-protected website for classroom use.
  • 29. 29 The Transaction Log •Keeps track of all transactions that update the database • DBMS uses the information stored in a log for (a): -Recovery requirement triggered by a ROLLBACK statement -Program’s abnormal termination -System failure © 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permittedin a license distributedwith a certain product or service or otherwise on a password-protected website for classroom use.
  • 30. 30 The Transaction Log © 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permittedin a license distributedwith a certain product or service or otherwise on a password-protected website for classroom use.
  • 31. Recap: Transaction Management DEF: A transaction symbolizes a logical unit of work performed within a DBMS (or similar system) that must be entirely completed or aborted. (treated in a coherent and reliable way independent of other transactions. a Transaction generally represents any change in a database.) • Follows the ACID properties. • Atomicity, Consistency, Isolation, Durability • Transaction boundaries • Start • first SQL statement is executed (eg. Oracle) • Some systems have a BEGIN WORK type command • End • COMMIT or ROLLBACK • This week: Concurrency Management Serializability
  • 32. 32 Transaction Properties ▪ A transaction must have the following properties: – Atomicity • all database operations (SQL requests) of a transaction must be entirely completed or entirely aborted – Consistency • it must take the database from one consistent state to another – Isolation • it must not interfere with other concurrent transactions • data used during execution of a transaction cannot be used by a second transaction until the first one is completed – Durability • once completed the changes the transaction made to the data are durable, even in the event of system failure ▪ Serializability – Ensures that the schedule for the concurrent execution of several transactions should yield consistent results
  • 33. •Many of you who studied Operating Systems and Parallel Processing (and similar units) will notice similarities with operating system design issues/theory. Versioning??
  • 34. Serial and Interleaved transactions. T0 T1 Read(X) X=X+1 Write(x) Read(Y) Y=Y*2 Write(Y) Read(x) X=X+2 Write(X) T0 T1 Read(X) Read(Y) Y=Y*2 X=X+1 Write(x) Write(Y) Read(x) X=X+2 Write(X) Serial Interleaved (non Serial) Time: One of the fundamental properties of a Tx is ISOLATION What will happen if several transaction execute concurrently? Isolation may no longer be preserved…
  • 35. Concurrency Control – all based on Serializability principle Try to manage/ prevent • Lost updates • Uncommitteddata • Inconsistent retrievals
  • 36. 36 Concurrency Control • Coordination of the simultaneous transactions execution in a multiuser database system • Objective: ensures serializability of transactions in a multiuser database environment • Important because the simultaneous execution of transactions over a shared database can create several data integrity and consistency problems • Three main problems are lost updates, uncommitted data, and inconsistent retrievals © 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permittedin a license distributedwith a certain product or service or otherwise on a password-protected website for classroom use.
  • 37. 37 Problems in Concurrency Control • Lost update • Occurs in two concurrent transactions when: - Same data element is updated - One of the updates is lost • Uncommitted data • Occurs when: - Two transactions are executed concurrently - First transaction is rolled back after the second transaction has already accessed uncommitted data • Inconsistent retrievals • Occurs when: - A transaction accesses data before and after one or more other transactions finish working with such data © 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permittedin a license distributedwith a certain product or service or otherwise on a password-protected website for classroom use.
  • 38. The impact of interleaved transactions: Lost Updates
  • 39. 39 The Scheduler • Establishes the order in which the operations are executed within concurrent transactions • Interleaves the execution of database operations to ensure serializability and isolation of transactions • Bases actions on concurrent control algorithms / methods • Determines appropriate order • Creates serialization schedule • Serializable schedule: interleaved execution of transactions yields the same results as the serial execution of the transactions © 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permittedin a license distributedwith a certain product or service or otherwise on a password-protected website for classroom use.
  • 40. T0 T1 Read(X) X=X+1 Write(x) Read(Y) Y=Y*2 Write(Y) Read(x) X=X+2 Write(X) Time: Writing schedules • In Transaction Management, only the following operations are considered: Read, Write, Commit, and Abort. • Therefore, the Serial Schedule below can be written as: S1: r0(X); w0(X); c0; r1(Y); w1(Y); r1(X); w1(X); c1; • Note that r means read, w means write, and c means commit. Other operations are omitted. 0 and 1 indicate the transaction number.
  • 41. • If transactions cannot be interleaved, there are two possible correct schedules: one that has all operations in T0 before all operations in T1, and a second schedule that has all operations in T1 before all operations in T0 (these are known as serial schedules). Serial Schedule 1: [r0(X); w0(X); c0]; [r1(Y); w1(Y); r1(X); w1(X); c1]; Serial Schedule 2: [r1(Y); w1(Y); r1(X); w1(X); c1]; [r0(X); w0(X); c0]; • If transactions can be interleaved, there may be many possible interleavings (nonserial schedules) Interleaved Schedule 1: r0(X); r1(Y); w0(X); w1(Y); r1(X); c0; w1(X); c1; Interleaved Schedule 2: r0(X); r1(Y); w1(Y); r1(X); w1(X); c1; w0(X); c0;
  • 42. “A given interleaved execution of some set of transactions is said to be serializable if and only if it produces the same result as some serial execution of those same transactions”. Question: T0 T1 Read(X) X=X+1 Write(X) Read(Y) Y=Y*2 Write(Y) Read(X) X=X+2 Write(X) Serial T0 T1 Read(X) Read(Y) Y=Y*2 Write(Y) X=X+1 Write(X) Read(X) X=X+2 Write(X) Interleaved T0 T1 Read(X) Read(Y) Y=Y*2 Write(Y) Read(X) X=X+2 X=X+1 Write(X) Write(X) Interleaved Serializability: A property in which the selected order of concurrent tx operations creates the same final database state that Would have been produced if the tx’s had been excecuted in serial fasion 1) Suppose x = 10 and y = 20 – What is answer to schedule 1, 2 and 3? 2) Which one of 2 or 3 is serializable? (1) (3) (2)
  • 43. “A given interleaved execution of some set of transactions is said to be serializable if and only if it produces the same result as some serial execution of those same transactions”. Question: T0 T1 Read(X) X=X+1 Write(X) Read(Y) Y=Y*2 Write(Y) Read(X) X=X+2 Write(X) Serial T0 T1 Read(X) Read(Y) Y=Y*2 Write(Y) X=X+1 Write(X) Read(X) X=X+2 Write(X) Interleaved This is serializable T0 T1 Read(X) Read(Y) Y=Y*2 Write(Y) Read(X) X=X+2 X=X+1 Write(X) Write(X) Interleaved This is NOT serializable Serializability: A property in which the selected order of concurrent tx operations creates the same final database state that Would have been produced if the tx’s had been excecuted in serial fasion 1) Suppose x = 10 and y = 20 – What is answer to schedule 1, 2 and 3? 2) Which one of 2 or 3 is serializable? (1) (3) (2)
  • 44. Let’s learn to understand serializability Assume at the start: X = 10, Y = 20 (bold and underline used for clarity) X=10+1 Y=20*2 X=11+2 X=10+1 Y=20*2 Y=20*2 X=11+2 X=10+1 X=10+2 Finally: X=??? X = 13 Y = 40 X = 13 Y = 40 X = ??? Y = 40
  • 45. •“A given interleaved execution of some set of transactions is said to be serializable if and only if it produces the same result as some serial execution of those same transactions”. •For interleaved schedules, we need to determine whether the interleaved schedules are correct, i.e., are serializable. • “Serializable schedules are equivalent to a serial schedule of the same transactions”.
  • 46. CMPG321 • Homework assignment • Ensure you can sign onto eFundi and see the “CMPG321 1-1 V 2023” page • Go through all the information & resources available on eFundi • Get the textbook • Read through Chapter 10 - Transactions and Concurrency Control • Next week – Locks?? • Next Class: Monday 31 July @ 11:00