0% found this document useful (0 votes)
54 views7 pages

DBMSEnd Sem Winter 2017 Solution

The document describes an exam for a database systems course. It contains 5 questions assessing various database concepts. The first question involves transactions modifying database elements concurrently and recovering from a crash. The second question involves locking in a tree protocol and testing conflict serializability. The third question involves indexing strategies to optimize a query. The fourth question involves normal forms and decomposing a relation. The fifth question involves drawing an ER diagram from SQL statements.

Uploaded by

Gurmehak kaur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views7 pages

DBMSEnd Sem Winter 2017 Solution

The document describes an exam for a database systems course. It contains 5 questions assessing various database concepts. The first question involves transactions modifying database elements concurrently and recovering from a crash. The second question involves locking in a tree protocol and testing conflict serializability. The third question involves indexing strategies to optimize a query. The fourth question involves normal forms and decomposing a relation. The fifth question involves drawing an ER diagram from SQL statements.

Uploaded by

Gurmehak kaur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

CSE202: Fundamentals of Database Systems

End Semester Exam, Winter 2017

Name:________________________ Roll Number:____________________

Maximum Marks: 40 Time: 1.5 hours

Question-1:​(3 + 4 + 3 = ​10 Marks​) Consider a database that has six elements - A, B,


C, D, E and F. The initial values of the elements are:
A = 10, B = 20, C = 30, D = 40, E = 50, F = 60
Let there be three transactions U, V and W that modify these elements concurrently.
● U: A := 5, B:= 15, D := 30
● V: C := 25
● W: E := 35, F:=45
While the elements are being modified by the transactions, the database system
crashes. The recovery mechanism depends on the logging scheme we use. In the
questions below, we present the contents of the log at the time of ​crash when the
logging scheme used is steal/no force. (For each log entry we give the relevant data)

< START U > ;< U, A, 10, 5 >; < START V >; < U, B, 20, 15 >; < V, C, 30, 25 > ;<
COMMIT V >; < START CKPT(U) >; < START W >; < U, D, 40, 30 > ;< W, E, 50, 35 >;
< END CKP T >; < W, F, 60, 45 >

a) Is the following state of database elements (on disk) possible at the time of
crash? Justify your answer.
A = 5, B = 15, C = 25, D = 40, E = 35, F = 45
b) What are the values of the database elements (A=?, B=?, C=?, D=?, E=?, F=?)
after a successful recovery?
c) What different compensation log records will be written in the log during
recovery?

Answer:
a) ​[1 + 2 marks] ​Yes. Before checkpointing, all updates must be on disk, remaining may
or may not be there.
b) ​[4 marks. No partial marking.] ​A = 10, B = 20, C = 25, D = 40, E = 50, F = 60.
Transaction U,W are undone. V had already committed and was not active at start of
checkpoint, hence its effect has been reflected on the disk already.
c) ​[3 marks. No partial marking.] ​Compensation log records will be as follows:
<U, A, 10>
<U, B, 20>
<U, D, 40>
<W, E, 50>
<W, F, 60>
Or
<W, F, 60>
<W, E, 50>
<U, D, 40>
<U, B, 20>
<U, A, 10>

Question-2:
a) [​3 Marks​] Suppose there are eight transactions T1, T2, ..., T8, of which the
odd-numbered transactions, T1, T3, T5 and T7, lock the root of the tree, in that
order. There are three children of the root, first locked by T1, T2, T3 and T4 in
that order. The second child is locked by T3, T6, and T5 in that order, and the
third child is locked by T8 and T7, in that order. Give one example of a serial
order that is consistent with these statements if transactions are assumed to
follow Tree protocol.

T1, T2, T3, T4, T6, T5, T8, T7


[1 mark for justification + 2 marks for final correct order.]
b) [​2 Marks​] Consider the following precedence graph of transactions created to
test the conflict- serializability of a schedule.

i) Is this schedule conflict-serializable?


ii) Give an example schedule for operations of transactions that is consistent
with the above precedence graph, i.e. the schedule would produce the
above precedence graph.

Answer:
i) ​[1 mark.] ​No. There is cycle in precedence graph.
ii) ​[1 mark for correct example.]
T1 T2 T3

R1(A)

W2(A)

W2(B)

R1(A)

W3(B)

c) [​3 Marks​] Give an example of a transaction schedule that is conflict-serializable,


but is not possible using 2PL. In other words, the schedule should be
conflict-serializable, but there should be no way to acquire and release read/write
locks in a way that is consistent with the 2PL protocol.
[No partial marking.]
Answer:
R1(X)R2(Y)R3(Y)W2(Y)W1(X)W3(X)R2(X)W2(X). A valid 2PL scheme cannot be
scheduled with the same schedule because to execute W2(Y) the shared lock on Y by
transaction 3 would have to be released but as W3(X) is also scheduled in transaction 3
after R3(Y), an exclusive lock on X would have to be acquired by transaction 3, after the
release of lock on Y. This violates the 2PL protocol.
d) [​2 marks​] Consider the following schedule of two transactions in terms of query
statements.
1. T1: Select avg(GPA) from Students group by class_id.
2. T2: Update Students Set GPA = 10 where roll_number = ‘2015CSE0001’
3. T2: Commit
4. T1: Select avg(GPA) from students.
5. T1: Commit

T1 transaction consists of two query statements and T2 consists of one query


statement. Both transactions access/update a relation Students (Name, roll_number,
class_id, GPA). As discussed in the class there can be different isolation levels that a
user can set for a transaction, i.e., Repeatable read, Read uncommitted, Read
committed and Serializable.

