0% found this document useful (0 votes)
26 views4 pages

Assignment3 Solution 2024

Uploaded by

Krystal Yeung
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)
26 views4 pages

Assignment3 Solution 2024

Uploaded by

Krystal Yeung
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/ 4

Question 1.

(50 marks)
Suppose that you have formatted your disk with a block size of 4096 bytes and assume
that we have 10,000 SMARTPHONE records of fixed length. A block pointer is 10
bytes long (P=10), and a record pointer is 6 bytes long (Pr=6). Each SMARTPHONE
record has the following fields: Brand (16 bytes), Model (20 bytes), Color (10 bytes),
Size (60 bytes), Weight (10 bytes), Price (8 bytes), Year (4 bytes), and Remarks (160
bytes). The file is ordered by the key field Brand, and we want to construct a primary
index on Brand.
Justify your answers and state any assumptions that you make!

(a) Calculate the blocking factor (bfr) and the number of file blocks needed to store the
SMARTPHONE records. Assume that records are stored unspanned. How much
space remains unused per block? [10 marks]
The record size R = 16 + 20 + 10 + 60 + 10 + 8 + 4 + 160 = 288.
bfr = floor(B / R) = floor(4096/288) = 14 records/block.
#file_blocks = ceil(10000 / bfr) = 715 blocks.
spc_unused = B – (R*bfr) = 4096 – 288 * 14 = 64 bytes.

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


Ri = size(Brand) + P = 16 + 10 = 26 bytes.
bfri = floor(B / Ri) = floor(4096 / 26) = 157 entries/block.

(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 = 715 blocks, denote as I
#index_block = = ceil(I / bfri) = ceil(715 / 157) = 5

(d) Suppose we are going to retrieve a record based on the value of Brand. What is
the number of block accesses needed to search for a record without using the
primary index? And what is the number of block accesses using the single-level
index in subquestion (c)? [10 marks]
without index: ceil(log 715) = 10 blocks.
with index: ceil(log 5) + 1 = 4 blocks.
(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: 5 blocks
second level: ceil(5 / 157) = 1 block
So we need two levels. Total number of blocks is 5 + 1 = 6.

(f) Consider the multilevel index from subquestion (e). What is the number of block
accesses needed to search for and retrieve a record from the file, given its Brand
value? [5 marks]
#block_access = #level + 1 = 3

Question 2. [30 marks]


Suppose that the size of a search key field is V=32 bytes, the size of a data (record)
pointer is Pr=7 bytes, and the size of a block pointer/tree pointer is P=7 bytes, the
block size B is 4096 bytes.
(a) If we want to construct a B+ tree, what is the maximum number of tree pointers in
an internal node? What is the maximum number of data pointers in a leaf node?
[15 marks]
internal node:
q*P + (q-1) * V <= B
7q + 32(q-1) <= 4096
q <= 105

leaf node:
q- * (Pr + V) + P <= B
39q- + 7 <= 4096
q <= 104

(b) Assume that we have 20,000 SMARTPHONE records of fixed length; compute the
total number of blocks needed if (internal and leaf) nodes are approximately 60%
full. [15 marks]
On average, each internal node will contain 105 * 0.6 = 63 pointers.
On average, each leaf node will contain (104+1) * 0.6 = 63 pointers.
Therefore, the average number of leaf blocks is ceil(20000 / 63) = 318 blocks. Let k
be the leaf level.
Since each internal node has 63 pointers, the number of internal blocks on the level
k-1 is ceil(318 / 63) = 6 blocks.
Finally, we have one root block on level k-2.
To sum up, the total number of blocks used is 1 + 6 + 318 = 325 blocks.

Question 3. [20 marks]

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

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


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

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

Notes: r1(X) denotes that T1 reads X, w2(Z) denotes that T2 writes Z, and c3 denotes
that T3 commits.
(a) 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). [10 marks]

X
Y
X
Y

This is not serializable, because the serialization graph contains cycles.

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


cascadeless, or strict) that S satisfies. [10 marks]
S is recoverable since T2 reads Z after T3 writes Z and T2 commits after T3 commits.
It’s cascadeless since T2 reads Z after T3 commits. It is not strict since T2 writes Z
before T3 writes Z and T2 has not committed yet when T1 writes Z.

You might also like