concurrency control
the process of managing simultaneous operations on the database without having them interfere with one another
concurrency control prevents
interference when two or more users are accessing database simultaneously and at least one is updating data
although two transactions may be correct in themselves,
interleaving of operations may produce an incorrect result
three examples of potential problems caused by concurrency
lost updates, uncommitted data, inconsistent retrievals
lost update problem
occurs when a successfully completed update is overwritten by another transaction
uncommitted data problem
occurs when one transaction accesses the intermediate results of another transaction before they are committed, and the second transaction is then rolled back
lost update example
T1 withdraws $10 from 100
T2 deposits 100 into same account
incorrectly overlapping transactions may lead to final balance of $90, with T2’s update being lost
inconsistent retrievals problem
occurs when a transaction reads several values, but a different transaction updates some of them in the midst of this process
inconsistent retrievals example
T6 is totaling 3 account balances. T5 is also transferring $10 from acc x to acc z after x is totaled but before z is, so T6 has a result that is $10 too high
serializable schedule
a schedule of a transaction’s operations in which the interleaved execution of all active transactions yields the same results as if those transactions were executed in serial order
because waiting for one transaction to finish before starting any others may be inefficient, the built-in scheduler ensures
efficient use of the DBMS and CPU by interleaving operations when possible. if transactions access unrelated data, there is no conflict among their operations
methods for scheduling conflicting operations in concurrent transactions
locking methods, timestamping
lock granularity
refers to the size of the locked resource
scale for size of locked resource
database-level -> table-level -> page-level -> row-level
database-level means ______, while row-level means ______
slow data access, significant overhead
an exclusive lock
prohibits other users from reading the locked resource
a shared lock
allows other users to read the locked resource, but they cannot update it
optimistic locking assumes that
no transaction conflicts will occur
with optimistic locking, DBMS processes
a transaction to a temporary file and checks whether conflict occurred. if not, transaction finished. if so, the transaction is repeated until there is not conflict.
optimistic locking is acceptable for applications with
few update operations
pessimistic locking assumes that
conflicts will occur
with pessimistic locking, locks are issued
before a transaction is processed, and then the locks are released
two-phase locking (2PL)
guarantees serializability
T/F: 2PL is one of the most common techniques used to achieve serializability
true