The Lost Update Problem
The Lost Update Problem
The concurrent processing illustrated in Figure 9-4 poses no problems because the users are processing different data. But suppose that both users want to process Item 100. For example,
Figure 9-3
Need for Transaction Processing
CNum OrderNum Description
CNum OrderNum Description AmtDue 123
AmtDue
1. Add new-order data to
2. Add new-order data to
Total-
Name
Sales Commission Due JONES
Sales Commission Due
3. Insert new ORDER.
(a) Errors Introduced Without Transaction
(continued)
Figure 9-3
Begin Transaction
CUSTOMER
Change CUSTOMER data
CNum OrderNum Description
CNum OrderNum Description AmtDue 123
AmtDue
Change SALESPERSON data
Insert ORDER data
If no errors then Commit Transactions Else
SALESPERSON
Rollback Transaction
Sales Commission Due JONES
Sales Commission Due
(b) Atomic Transaction Prevents Errors
Chapter 9 Managing Multiuser Databases
User A
User B
1. Read item 100.
1. Read item 200.
2. Change item 100.
2. Change item 200.
3. Write item 100.
3. Write item 200.
Order of processing at database server 1. Read item 100 for A.
2. Read item 200 for B. 3. Change item 100 for A.
Figure 9-4
4. Write item 100 for A. 5. Change item 200 for B.
Concurrent-Processing
6. Write item 200 for B.
Example
User A wants to order five units of Item 100, and User B wants to order three units of the same item. Figure 9-5 illustrates the problem.
User A reads a copy of Item 100’s record into memory. According to the record, there are
10 items in inventory. Then User B reads another copy of Item 100’s record into a different section of memory. Again, according to the record, there are 10 items in inventory. Now User A takes five, decrements the count of items in its copy of the data to five, and rewrites the record for Item 100. Then User B takes three, decrements the count in its copy of the data to seven, and rewrites the record for Item 100. The database now shows, incorrectly, that there are seven Item 100s in inventory. To review: We started with 10 in inventory, User A took 5, User B took 3, and the database shows that 7 are in inventory. Clearly, this is a problem.
Both users obtained data that were correct at the time they obtained them. But when User B read the record, User A already had a copy that it was about to update. This situation is called the lost update problem, or the concurrent update problem. A similar problem is the inconsistent read problem. With this problem, User A reads data that have been processed by a portion of a transaction from User B. As a result, User A reads incorrect data.
One remedy for the inconsistencies caused by concurrent processing is to prevent multiple applications from obtaining copies of the same record when the record is about to be changed. This remedy is called resource locking.
Figure 9-5
User B Lost Update Problem
User A
1. Read item 100
1. Read item 100
(item count is 10).
(item count is 10).
2. Reduce count of items by 5.
2. Reduce count of items by 3.
3. Write item 100.
3. Write item 100.
Order of processing at database server 1. Read item 100 (for A).
2. Read item 100 (for B). 3. Set item count to 5 (for A). 4. Write item 100 for A. 5. Set item count to 7 (for B). 6. Write item 100 for B.
Note: The change and write in steps 3 and 4 are lost.
Part 4 Multiuser Database Processing
Parts
» This page intentionally left blank
» Reporting and Data Mining Database Applications
» Database Applications and SQL
» Reading Specified Columns and Rows from a Single Table
» “Does Not Work with Microsoft Access ANSI-89 SQL”
» Processing SQL Statements in Microsoft Access 2010
» Using SQL in Microsoft SQL Server 2008 R2
» Using SQL in Oracle Database 11g
» Using SQL in Oracle MySQL 5.5
» Wildcards in SQL WHERE Clauses
» Using SQL Built-in Functions
» SQL Expressions in SQL SELECT Statements
» Querying Multiple Tables with Subqueries
» Querying Multiple Tables with Joins
» Comparing Subqueries and Joins
» Finding Functional Dependencies
» Eliminating Anomalies from Multivalued Dependencies
» The Multivalue, Multicolumn Problem
» The General-Purpose Remarks Column
» R Diagrams Using the IE Crow’s Foot Model
» The Multivalued Attribute Pattern
» The Archetype/Instance Pattern
» The Student Acceptance Letter
» X This is a warning, no further action is required.
» 1:1 Relationships Between Strong Entities
» M Relationships Between Strong Entities
» Relationships in Mixed Entity Designs
» Representing Ternary and Higher-Order Relationships
» Relational Representation of the Highline University Data Model
» Surrogate Key Database Design
» Column Properties for the View Ridge Database Design Tables
» Variations in SQL Data Types
» Implementing Data Constraints
» Populating the View Ridge Database Tables
» Using Triggers to Provide Default Values
» The WORK_AddWorkTransaction Stored Procedure
» • If a PROJECT row is deleted, then the project has been canceled, and it is unneces-
» Reducing Cardinalities (with Data Loss)
» Optimistic Versus Pessimistic Locking
» Declaring Lock Characteristics
» Processing Rights and Responsibilities
» Recovery via Rollback/Rollforward
» Maintaining the Data Repository
» Types of Distributed Databases
» • Express Edition. This free, feature-limited version is available for download. It
» SQL Server 2008 R2 SQL Statements and SQL Scripts
» Creating the View Ridge Database Table Structure
» Populating the VRG Tables with Data
» The Stored Procedure InsertCustomerAndInterests
» The Stored Procedure InsertCustomerWithTransaction
» A Trigger for Setting Default Values
» A Trigger for Enforcing a Data Constraint
» A Trigger for Enforcing a Required Child Constraint
» Creating an ODBC Data Source Name
» Materializing XML Documents with XSLT
» Using the SQL SELECT . . . FOR XML Statement
» Multitable SELECT with FOR XML
» A Schema with Two Multivalued Paths
» Problems with Operational Data
» Using SQL for Market Basket Analysis
Show more