Assignment 8 2022 July

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Database Management System: Assignment 8

Total Marks : 100

October 3, 2022

Question 1
Assume an immediate database modification scheme. Consider the following log records for
transactions T0, T1, T2, T3 and T4: Marks: 2 MSQ

steps Details of log


1 hT0,starti
2 hT1,starti
3 hT1,X,100,200i
4 hT1,commiti
5 hcheckpoint{T0} i
6 hT0,Y,200,400i
7 hT2,starti
8 hT0,commiti
9 hT3,starti
10 hT4,starti
11 hT3,Z,400,600i
12 hT4,W,600,1200i
13 hT4,commiti

If there is a crash just after step 13 and the recovery of the system is successfully completed,
identify the correct actions for the above scenario.

a) After recovery completion, value of X will be 100.

b) After recovery completion, value of Y will be 400.

c) After recovery completion, value of Z will be 600.

d) After recovery completion, value of W will be 1200.

Answer: b), d)
Explanation: In the immediate database modification scheme, during recovery after a
crash, a transaction needs to be redone if and only if both hTi , starti, hTi , commiti are
present in the log. Otherwise, undo is required.
Any transactions that are committed before the last checkpoint should be ignored(updates
already output to disk due to the checkpoint).
Redo list contains transactions {T0, T4} and undo list contains transactions {T2, T3} and for
transaction {T1} no action is needed because it is already committed before checkpoint.
After recovery completion, for T0 the value of Y will be 400, for T3 the value of Z will be 400
and for T4 the value of W will be will be 1200. Hence, options (b) and (d) are correct.

1
Question 2
Identify the cost estimation of a query evaluation plan, if 2000 blocks are required to be
transferred from disk and the required number of disk seeks are 50.

• Time to transfer one block: tT = 4 milliseconds.

• Time for one seek: tS = 0.4 seconds.

Marks:2 MCQ

a) 4.4 Seconds

b) 8 Seconds

c) 10 Seconds

d) 28 Seconds

Answer: d)
Explanation: Cost for b block transfers plus S seeks will be (b ∗ tT + S ∗ tS ) seconds
=(2000 ∗ 4 ∗ 10−3 ) + (50 ∗ 0.4) seconds
= (8 + 20) Seconds
= 28 Seconds
For more details refer to 38.12 of lecture material.
Hence, option d) is the answer.

2
Question 3
Consider the following state of transactions and the statements below.

1. T1, T2 and T4 can be ignored.

2. T1 and T2 can be ignored.

3. T3 and T5 need to be undone.

4. T2, T3, T4 and T5 need to be redone.

5. Only T4 needs to be redone.

Identify the correct group of statements from the options below. Marks:2 MCQ

a) 1), 2), 3)

b) 1), 3), 4)

c) 2), 4), 5)

d) 2), 3), 5)

Answer: d)
Explanation: Any transaction that is committed before the last checkpoint should be ig-
nored. Therefore, T1 and T2 can be ignored (updates already output to disk due to the last
checkpoint).
Any transaction that is committed since the last checkpoint, needs to be redone. Hence, only
T4 needs to be redone.
Any transaction that was running at the time of failure, needs to be undone and restarted. So,
T3 and T5 need to be undone.
Hence, option (d) is the correct answer.

3
Question 4
Let us consider the following statistics for two relations Patients and Appointments:
Marks:2 MCQ

• Number of records of Patients: nPatients = 5000.

• Number of blocks of Patients: bPatients = 200.

• Number of records of Appointments: nAppointments = 1000.

• Number of blocks of Appointments: bAppointments = 100.

Identify the required number of block transfers and seeks for Nested-loop join if the
smaller relation fits entirely in memory and the smaller relation is used as the inner relation
in the join operation.

a) 500200 block transfers and 2 seeks

b) 200100 block transfers and 2 seeks

c) 6300 block transfers and 2 seeks

d) 300 block transfers and 2 seeks

