1 / 44

Chapter 13 Managing Transactions and Concurrency

Chapter 13 Managing Transactions and Concurrency. Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition. Objectives. In this chapter, you will learn: About database transactions and their properties

marv
Download Presentation

Chapter 13 Managing Transactions and Concurrency

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 13 Managing Transactions and Concurrency Database Principles: Fundamentals of Design, Implementation, and ManagementTenth Edition

  2. Objectives • In this chapter, you will learn: • About database transactions and their properties • What concurrency control is and what role it plays in maintaining the database’s integrity • What locking methods are and how they work

  3. What Is a Transaction? • Any action that reads from and/or writes to a database may consist of: • Simple SELECT statement to generate list of table contents • Series of related UPDATE statements to change values of attributes in various tables • Series of INSERT statements to add rows to one or more tables • Combination of SELECT, UPDATE, and INSERT statements

  4. What Is a Transaction? • Logical unit of work that must be either entirely completed or aborted • Successful transaction changes database from one consistent state to another • One in which all data integrity constraints are satisfied • Most real-world database transactions are formed by two or more database requests • Equivalent of a single SQL statement in an application program or transaction

  5. Evaluating Transaction Results • Not all transactions update database • SQL code represents a transaction because database was accessed • Improper or incomplete transactions can have devastating effect on database integrity • Some DBMSs provide means by which user can define enforceable constraints • Other integrity rules are enforced automatically by the DBMS

  6. Evaluating Transaction Results Select cust_number, cust_balance From customer Where cust_number=106; COMMIT; Insert into invoice Values( ...) Insert into line Values( ...) Update product Set prod_ qoh=prod_qoh-1 Where prod_code=’89-WRE-Q’; Update customer Set cust_balance=cust_balance+277.55 Where cust_number=106; Insert into acc_transaction Values(...)

  7. Figure 9.2

  8. Transaction Properties • Atomicity • All operations of a transaction must be completed • Consistency • Permanence of database’s consistent state • Isolation • Data used during transaction cannot be used by second transaction until the first is completed

  9. Transaction Properties (cont’d.) • Durability • Once transactions are committed, they cannot be undone • Serializability • Concurrent execution of several transactions yields consistent results • Multiuser databases are subject to multiple concurrent transactions

  10. Joint account ATM ATM Let’s see the following example and Discuss what is wrong with it. Draw 100 balance=500 Deposit 200 Begin Transaction Readbalance from DB B=500 B=500-100=400 Take the Money Writenew balance to DB End Transaction Begin Transaction Read balance from DB B=500 B=500+200=700 Give the Money Writenew balance to DB End Transaction LOST UPDATE PROBLEM

  11. Transaction Management with SQL • ANSI has defined standards that govern SQL database transactions • Transaction support is provided by two SQL statements: COMMIT and ROLLBACK • Transaction sequence must continue until: • COMMIT statement is reached • ROLLBACK statement is reached • End of program is reached • Program is abnormally terminated

  12. The Transaction Log • Transaction log stores: • A record for the beginning of transaction • For each transaction component: • Type of operation being performed (update, delete, insert) • Names of objects affected by transaction • “Before” and “after” values for updated fields • Pointers to previous and next transaction log entries for the same transaction • Ending (COMMIT) of the transaction

  13. Concurrency Control • Coordination of simultaneous transaction execution in a multiprocessing database • Objective is to ensure serializability of transactions in a multiuser environment • Three main problems: • Lost updates • Uncommitted data • Inconsistent retrievals

  14. Lost Updates • Lost update problem: • Two concurrent transactions update same data element • One of the updates is lost • Overwritten by the other transaction

  15. Uncommitted Data • Uncommitted data phenomenon: • Two transactions are executed concurrently • First transaction rolled back after second already accessed uncommitted data

  16. Inconsistent Retrievals • Inconsistent retrievals: • First transaction accesses data • Second transaction alters the data • First transaction accesses the data again • Transaction might read some data before they are changed and other data after changed • Yields inconsistent results

  17. The Scheduler • Special DBMS program • Purpose is to establish order of operations within which concurrent transactions are executed • Interleaves execution of database operations: • Ensures serializability • Ensures isolation • Serializable schedule • Interleaved execution of transactions yields same results as serial execution

  18. Concurrency Controlwith Locking Methods • Lock • Guarantees exclusive use of a data item to a current transaction • Required to prevent another transaction from reading inconsistent data • Pessimistic locking • Use of locks based on the assumption that conflict between transactions is likely • Lock manager • Responsible for assigning and policing the locks used by transactions

  19. Joint account ATM ATM Deposit 200 balance=1000 Draw 100 Begin Transaction Read + Lock balance from DB B=1000 B=1000+200=1200 Give the Money Write +Unlock new balance to DB End Transaction Begin Transaction Wait Wait Wait Wait Read + Lock balance from DB B=1200 B=1200-100=1100 Take the Money Write +Unlock new balance to DBEnd Transaction

  20. Lock Granularity • Indicates level of lock use • Locking can take place at following levels: • Database • Table • Page • Row • Field (attribute)

  21. Lock Granularity (cont’d.) • Database-level lock • Entire database is locked • Table-level lock • Entire table is locked • Page-level lock • Entire diskpage/page is locked

  22. Lock Granularity (cont’d.) • Row-level lock • Allows concurrent transactions to access different rows of same table • Even if rows are located on same page • Field-level lock • Allows concurrent transactions to access same row • Requires use of different fields (attributes) within the row

  23. General Knowledge About Advanced Topics of Database

  24. Business Intelligence (BI) Systems • Business Intelligence (BI) Systems are information systems that assist managers and other professionals: • To analyze current and past activities, and • To predict future events. • Two broad categories: • Reporting • Data mining

  25. Data for BI Systems • BI Systems obtain data in three ways: • From the operational database: • Read and process data only • DO NOT insert, modify or delete operational data! • From extracts from the operational database: • Data is in a BI DBMS • May be a different DBMS than the operations DBMS. • From data purchased from data vendors.

  26. Reporting Applications • Reporting system applications: • Filter • Sort • Group • Make simple calculations • Classify entities (customers, products, students, etc.) • Can be performed using standard SQL • Extensions to SQL are sometimes used • OLAP • Summarize current business status • Compare current business to past or future • Deal with critical report delivery

  27. Data Mining Applications • Data mining applications are used to: • Perform what-if analysis • Make predictions • Facilitate decision making • Data mining applications use sophisticated statistical and mathematical techniques.

  28. Data Storage and Retrieval • Computers and data processing techniques have made possible the high-speed, selective retrieval of large amounts of information for government, commercial, and academic purposes. • There are several basic types of data-storage-and-retrieval systems: • Document-retrieval systems • Database systems • Reference-retrieval systems

  29. Data Storage and Retrieval • Document-retrieval systems • Store entire documents, which are usually retrieved by title or by key words associated with the document. • In some systems, the text of documents is stored as data.

  30. Data Storage and Retrieval • Database systems • Store the information as a series of discrete records that are, in turn, divided into discrete fields (e.g., name, address, and phone number) • Records can be searched and retrieved on the basis of the content of the fields (e.g., all people who have a particular telephone area code). • The data are stored within the computer, either in main storage or auxiliary storage, for ready access. 

  31. Data Storage and Retrieval • Reference-retrieval systems • Store references to documents rather than the documents themselves. • Such systems, in response to a search request, provide the titles of relevant documents and frequently their physical locations. • Such systems are efficient when large amounts of different types of printed data must be stored. • They have proven extremely effective in libraries, where material is constantly changing.

  32. Data Retention • Data retention is a subset of data integrity that specifies criteria for preventing the loss of critical data through updates or deletions. • It considers the future value of data to determine what data should be retained and how they should be retained. • It looks future to determine the unknown or hidden usefulness of data.

  33. Data Retention (cont.) • To ensure data retention: • (Rule) specifies how long data values are retained in a particular database. • (The rule also) specifies what is to be done with data values when their usefulness in that database is over. • (Another rule) specifies how long the data occurrence is retained and what is to be done with that data occurrence when it is no longer useful in the database.

  34. Data Retention (cont.) • Data retention requirement based on business needs may be used in policies for data archiving. • Based on large volumes of data interfering with operations • Need for better protection from modification • Need for isolation of content from changes

More Related