Docsity

DB HW4: Join Types, Order, Cost, Transactions, Assignments of Deductive Database Systems

Toggle sidebar
bg1
CS411 Database Systems
Fall 2004
HW#4
Due: 11:30am CST, 12/08/04
Note: Print your name and NetID in the upper right corner of every page of your submission.
Problem 1 Index-Based Join and Sort-Merge Join Algorithms
Suppose we want to join two relations Rand Son attribute A, and then project the resulting
tuples on A. (Thus, we do not worry about other attributes.) The values of Ain the relations,
listed in the order of relation scanning, are as follows:
R.A : 5,2,4,1,7,2,3,8
S.A : 4,7,5,2,9,8
Let’s execute the join with different algorithms below. For each algorithm, show the resulting
tuples (which have only one attribute A) in the order that they are produced.
(a) Index join using an index on R.A.
(b) Sort-merge join.
Problem 2 Hybrid Hash Join Algorithm
Exercise 15.5.5 (Page 756)
Problem 3 Algebraic Laws
(a) Starting with an expression πL(R(a, b, c)./ S(b, c, d, e)), push the projection down as far
as it can go if Lis b+c→x, d +e→y.
(b) Starting with an expression πL(R(a, b, c)./ S(b, c, d, e)), push the projection down as far
as it can go if Lis a, b, a +d→z.
(c) Starting with an expression πL(R(a, b, c)./R.b>S. d S(b, c, d, e)), push the projection down
as far as it can go if Lis a, d.
Problem 4 Join Order Selection
Consider the join of relations R(a, b), S(b, c), T(c, d), and U(a, d), where Rand Seach
have 250 tuples, while Tand Ueach have 2000 tuples. Further, there are 375 values of all
attributes of all relations, except for attribute b, where V(R, b) = V(S, b) = 20.
(a) What is the order selected by the greedy algorithm? What is its cost?
(b) Give the dynamic-programming table entries that evaluates all possible join orders al-
lowing all trees. And show what the best choice is.
1
pf3

Partial preview of the text

Download DB HW4: Join Types, Order, Cost, Transactions and more Assignments Deductive Database Systems in PDF only on Docsity!

CS411 Database Systems

Fall 2004

HW#

Due: 11:30am CST, 12/08/

Note: Print your name and NetID in the upper right corner of every page of your submission.

Problem 1 Index-Based Join and Sort-Merge Join Algorithms

Suppose we want to join two relations R and S on attribute A, and then project the resulting tuples on A. (Thus, we do not worry about other attributes.) The values of A in the relations, listed in the order of relation scanning, are as follows:

R.A : 5 , 2 , 4 , 1 , 7 , 2 , 3 , 8 S.A : 4 , 7 , 5 , 2 , 9 , 8

Let’s execute the join with different algorithms below. For each algorithm, show the resulting tuples (which have only one attribute A) in the order that they are produced.

(a) Index join using an index on R.A.

(b) Sort-merge join.

Problem 2 Hybrid Hash Join Algorithm

Exercise 15.5.5 (Page 756)

Problem 3 Algebraic Laws

(a) Starting with an expression πL(R(a, b, c) ./ S(b, c, d, e)), push the projection down as far as it can go if L is b + c → x, d + e → y.

(b) Starting with an expression πL(R(a, b, c) ./ S(b, c, d, e)), push the projection down as far as it can go if L is a, b, a + d → z.

(c) Starting with an expression πL(R(a, b, c) ./R.b>S.d S(b, c, d, e)), push the projection down as far as it can go if L is a, d.

Problem 4 Join Order Selection

Consider the join of relations R(a, b), S(b, c), T (c, d), and U(a, d), where R and S each have 250 tuples, while T and U each have 2000 tuples. Further, there are 375 values of all attributes of all relations, except for attribute b, where V (R, b) = V (S, b) = 20.

(a) What is the order selected by the greedy algorithm? What is its cost?

(b) Give the dynamic-programming table entries that evaluates all possible join orders al- lowing all trees. And show what the best choice is.

(c) Give the dynamic-programming table entries that evaluates all possible join orders al- lowing left-deep trees only. And show what the best choice is.

Problem 5 Cost Estimation

Estimate the size of the join R(a, b)onS(b, c) using histograms for R.b and s.b. Assume V (R, b) = V (S, b) = 25, and the histograms for both attributes give the frequency of the five most common values, as tabulated below:

0 1 2 3 4 5 others R.b 4 7 6 5 3 35 S.b 9 7 8 5 6 40

How does this estimate compare with the simpler estimate, assuming that all 25 values are equally likely to occur, with T (R) = 60 and T (S) = 75?

Problem 6 Transactions

Exercise 17.1.2 (Page 883)

Problem 7 Failure Recovery

Consider a database with data items {A, B, C, D}. The system uses an undo/redo scheme and has the following logs. Note that an entry 〈T, X, old, new〉 means transaction T changes the value of X from old to new.

We will consider recovery using this udno/redo log. Suppose that the database, at the point when the system failed, is A=a, B=b, C=c, and D=d (where a, b, c, and d are some values).

(a) What are the initial values of A, B, C, and D, before all the transactions start?

(b) List all the possible values of a, b, c, and d. That is, what are the possible data values on the disk at the point of failure (i.e., right after action 21)? Explain why. (Hint: This problem essentially asks you to think how “dirty data” might be buffered in memory or flushed to disks.)

(c) During recovery, how far back in the log do we have to scan to? Answer in terms of Action ID. Explain why.

(d) During recovery, what are the transactions that need to be undone?

(e) During recovery, what are the transactions that need to be redone?

(f) What are the values of A, B, C, and D after recovery? Explain why.