Answer: d)
Explanation: Number of block transfers will be: 200 + 100 = 300, and number of seeks will
be :2, if the smaller relation fits entirely in memory.
For more details refer to 38.31 of lecture material.

4
Question 5
Assume an immediate database modification scheme. Consider the following log records
for transactions T0, T1, T2, T3 and T4: Marks: 2 MCQ

steps Details of log


1 hT0,starti
2 hT0,X,200,400i
3 hT1,starti
4 hT1,Y,400,600i
5 hT0,commiti
6 hcheckpoint{T1} i
7 hT2,starti
8 hT2,Z,600,800i
9 hT3,starti
10 hT3,W,800,1000i
11 hT3,commiti
12 hT4,starti
13 hT4,P,1000,1200i

If there is a crash just after step 13 and the recovery of the system is successfully completed,
identify the correct action for the above scenario.

a) No Action: T0, T1; Redo: T3 and Undo: T2, T4

b) No Action: T0; Redo: T3 and Undo: T1, T2, T4

c) Redo: T0, T3 and Undo: T1, T2, T4

d) Redo: T0, T1 and Undo: T2, T3, T4

Answer: b)
Explanation: In the immediate database modification scheme, during recovery after a
crash, a transaction needs to be redone if and only if both hTi , starti, hTi , commiti are
present in the log. otherwise undo is required.
Any transactions that committed before the last checkpoint should be ignored(updates already
output to disk due to the checkpoint).
Redo list contains transaction {T3} and undo list contain transaction {T1, T2, T4} and for
transaction {T0} no need any action because it is already committed before checkpoint.
Hence, option b) is the answer.

5
Question 6
Consider the log record of transaction T0, transaction T1 with operation instances O1 and
transaction T2 with operation instances O2 used in recovery system with early lock release,
B+ tree based concurrency control. Marks: 2 MCQ

Step Operation
1 hT0, starti
2 hT0, X, 200, 400i
3 hT0, commiti
4 hT1, starti
5 hT1, Y, 400, 600i
6 hcheckpoint{T1} i
7 hT1, O1, operation–begini
8 hT1, Z, 600, 800i
9 hT1, O1, operation–end,(Z, -200)i
10 hT2, starti
11 hT2, O2, operation–begini
12 hT2, W, 800, 1000i
13 crash or abort here

Choose the correct set of log entries for the recovery of transactions.

hT2, W, 800i
hT2, aborti
hT1, Z, 800, 600i
a) hT1, O1, operation–aborti
hT1, Y, 600i
hT1, aborti
hT0, X, 200i

hT2, W, 1000i
hT2, aborti
hT1, Z, 800, 600i
b) hT1, O1, operation–aborti
hT1, Y, 600i
hT1, aborti
hT0, X, 400i

hT2, W, 1000i
hT2, aborti
hT1, Z, 800, 600i
c)
hT1, O1, operation–aborti
hT1, Y, 600i
hT1, aborti

hT2, W, 800i
hT2, aborti
hT1, Z, 800, 600i
d)
hT1, O1, operation–aborti
hT1, Y, 400i
hT1, aborti

6
Answer: d)
Explanation: Step i: Scan the log records backward.
Step ii: For the step 12 update of W was part of O2, undone physically during recovery since
O2 did not complete; so, physical undo is required for operation O2 on the variable W. That
means, we have to add log hT2, W, 800i. For step 10, add the log hT2, abort i
Step iii: For step 9 hT1, O1, operation-end, (Z,-200)i is found; so, logical undo is required
for operation O1 on the variable Z using the information (subtraction of 200). That means,
we have to delete the previous modifications on Z. So, add the following logs for steps 9, 8 and
7 respectively: hT1, Z, 800, 600i and hT1, O1, operation–aborti.
Step iv: For step 5, add the log hT1, Y, 400i.
Step v: For step 4, add the log hT1, abort i.
For steps 3 to 1 no need any action because any transactions that committed before the last
checkpoint should be ignored(updates already output to disk due to the checkpoint).
Hence, option (d) is correct.

