Presentation is loading. Please wait.

Presentation is loading. Please wait.

Answers to Midterm - Exam. Feb. 27, 2006

Similar presentations


Presentation on theme: "Answers to Midterm - Exam. Feb. 27, 2006"— Presentation transcript:

1 Answers to Midterm - Exam. Feb. 27, 2006
1.(20) Apply the quick sorting algorithm to the following sequence: 1, 10, 9, 8, 5, 7, 6, 2, 4, 3, and trace the sequence change step by step. 12/3/2019

2 The center element is 5. j i i = j = 5 main idea:
1st step: 2nd step: 3rd step: 4rd step: from center to 10 3 i j 9 4 8 2 i = j = 5 Smaller than 5 greater than 5 12/3/2019

3 8 2 i = 3 j = 2 5th step: 1 4 5 7 6 9 9 10 3 6th step: 1 2 3 4 from
center to 5th step: 6th step: from center to 8 3 2 i = 3 j = 2 12/3/2019

4 center 7th step: from to i = 1 j = 1 8th step: 12/3/2019

5 (b) When the system crashes as shown in Fig. 1, how do we undo
2.(20) (a) Tell the difference between commit points and checking points. (10) (b) When the system crashes as shown in Fig. 1, how do we undo or redo the transactions? Here, we assume that all these transactions are not interferenced and at a checking point all the made by the transactions will be stored in the database. (10) Time T1 T2 T3 T4 T5 Time of checkpoint failure Fig. 1 12/3/2019

6 The DBMS force-writes all changes/updates made by a
2. (a) A transaction has committed when it has finished all this work. At this point: The DBMS force-writes all changes/updates made by a transaction to the log Then the DBMS force-writes a commit record for the Transaction 12/3/2019

7 A DBMS will execute a checkpoint in order to simplify the
recovery process. At a checkpoint any committed transactions will have their database writes (updates/changes) physically written to the database. (The changes made by unaccomplished transactions may also be written to the database.) This is a four-step process Suspend transaction execution temporarily The DBMS force-writes all database changes to the database The DBMS writes a checkpoint record to the log and force-writes the log to disk Transaction execution is resumed 12/3/2019

8 2. (b) T1 – redone T2 – no redo, no undo T3 – no redo, no undo
T5 – undone 12/3/2019

9 3.(20)Given the relation schemas shown below, generate an optimal
query tree for the following query: SELECT fname, lname FROM EMPLOYEE, DEPARTMENT, PROJECT, WORKS_ON WHERE salary > and Pname = ‘Web Database’ and Pnumber = PNO and hours > 30 and dno = dnumber and Dname = ‘CS’ and ssn = ESSN 12/3/2019

10 Dname, dnumber, mgrssn, mgrstartdate
DEPARTMENT Dname, dnumber, mgrssn, mgrstartdate EMPLOYEE fname, minit, lname, ssn, bdate, address, sex, salary, superssn, dno PROJECT Pname, Pnumber, Plocation, Dnum WORKS_ON ESSN, PNO, HOURS 12/3/2019

11 fname, lname((salary >50000(Employee) Dname=’CC’(Department)
dno=Dnumber ((hours >30( Works_on) Pname=’web database’(Project)) ssn=ESSN PNO=Pnumber 12/3/2019

12 Question 3 fname, lname fname, lname PNO Pnumber
ssn=ESSN Pname= ‘web database’ fname, lname ssn ESSN, PNO Project Dnumber=dno Dept. Dname=’BC’ dnumber fname, lname, ssn, dno hours > 30 salary > 50000 Employee Works_on 12/3/2019

13 Answers to Midterm - Exam. Feb. 27, 2006
4.(30) (i) Explain the difference among the recoverable, cascadeless and strict schedules. (10)   (ii) Given the following schedules, show which is recoverable, non-recoverable, cascadeless or strict. (20) (a) R1(X), W1(X), R2(Z), W2(Z), R1(Y), W1(Y), R2(Y), C1, R2(X), W2(X), C2. (b) R1(X), W1(X), R2(X), R1(Y), W2(X), C2, W1(Y), C1. (c) R1(X), R2(X), W1(X), R2(Y), W2(Y), W2(X), C2, R1(Y), W1(Y), C1. (d) R1(X), W1(X), R2(Y), W2(Y), C1, R2(X), W2(X), C2. (e) R1(X), R2(X), W1(X), R2(Y), W2(X), C2, A1. 12/3/2019

14 Recoverable: A schedule S is recoverable if no transaction T in S
commits until all transactions T’ that have written an item that T reads have committed. cascadeless: Every transaction in the schedule reads only items that were written by committed transaction. Strict: a transaction can neither read nor write an item X until the last transaction that wrote X has committed or aborted. (ii) Recoverable Non-recoverable Cascadeless Strict cascadeless 12/3/2019

15 Answers to Midterm - Exam. Feb. 27, 2006
5.(5) (i)Consider the following transactions T1 and T2, which execute concurrently. Is the result of this execution correct? Explain your answer and try this for X = 10, Y = 20, N = 5 and M = 8. T1 Read(X) X := X - N Write(X) Read(Y) Y := Y + N Write(Y) Commit T2 Read(X) X := X + M Write(X) Commit 12/3/2019

16 The result produced by the interleaved transaction is not correct.
Answer: The result produced by the interleaved transaction is not correct. It suffers the so-called lost-update problem. After this interleaved execution, X becomes 5 and Y becomes 25. The result of the serial execution is X = 13 and Y = 25. 12/3/2019

17 (ii) If the two transactions are executed interleavingly as follows and the
initial values for X and Y are 20 and 30, respectively, what are the values of X and Y after the execution. Explain why the results are not correct. (5) T1 read_lock(Y) read_item(Y) unlock Write_lock(X) Read_item(X) X :=X+Y Write_item(X) Unlock(X) T2 read_lock(X) read_item(X) unlock(X) write_lock(Y) read_item(Y) Y:=X+Y write_item(Y) unlock(Y) 12/3/2019

18 The result produced by the interleaved transaction is not correct.
Answer: The result produced by the interleaved transaction is not correct. It is because both the transaction use the data before the transactions’ execution. The changes made by the transactions are not accumulated. The result is not to the serial execution. After this interleaved execution, both X and Y are equal to 50. Serial executions T1 before T2: X = 50, Y = 80 T2 before T1: X = 70, Y = 50 12/3/2019


Download ppt "Answers to Midterm - Exam. Feb. 27, 2006"

Similar presentations


Ads by Google