Docsity

Practice Midterm - Database Design | CMSC 424, Exams of Principles of Database Management

Toggle sidebar
bg1
UNIVERSITY OF MARYLAND
Department of Computer Science
CMSC424
Fall 2006
Database Design
PRACTICE MIDTERM
Closed Book
Deshpande
•The questions were combined from two different exams, so the points don’t add up.
•Weight: 12.5% of the course grade.
1 Misc Questions [18 pts]
1. A disk has an average seek time of 5ms, and rotates at 12000 rpm. Compute the average number of
random I/Os possible per second. Underline the final answer. 1s =1000ms. [3 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.
2. A file is being organized using static hashing over an integer search key. The developer is considering
two hash functions: x mod 17 and x mod 18, where xis search key. Which one of these should be
chosen when it is known that xis guaranteed to be a prime number, and why ? [3 pts]
Answer: The first one. If xis always prime, x mod 18 will be odd (except if x =2), which means
most of the even numbered buckets will be empty.
3. Consider the following sequence of page requests to a buffer manager that contains 3 pages:
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]
•LRU (least recently used): Answer: A, B, E
•MRU (most recently used): Answer: A, B, C
4. I have a database with two relations, customer and dvd-rentals. I expect the first relation to be fairly
static (with few changes), whereas the second relation will be continuously updated. Which RAID
level(s) should I use to store these two relations? You can briefly describe the levels, in case you don’t
remember the numbers. [3 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).
5. State true or false. [3 pts]
•Flash memory is faster to access than main memory (RAM). Answer: False
pf3
pf4
pf5

Partial preview of the text

Download Practice Midterm - Database Design | CMSC 424 and more Exams Principles of Database Management in PDF only on Docsity!

UNIVERSITY OF MARYLAND

Department of Computer Science

CMSC

Fall 2006

Database Design

PRACTICE MIDTERM

Closed Book

Deshpande

  • The questions were combined from two different exams, so the points don’t add up.
  • Weight: 12.5% of the course grade.

1 Misc Questions [18 pts]

  1. A disk has an average seek time of 5ms, and rotates at 12000 rpm. Compute the average number of random I/Os possible per second. Underline the final answer. 1s = 1000ms. [3 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.

  1. A file is being organized using static hashing over an integer search key. The developer is considering two hash functions: x mod 17 and x mod 18, where x is search key. Which one of these should be chosen when it is known that x is guaranteed to be a prime number, and why? [3 pts]

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.

  1. Consider the following sequence of page requests to a buffer manager that contains 3 pages:

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]

  • LRU (least recently used): Answer: A, B, E
  • MRU (most recently used): Answer: A, B, C
  1. I have a database with two relations, customer and dvd-rentals. I expect the first relation to be fairly static (with few changes), whereas the second relation will be continuously updated. Which RAID level(s) should I use to store these two relations? You can briefly describe the levels, in case you don’t remember the numbers. [3 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).

  1. State true or false. [3 pts]
    • Flash memory is faster to access than main memory (RAM). Answer: False
  • Tape storage can only be accessed sequentially. Answer: True
  • CDs/DVDs are non-volative storages. Answer: True
  1. In a main memory database, the entire database is loaded into memory at the beginning of operation, and disk does not need to be accessed for any query processing. Discuss why the performance dif- ference between secondary and primary indexes decreases dramatically for such a database. [3 pts] Answer: The main issue with secondary index is that it requires random access to the underlying relation records. In main memory, random access is only as costly as a sequential access, and hence the performance hit for using secondary index is much lower.

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.

} RPage 1

} RPage 2

} RPage 3

} RPage 4

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

  1. There are two ways to do query evaluation for a query involving multiple operations: (1) Material- ization, and (2) Pipelining. Compare the two and explain when one is preferable over the other. Be concise. [3 pts]

Answer: See class notes.

  1. Compute the number of disk I/Os required for executing a join between two relations, R and S , using the specified algorithm and the specified amount of memory. Size of R: 2,000 pages, 200,000 tuples. Size of S : 5,000 pages, 100,000 tuples.

(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.

  1. Semijoin is a binary operator similar to a join. Given two relations, R(A, B) and S (B, C), the result of the semijoin operation, R X S , has the same schema as R, and contains all tuples of R that have at least one match (on attribute B) in S. For example, if R(A, B) = { (1, α), (2, β), (3, γ)} and S(B, C) = { (α, 2), (γ, 3)}, then R X S = { (1, α), (3, γ) }. Write down the steps for an efficient hash-based algorithm for R X S , assuming that S fits in memory, but R is much larger than memory. Be concise. Explicitly write the step that constructs the output tuple. [4 pts]

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.

  1. Consider a relation R that is 10GB in size, with 100 bytes per tuple. Also, let the block size be 10KBytes. So exactly 100 tuples fit on each block, and the relation occupies a total of 1,000, blocks. Show that if you want to do external sorting in two passes, you need at least 1001 blocks of memory (approx 10MB). [5 pts]

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.