Docsity

Relational Algebra - Final Exam - 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
FINAL
Closed Book
Deshpande
Your Name:
•Total points: 100. Weight: 25% of the course grade.
•Show your reasoning. Write partial solutions. You will get a fair amount of the credit if I think you know
the concepts.
•Unless otherwise specified, a Yes/No answer is not sufficient for any question. No points will be
given without accompanying explanation.
1 E/R Modeling/Relational Algebra/SQL [22.5 pts] (2.5 each)
1. Explain the distinction between the terms primary key, candidate key and superkey.
2. Explain the effect of the underlined part in the following SQL command.
create table R (i integer, j integer,foreign key (j) references S(j) on delete cascade);
3. What is a “weak entity set” ? Explain with an example.
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Relational Algebra - Final Exam - 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

FINAL

Closed Book

Deshpande

Your Name:

  • Total points: 100. Weight: 25% of the course grade.
  • Show your reasoning. Write partial solutions. You will get a fair amount of the credit if I think you know the concepts.
  • Unless otherwise specified, a Yes/No answer is not sufficient for any question. No points will be given without accompanying explanation.

1 E/R Modeling/Relational Algebra/SQL [22.5 pts] (2.5 each)

  1. Explain the distinction between the terms primary key, candidate key and superkey.
  2. Explain the effect of the underlined part in the following SQL command. create table R (i integer, j integer, foreign key (j) references S(j) on delete cascade);
  3. What is a “weak entity set”? Explain with an example.
  1. The marketing department of a bank wants to know the total account balance for each zipcode. The data is stored in a table account(acct-no, balance, cust-name, zipcode). However the privacy-paranoid branch managers don’t want to give anybody but themselves access to the balance information for individual customers. What should they do?
  2. Consider the following relation: R(A, B) = {(0, 1), (2, 3), (3, 2), (0, 2), (2, 4)}

What are the results of:

  1. Gsum(sq)(ρS (sq)(πA (^2) +B 2 (R)))
  2. Gsum(sq)(ρS (sq)(π∗ A (^2) +B 2 (R)))
  3. Given a relation R(A, B), write an SQL query to find the tuples t = (a, b) such that there does not exist another tuple with A = a. Assume there are no duplicates.
  1. Give an example of a database operation for which MRU is the better buffer management policy. [2 pts]
  2. Memory error-correcting codes typically require 3 extra parity bits per 4 data bits to identify and correct a single error. Having just one parity bit can help with error detection, but not with correction. Then why is that RAID Level 3 (and 5) is able to do essentially similar task with just one parity bit? [2.5 pts]
  3. Suppose there is a relation R(A, B, C), with a B+-Tree index with search key containing two attributes (A, B). Figure shows an example of such a tree. The keys are sorted by A first, and then by B (if A is the same). Assume A and B are integer attributes. Briefly list the steps taken in using such an index to answer the query σ(0<A<10)∧(5<B<10)(R). [4 pts]

(8,20) (8,30) (9, 8)

(8,1) (8,3) (8, 7) (8,20) (8,25) (8,27) (8,30) (9, 6) (9, 7)

Pointer to tuple with A = 8 and B = 1 Other pointers to the relation are not shown for clarity reasons.

  1. In general, using the index from the previous question to answer a query on B alone, e.g. σ 5 <B< 10 (R), is a bad idea. Construct an example (by choosing some numbers for the relation size, attribute distributions etc) where using this index is preferrable to scanning the relation for this query (Hint: Consider a scenario when A takes only 2 distinct values). [3 pts]
  2. Consider a relation R that is 3.2GB in size. Also, let the block (disk page) size be 4KBytes. Assume the page utilization (how full the pages are) is 80% (for all pages including index pages). Compute the height of a B+-Tree index on this relation, assuming that the maximum number of (key, pointer) pairs that can be stored per page is 125. [3 pts]

3 Query Processing/Query Optimization [34 pts]

  1. For each of the following pairs of expressions, list whether the two expressions are equivalent or not. The relation schemas are: R(a, b), S (a, b), T (b, c). [4 pts]

Expression 1 Expression 2 Equivalent? R − S S − R πb(R − S ) ∩ πb(T ) πb(R) − (πb(S ) ∩ πb(T )) σa= 20 ∧c= 20 (S Z T ) σa= 20 (S ) Z σc= 20 (T ) σa= 20 ∨c= 20 (S Z T ) σa= 20 (S ) Z σc= 20 (T )

  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]
  2. Consider the following three relations (assume all attributes are integers).
    • r 1 (A, B, C): 10000 tuples; primary key A; Attribute B is distributed uniformly between [0, 99] (both inclusive).
    • r 2 (C, D, E): 7000 tuples; primary key C; Attribute D is distributed uniformly between [0, 999] (both inclusive).
    • r 3 (E, F)): 2000 tuples; primary key E.

Compute an estimate for the sizes of the following expressions: [6 pts]

  • σB= 10 (r 1 ):
  • r 1 Z r 2 Z r 3 :
  • σr 1 .B=r 2 .D(r 1 × r 2 ):
  1. For the following 3-relation query, draw all join orders that do not require a cartesian product. [3 pts] select * from R, S, T where R.a = S.a and S.b = T.b
  2. 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,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]

4 Concurrency/Recovery [26 pts]

  1. Explain the “SIX” lock mode with an example of its use. [2 pts]
  2. What is a “dirty read”? Which desriable property of transactions is compromised if dirty reads are allowed (even if serializability is guaranteed)? [3 pts]
  1. What is “STEAL”? Explain with an example why allowing “STEAL” may cause problems with atomic- ity. [3 pts]
  2. Restart recovery: Consider the following transaction log from the start of the run of a database system that is capable of running undo/redo logging with checkpointing. Assume the log entrys are in the format 〈 Tid, variable, new value, old value 〉. Also, note the checkpoint in Step (j). - What are the values of the data items, A, B, C, D, E, and F, on disk, immediately after the check- point in Step (j). [3 pts] - Construct the two lists, “undo-list” and “redo-list”, created during restart recovery. [3 pts]

(a) 〈 START T 1 〉 (b) 〈 T 1 , B, 250, 25 〉 (c) 〈 START T 2 〉 (d) 〈 T 1 , A, 75, 50 〉 (e) 〈 T 2 , C, 35, 25 〉 (f) 〈 COMMIT T 1 〉 (g) 〈 START T 3 〉 (h) 〈 T 3 , E, 55, 25 〉 (i) 〈 T 2 , D, 45, 25 〉 (j) 〈 Checkpoint T 2 ,T 3 〉 (k) 〈 T 2 , C, 65, 35 〉 (l) 〈 COMMIT T 2 〉 (m) 〈 START T 4 〉 (n) 〈 T 4 , F, 100, 25 〉 (o) — System Crash —