Give brief answers to the following questions:
- What is a transaction? In what ways is it different from an ordinary program (in a language such as C)?
- Define these terms: atomicity, consistency, isolation, durability, schedule, blind write, dirty read, unrepeatable read, serializable schedule, recoverable schedule, avoidsvcascadingaborts schedule.
- Describe Strict 2PL.
- What is the phantom problem? Can it occur in a database where the set of database objects is fixed and only the values of objects can be changed?
Consider the following actions taken by transaction T1 on database objects X and Y: R(X), W(X),R(Y), W(Y)
- Give an example of another transaction T2 that, if run concurrently to transaction T without some form of concurrency control, could interfere with T1.
- Explain how the use of Strict 2PL would prevent interference between the two transactions.
- Strict 2PL is used in many database systems. Give two reasons for its popularity.
Consider a database with objects X and Y and assume that there are two transactions Tl and T2. Transaction T1 reads objects X and Y and then writes object X. Transaction T2 reads objects X and Y and then writes objects X and Y.
- Give an example schedule with actions of transactions T1 and T2 on objects X and Y that results in a write-read conflict.
- Give an example schedule with actions of transactions T1 and T2 on objects X and Y that results in a read-write conflict.
- Give an example schedule with actions of transactions T1 and T2 on objects X and Y that results in a write-write conflict.
- For each of the three schedules, show that Strict 2PL disallows the schedule.
-
Write-read conflict (Reading uncommited data or Dirty Read) -
T1 R(X)
T1 R(Y)
T1 W(X)
T2 R(X) - Dirty Read
... -
Read-Write Conflict (Unrepeatable reads) -
T1 R(X)
T1 R(Y)
T2 R(X) T2 R(Y)
T1 W(X)
...
Now T2 will get unrepeatable read. -
Write-Write conflict (Overwriitng uncommited data) -
T1 R(X)
T1 R(Y)
T2 R(X)
T1 W(X) - Step 4 T2 R(Y)
T2 W(X) - Write-Write conflict
... -
Write-read conflict - T2 will not get a Shared lock on X, untill T1 commits.
Read-Write Conflict - T1 will not get Exclusive lock on X untill T2 commits.
Write-Write conflict - T1 will not get Exclusive lock on X in Step 4, unitll T2 commits.
We call a transaction that only reads database object a read-only transaction, otherwise the transaction is called a read-write transaction. Give brief answers to the following questions:
- What is lock thrashing and when does it occur?
- What happens to the database system throughput if the number of read-write transactions is increased?
- What happens to the datbase system throughput if the number of read-only transactions is increased?
- Describe three ways of tuning your system to increase transaction throughput.
- Lock thrashing occurs when a large number of active transactions get blocked while competing for locks.
- Number of transactions waiting for locks , increases.
- No impact, multiple transactions can acquire Shared locks simultaneously.
- Throughput can be increased by -
- Lock the smallest size objects possible.
- Reduce the time for which a transaction holds locks.
- Reduce number of hotspots (Objects that are frequently accessed and modified).
Suppose that a DBMS recognizes increment, which increments an integervalued object by 1, and decrement as actions, in addition to reads and writes. A transaction that increments an object need not know the value of the object; increment and decrement are versions of blind writes. In addition to shared and exclusive locks, two special locks are supported: An object must be locked in I mode before incrementing it and locked in D mode before decrementing it. An I lock is compatible with another I or D lock on the same object, but not with S and X locks.
- Illustrate how the use of I and D locks can increase concurrency. (Show a schedule allowed by Strict 2PL that only uses S and X locks. Explain how the use of I and D locks can allow more actions to be interleaved, while continuing to follow Strict 2PL.)
- Informally explain how Strict 2PL guarantees serializability even in the presence of I and D locks. (Identify which pairs of actions conflict, in the sense that their relative order can affect the result, and show that the use of 5, X, I, and D locks according to Strict 2PL orders all conflicting pairs of actions to be the same as the order in some serial schedule.)
- Take the following two transactions as example:
T1: Increment A, Decrement B, Read C;
T2: Increment B, Decrement A, Read C
If using only strict 2PL, all actions are versions of blind writes, they have to obtain exclusive locks on objects. Following strict 2PL, T1 gets an exclusive lock on A, if T2 now gets an exclusive lock on B, there will be a deadlock. Even if T1 is fast enough to have grabbed an exclusive lock on B first, T2 will now be blocked until T1 finishes. This has little concurrency. If I and D locks are used, since I and D are compatible, T1 obtains an I-Lock on A, and a D-Lock on B; T2 can still obtain an I-Lock on B, a D-Lock on A; both transactions can be interleaved to allow maximum concurrency. - The pairs of actions which conflicts are:
RW, WW, WR, IR, IW, DR, DW
We know that strict 2PL orders the first 3 conflicts pairs of actions to be the same as the order in some serial schedule. We can also show that even in the presence of I and D locks, strict 2PL also orders the latter 4 pairs of actions to be the same as the order in some serial schedule. Think of an I (or D)lock under these circumstances as an exclusive lock, since an I(D) lock is not compatible with S and X locks anyway (ie. can’t get a S or X lock if another transaction has an I or D lock). So serializability is guaranteed.
Answer the following questions: SQL supports four isolation-levels and t.wo access-modes, for a total of eight combinations of isolation-level and access-mode. Each combination impiicitly defines a class of transactions; the following questions refer to these eight classes:
- Consider the four SQL isolation levels. Describe which of the plHmomena can occur at each of these isolation levels: dirty read, unrepeatable read, phantom problem.
- For each of the four isolation levels, give examples of transactions that could be run safely at that level. :.3. Why does the access mode of a transaction matter?
Consider the university enrollment database schema: Student(snurn: integer, snarne: string, majoT: string, level: string, age: integer) Class(name: string, meets_at: time, Toom: string, fid"' integer) Enrolled(snum: integer, cname: string) Faculty(fid: integer, fname: string, deptid: integer) The meaning of these relations is straightforward; for example, Enrolled has one record per student-class pair such that the student is enrolled in the class. For each of the following transactions, state the SQL isolation level you would use and explain why you chose it.
- Enroll a student identified by her snum into the class named 'Introduction to Database Systems'.
- Change enrollment for a student identified by her snum from one class to another class,
- Assign a new faculty member identified by his fid to the class with the least number of students.
- For each class, show the number of students enrolled in the class.
Consider the following schema: Suppliers(sid: integer, sname: string, addTess: string) Parts(pid: integer, pname: string, coloT: string) Catalog(sid: integer, pid: integer, cost: real) The Catalog relation lists the prices charged for parts by Suppliers. For each of the following transactions, state the SQL isolation level that you would use and explain why you chose it.
- A transaction that adds a new part to a supplier's catalog.
- A transaction that increases the price that a supplier charges for a part.
- A transaction that determines the total number of items for a given supplier.
- A transaction that shows, for each part, the supplier that supplies the part at the lowest price.
Consider a database with the following schema: Suppliers(sid: integer, sname: string, addTess: string) Parts(pid: integer, pname: string, coloT: string) Catalog( sid: integer, pid: integer, cost: real) The Catalog relation lists the prices charged for parts by Suppliers. Consider three transactions 1'1,1'2, and 1'3; 1'1 always h8.o.'3 SQL isolation level SERIALIZABLE. We first run 1'1 concurrently with 1'2 and then we run 1'1 concurrently with 1'2 but we change the isolation level of 1'2 as specified below. Give a database instance and SQL statements for 1'1 and 1'2 such that result of running 1'2 with the first SQL isolation level is different from running 1'2 with the second SQL isolation level. Also specify the common schedule of 1'1 and 1'2 and explain why the results are different.
- SERIALIZABLE versus REPEATABLE READ.
- REPEATABLE READ versus READ COMMITTED.
- READ COMMITTED versus READ UNCOMMITTED