We are interested to know the level of concurrency one should associate with
transaction T1 to make the schedule feasible, when T2 has been assigned
conflict-serializable level. Answer and reason for each of the four levels, whether the
schedule will be feasible or not if that level is assigned to transaction T1.

Answer: ​[0.25 for mentioning the isolation level is feasible or not + 0.25 marks for
correct justification for each part.]
Repeatable read - Not feasible. Reason: T2 updates the data item read by transaction
T1.
Read uncommitted - Feasible.
Read committed - Feasible Reason: T1 reads the data item committed by T2.
Serializable - Not Feasible

Question-3:​ [​5 Marks​]Consider the following schema.

Enroll(StudentID, CourseID, Term, Grade)

Suppose we want to find the maximum grade of the CSE202 class in Winter 2002 term.
Assume that there is no other index on Enroll. Which one of the following four options
will likely provide the biggest performance improvement for the query? Briefly justify
your answer for each option.

(A) Create a clustered index on Enroll(StudentID)


(B) Create an index on Enroll(StudentID) and another index on Enroll(Grade) and none
of the index is clustered.
(C) Create a clustered index on Enroll(CourseID)and another index on Enroll(Term)
(D) Create a secondary index on Enroll(CourseID, Term)

[1 mark each for option a, b and d with justification why that is not best option. 2 marks
for option c with justification why this is best option.]

Answer: Best Option: C) Create a cluster index on Enroll(courseId) and another index
on Enroll(Term)
By using the index on courseID attribute get the block addresses for CSE 202 course.
Use the index on attribute Term to get the block addresses that have Winter2002 term
records. Then intersection of these block addresses would give us the desired blocks
addresses. Start scanning the file from the block address with the least course ID in the
increasing order of block addresses to get the result records. The number of Disk IOs
will be less than equal to the number of result tuples in addition to index accesses.
However, generally it is going to be very less as the index is clustered on courseID and
hence most of the result records will be highly likely together on the same blocks.

Explanation:
Option (A) is not good as it will result into linear scan of complete file.
Option(B) is not good as indices do not help at all. If any or both indices are used, the
number of Disk IOs will be equal to number of records in addition to accesses made for
index structure accesses.
Option(D) is not good as the number of Disk IOs will be equal to the number of students
enrolled for CSE202 course in Winter 2002 term, i.e. the number of tuples which satisfy
this condition.

Question-4:
a) [​4 Marks​] Consider a relation R with six attributes ABCDEF. The following
functional dependency, F1 = A à BCDEF, holds over R. Your task is to come up
with two other functional dependencies, F2 and F3, which satisfy the following
three properties.
1) Neither F2 nor F3 can be inferred from F1 using Armstrong’s axioms
2) Relation R with functional dependencies F1 and F2 is in BCNF
3) Relation R with functional dependencies F1, F2, and F3 is in 3NF but not in
BCNF
[0.5 mark each for F2 and F3 if they are non trivial. 1.5 mark if F2 makes relation R in
BCNF. 1.5 marks if F2 and F3 makes relation R in 3NF but not in BCNF.]

Answer:
F2: BC→ADEF
F3: D→C
F2 and F3 cannot be derived from F1 by any of reflexivity, transitivity, augmentation
axiom.
Key is A and BC with R based on F1 and F2 only . None of D,E,F are dependent on a
proper subset of the keys, hence relation is in 2NF. For F1 and F2, LHS is a superkey,
hence relation is in 3NF as well as BCNF.
Key is A and BC for R based on F1 ,F2 and F3. Due to same reasons as above, R is in
2NF. For F1,F2,F3, either LHS is a superkey or RHS is a primary key attribute, hence R
is in 3NF. However, D → C violates the property for BCNF as D is not a superkey.

b) [​6 Marks​] Consider relation R with six attributes ABCDEF and the following
functional dependencies: A → CDF, D → A, DF → E. We decompose R into
two relations, ABCD and DEF.
i) Is this decomposition a lossless join decomposition? Briefly justify your answer.
[3 marks. No partial marking. ]
ii) Is this decomposition a dependency-preserving decomposition? Briefly justify
your answer. ​[3 marks. No partial marking.]
Answer:
a)
● R1 ⋃ R2 = R
● R1⋂R2 = D
● D → A, A → CDF. By transitivity, D → CDF ,so D → DF. As, DF → E,
hence, D → DEF.
● Hence, R1⋂R2→R2, which is a lossless decomposition.
b) F1={D → A}, F2={DF → E}
X → Y in F
Z=X
While changes to Z occur do
for i ← 1 to n do
Z = Z ⋃ ((Z ⋂ R​i​) ⋂ R​i​) w.r.t F
if Y is a subset of Z then return true
else return false;
Hence, this is dependency preserving decomposition.
Question-5:​ [​5 Marks​] Draw an ER-diagram that captures the following two SQL
statements.

CREATE TABLE Employees (


ssn CHAR(11),
Name CHAR(30),
mlot INTEGER,
PRIMARY KEY(ssn) )

CREATE TABLE Dept_Mgr (


did INTEGER,
dname CHAR(20),
ssn CHAR(11) NOT NULL,
PRIMARY KEY (did),
FOREIGN KEY (ssn) REFERENCES Employees, ON DELETE NO ACTION)

[2 marks for cardinality constraint. 1 mark each for participation constraints on each
side. 0.5 mark for each of the two entity set(defined attributes and primary key)]

Answer:

You might also like