7
Question 7
Consider the following relational schema: Marks: 2 MCQ
Patients(pid, pname, age, p email)
Doctors(did, dname, qualification, d email)
Appointments(pid, did, date, time)

Two query trees are given below.

Figure 2:
Figure 1:

Identify the correct statement for the above two query trees.

a) Two query trees are equivalent as identical operations (irrespective of their positions) are
used in both the trees.

b) Two query trees are not equivalent as neither selection nor projection operation can be
carried out before performing the natural join.

c) Two query trees are equivalent and the query tree of Figure 1 will lead to more efficient
query processing.

d) Two query trees are equivalent and the query tree of Figure 2 will lead to more efficient
query processing.

Answer: c)
Explanation: Two query tree is equivalent and Figure 1 will lead to more efficient query
processing because performing the selection operation as early as possible reduces the size of
the relation to be joined.
If projection with needed attribute is carried out before join, query processing becomes efficient.
Hence, option (c) is correct.

8
Question 8
Consider the following relational schema: Marks: 2 MSQ
Patients(pid, pname, age, p email)
Doctors(did, dname, qualification, d email)
Appointments(pid, did, date, time)

Four relational algebra queries are given below:

Q1: (σage>20 (σdate=‘2022-06-12’ (Patients o


n Appointments)))

Q2: (σdate=‘2022-06-12’ (σage>20 (Patients o


n Appointments)))

Q3:Πdname (Πdname,d email (Doctors o


n Appointments))

Q4: Πdname,d email (Doctors o


n Appointments)

Identify the correct options from the options given below.

a) Q1 is equivalent to Q2.

b) Q1 is not equivalent to Q2.

c) Q3 is equivalent to Q4.

d) Q3 is not equivalent to Q4.

Answer: a), d)
Explanation: Q1 and Q2 will give the same result because according to transformation
rules, selection operations are commutative.
Q3 and Q4 will not give the same result because according to transformation rules, only
the last in a sequence of projection operations is needed, the others can be omitted.
Hence, options a) and d) are correct.

9
Question 9
Consider the following relational schema: Marks: 2 MCQ
Patients(pid, pname, age, p email)
Doctors(did, dname, qualification, d email)
Appointments(pid, did, date, time)

Consider the following query of the above relation:

Select Patients.pname, Doctors.dname


From Patients, Doctors, Appointments
Where Patients.pid=Appointments.pid and Doctors.did=Appointments.did and
Patients.age=50;

Identify the most optimized relational algebra for the above query using heuristic based query
optimization technique.

a) ΠPatients.pname,Doctors.dname
(σPatients.pid=Appointments.pid∧Doctors.did=Appointments.did∧Patients.age=50
(Patients × (Doctors × Appointments)))

b) ΠPatients.pname,Doctors.dname ((ΠDoctors.did,Doctors.dname (Doctors))


n (Appointments o
o n (σPatients.age=50
(ΠPatients.pid,Patients.pname,Patients.age (Patients)))))

c) ΠPatients.pname,Doctors.dname ((ΠDoctors.dname(Doctors)) o
n (Appointments o
n
(σPatients.age=50 (ΠPatients.pid,Patients.pname,Patients.age (Patients)))))

d) ΠPatients.pname,Doctors.dname (σPatients.age=50 (Patients o


n (Doctors o
n Appointments)))

Answer: b)
Explanation: Performing selection and projection as early as possible reduces the size of
the relations that are to be joined later. So, it is better to perform projection with required
attribute and then perform selection.
Hence, option b) is correct.

10
Question 10
Consider the Relational Algebra expression given below:
nθ (Q ∩ R) where P, Q, and R are relational algebra expressions.
Po

Identify the correct equivalent relational algebra expression of the above relational algebra
expression. Marks:2 MCQ

a) P o
nθ (Q o
nθ R)

nθ Q) ∩ (P o
b) (P o nθ R)

nθ Q) − R)
c) ((P o

nθ Q) − (P o
d) (P o nθ R)

Answer: b)
Explanation: As per the equivalence rules of Relational Algebra expressions.

11

You might also like