CH 10 Text
CH 10 Text
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 2
for classroom use.
What is a Transaction?
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 3
for classroom use.
Evaluating Transaction Results
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 4
for classroom use.
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 permitted in a license distributed with a certain product or service or otherwise on a password-protected website 5
for classroom use.
Transaction Management with SQL
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 6
for classroom use.
The Transaction Log
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 7
for classroom use.
Concurrency Control
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 8
for classroom use.
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 permitted in a license distributed with a certain product or service or otherwise on a password-protected website 9
for classroom use.
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
• 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 permitted in a license distributed with a certain product or service or otherwise on a password-protected website 10
for classroom use.
Concurrency Control with Locking Methods
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 11
for classroom use.
Lock Granularity (1 of 5)
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 12
for classroom use.
Lock Granularity (2 of 5)
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 13
for classroom use.
Lock Granularity (3 of 5)
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 14
for classroom use.
Lock Granularity (4 of 5)
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 15
for classroom use.
Lock Granularity (5 of 5)
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 16
for classroom use.
Lock Types (1 of 2)
• Binary lock
• Two states: locked (1) and unlocked (0)
- If an object is locked by a transaction, no other transaction can use that object
- If an object is unlocked, any transaction can lock the object for its use
• Exclusive lock
• Access is reserved for the transaction that locked the object
• Shared lock
• Concurrent transactions are granted read access on the basis of a common lock
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 17
for classroom use.
Lock Types (2 of 2)
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 18
for classroom use.
Two-Phase Locking to Ensure Serializability (1 of 3)
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 19
for classroom use.
Two-Phase Locking to Ensure Serializability (2 of 3)
• Governing rules
• Two transactions cannot have conflicting locks
• No unlock operation can precede a lock operation in the same transaction
• No data are affected until all locks are obtained
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 20
for classroom use.
Two-Phase Locking to Ensure Serializability (3 of 3)
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 21
for classroom use.
Deadlocks
• Occur when two transactions wait indefinitely for each other to unlock data
• Also known as deadly embrace
• Control techniques
• Deadlock prevention
• Deadlock detection
• Deadlock avoidance
• Choice of deadlock control method depends on database environment
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 22
for classroom use.
Concurrency Control with Time Stamping Methods (1 of 2)
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 23
for classroom use.
Concurrency Control with Time Stamping Methods (2 of 2)
• Disadvantages
• Each value stored in the database requires two additional stamp fields
• Increases memory needs
• Increases the database’s processing overhead
• Demands a lot of system resources
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 24
for classroom use.
Wait/Die and Wound/Wait Schemes (1 of 2)
• Wait/die
• A concurrency control scheme in which an older transaction must wait for the
younger transaction to complete and release the locks before requesting the locks
itself
- Otherwise, the newer transaction dies and is rescheduled
• Wound/wait
• A concurrency control scheme in which an older transaction can request the lock,
preempt the younger transaction, and reschedule it
- Otherwise, the newer transaction waits until the older transaction finishes
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 25
for classroom use.
Wait/Die and Wound/Wait Schemes (2 of 2)
Wait/Die and
Wound/Wait
Concurrency Control
Schemes
Transaction Transaction Wait/Die Scheme Wound/Wait Scheme
Requesting Lock Owning Lock
T1 (11548789) T2 (19562545) • T1 waits until T2 is • T1 preempts (rolls back)
completed and T2 T2.
releases its locks. • T2 is rescheduled using
the same time stamp.
T2 (19562545) T1 (11548789) • T2 dies (rolls back). • T2 waits until T1 is
• T2 is rescheduled completed and T1
using the same time releases its locks.
stamp.
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 26
for classroom use.
Concurrency Control with Optimistic Methods (1 of 2)
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 27
for classroom use.
Concurrency Control with Optimistic Methods (2 of 2)
• Read phase
• Transaction:
- Reads the database
- Executes the needed computations
- Makes the updates to a private copy of the database values
• Validation phase
• Transaction is validated to ensure that the changes made will not affect the integrity
and consistency of the database
• Write phase
• Changes are permanently applied to the database
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 28
for classroom use.
ANSI Levels of Transaction Isolation (1 of 2)
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 29
for classroom use.
ANSI Levels of Transaction Isolation (2 of 2)
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 30
for classroom use.
Database Recovery Management
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 31
for classroom use.
Transaction Recovery (1 of 3)
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 32
for classroom use.
Transaction Recovery (2 of 3)
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 33
for classroom use.
Transaction Recovery (3 of 3)
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 34
for classroom use.
Summary (1 of 2)
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 35
for classroom use.
Summary (2 of 2)
• Concurrency control with time stamping methods assigns a unique time stamp
to each transaction and schedules the execution of conflicting transactions in
time stamp order
• Concurrency control with optimistic methods assumes that the majority of
database transactions do not conflict and that transactions are executed
concurrently, using private, temporary copies of the data
• Database recovery restores the database from a given state to a previous
consistent state
© 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website 36
for classroom use.