0% found this document useful (0 votes)
30 views3 pages

Homework3 Sol

Uploaded by

jonathandikaspam
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)
30 views3 pages

Homework3 Sol

Uploaded by

jonathandikaspam
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/ 3

Question 1.

(50 marks)
Suppose that you have formatted your disk with a block size of 1024 bytes and
assume that we have 10,000 CAR records of fixed length. A block pointer is 7 bytes
long (P=7), and a record pointer is 5 bytes long (Pr=5). Each CAR record has the
following fields: Model (20 bytes), Registration (8 bytes), Color (9 bytes), License (9
bytes), Location (40 bytes), Mileage (10 bytes), Price (8 bytes), Year (4 bytes),
Manufacturer (16 bytes), and Remarks (200 bytes). The file is ordered by the key
field Model and we want to construct a primary index on Model.

(a) Calculate the blocking factor (bfr) and the number of file blocks needed to store
the CAR records. Assume that records are stored unspanned. How much space
remains unused per block? . [10 marks]

bfr = floor(1024 / (20 + 8 + 9 + 9 + 40 + 10 + 8 + 4 + 16 + 200)) = 3


#file_blocks = ceil(10000 / bfr) = 3334
spc_unused = 1024 – 324 * bfr = 52

(b) Calculate the index blocking factor bfri . [10 marks]

bfri = floor(1024 / (size(Model) + size(block_pointer)) = floor(1024 / 27) = 37

(c) Assume that the primary index is a single-level index. Calculate the number of
index entries and the number of index blocks. [10 marks]

#index_entry = #file_blocks = 3334


#index_block = ceil(3334 / 37) = 91

(d) What is the number of block accesses needed to search for a record without
using primary index? And what is the number of block accesses using the single-
level index in subquestion (c)? [5 marks]

without index: ceil(log ଶ 3334) = 12


with index: ceil(log ଶ 91) + 1 = 8
(e) Now suppose that we want to make the primary index a multilevel index. How
many levels are needed and what is the total number of blocks required by the
multilevel index? . [10 marks]

first level: 91 blocks


second level: ceil(91 / 37) = 3 blocks
third level: ceil(3 / 37) = 1 block
So we need three levels. Total number of blocks is 91 + 3 + 1 = 95.

(f) Consider the multilevel index from subquestion (d). What is the number of block
accesses needed to search for and retrieve a record from the file given its Model
value? . [5 marks]

#block_access = #level + 1 = 4

Question 2. [20 marks]


Suppose that the size of a search key field is V=16 bytes, the size of a record pointer
is Pr=6 bytes, the size of a block pointer/tree pointer is P=8 bytes, the block size B is
1024 bytes. If we want to construct a B+ tree, what are the maximum values of the
order of internal nodes, and the order of leaf nodes?

internal node:
q*P + (q-1) * V <= B
8q + 16(q-1) <= 1024
q <= 43

leaf node:
(q-1) * (Pr + V) + P <= B
22(q-1) + 8 <= 1024
q <= 47

Question 3. [30 marks]


Consider three transactions T1, T2, and T3 and a schedule S, which are given
below:

T1: r1 (X); r1 (Z); w1 (X); w1 (Z);


T2: r2 (Y); w2 (Z); w2 (Y); r2(Z);
T3: r3 (X); r3 (Y); w3 (Y); w3 (X);

S: r1(X); r1(Z); r3(X); r2(Y); r3(Y); w1(X); w2(Z); w1(Z); c1; w2(Y); w3(Y);
w3(X); r2(Z); c2; c3;

1) Draw the serialization graph for S and state whether it is serializable or not. If it’s
serializable, write down all equivalent serial schedule(s). If not, write down a
serializable schedule whose equivalent serial schedule is T1->T2->T3. [20
marks]

X
Z
X
Z

This is not serializable. A serializable schedule can be [r1(X), r1(Z), w1(X), w1(Z), c1,
r2(Y), w2(Z), w2(Y), r2(Z), c2, r3(X), r3(Y), w3(Y), w3(X), c3].

2) Determine the strictest recoverability condition (non-recoverable, recoverable,


cascadeless or strict) that S satisfies.[10 marks]

S is recoverable since T2 reads Z after T1 writes Z and T2 commits after T1


commits. It’s cascadeless since T2 reads Z after T1 commits. It is not strict since T2
writes Z before T1 writes Z and T2 has not committed yet when T1 writes Z.

You might also like