



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




1 Misc Questions [18 pts]
Answer: access time = 5ms + average rotational latency = 5ms + 60 /12000 * 1/ 2 = 5ms + 2.5ms = 7.5ms. Number of random I/Os possible = 1000 /7.5 = approx 133.
Answer: The first one. If x is always prime, x mod 18 will be odd (except if x = 2), which means most of the even numbered buckets will be empty.
C, D, A, B, C, D, E, A, B
What are the current contents of the buffer pool assuming the buffer management policy is: [1+2 pts]
Answer: The first relation should be stored on RAID level 5 (to minimize the wasted space), whereas the second relation should be stored on level 1 (for better write performance).
2 B+-Tree [19 pts]
Figure below shows a B+-Tree over a sorted relation with three attributes. The order of the B+-Tree is 3 - each node holds at most 3 key values (and 4 pointers) and at least 2 key values (except root). The number of tuples that fit in each disk page is 3 (as shown). Answer the following questions for this tree.
12 20
8 10
22 .. ..
21 .. ..
21 .. ..
20 .. ..
20 .. ..
18 .. ..
B
..
..
B B .. ..
A
A
A
15
12
10
8
8
12 15 18 20 21 22
Order = 3 Number of tuples per block = 3 Not all pointers to the relation are shown for clarity reasons.
Sorted relation file
.. .. ..
..
20
20
OPage 1: Overflow page (for page 3)
BPage 1
BPage 2 (^) BPage 3 BPage 4
Figure 1: A Primary B+-Tree on a Sorted Relation
15 20
8 12 15 18 20 21 22
Figure 3: After deleting (10, A 10 , B 10 )
2 each), and (b) the underlying relation contains 1024 different search keys (in the above example, the number of different search keys is 8). [4 pts]
Answer: The lowest level has 1024/ 2 = 512 pages. The second level would have 512/ 3 = 171 pages, the next one 57, the next one 19, the next one 7, the next one 3, and finally the root 1 page. The total number of pages = 512 + 171 + 57 + 19 + 7 + 3 + 1 = 770 pages. The height would be 7.
3 Query Processing
Answer: See class notes.
(a) Hash Join, Memory 3,000 pages. [3 pts] Answer: Since the smaller relation fits in memory: 2000 + 5000 = 7000 I/Os (b) Sort-Merge Join, Memory 1000 pages. Assume neither relation is sorted to begin with. [3 pts] Answer: (1) Create sorted runs for R on disk (4000 I/Os); (2) Create sorted runs for S on disk (10000 I/Os); (3) Simultaneously read all the runs of R and S , and do a merge join (7000 I/Os). Total = 21000 I/Os. This can be further reduced by noticing that the most of the last run of S can be memory (reduc- ing the number of I/Os by about 2000). (c) Hybrid Hash Join, Memory 1002 pages. [3 pts] Answer: (1) Create two partitions of S (10000 I/Os); (2) Create two partitions of R: build a hash table on the first partition, write the second partition to disk (3000 I/Os); (3) Read first partition of S and join it with the first partition of R (2500 I/Os); (4) Read in the second partition
of R, build a hash table on it, read the second partition of S , and do the join (1000 + 2500 = 3500 I/Os). Total = 19000 I/Os.
Answer: (1) Read S in memory, and build a hash table on it. (2) For each tuple in R, check if there is a match in S using the hash table. If yes, output the tuple.
Answer: Say I have B + 1 blocks of memory. In the second merge phase, I need one block for the output results, and so I can merge B sorted runs. Simiarly, in the first phase, I can sort at most B blocks of data, and hence each sorted run can be of at most size B blocks. Thus, with B + 1 blocks of memory, I can sort B^2 amount of data. The claim follows.