Exercises On Join Algos
Exercises On Join Algos
Exercise 02:
Assume (for simplicity in this exercise) that only one tuple fits in a block and memory
holds at most 3 blocks. Show the runs created on each pass of the sort-merge
algorithm, when applied to sort the following tuples on the first attribute: (kangaroo, 17),
(wallaby, 21), (emu, 1), (wombat, 13), (platypus, 3), (lion, 8), (warthog, 4), (zebra, 11),
(meerkat, 6), (hyena, 9), (hornbill, 2), (baboon, 12).
Exercise 03:
Let relations r1(A, B,C) and r2(C, D, E) have the following properties:
r1 has 20,000 tuples,
r2 has 45,000 tuples,
5 tuples of r1 fit on one block, and 30 tuples of r2 fit on one block.
Estimate the number of block transfers required, using each of the following join
strategies for r1⨝r2 in the case of B=200 and B=850 (B is the buffer size in pages):
a. Nested-loop join.
b. Block nested-loop join.
c. Sort merge join.
Exercise 04:
Let r and s be relations with no indices, and assume that the relations are not sorted.
Assuming infinite memory, what is the lowest-cost way (in terms of I/O operations) to
compute r ⨝ s? What is the amount of memory required for this algorithm?
Exercise 05:
Suppose you need to sort a relation of 40 gigabytes, with 4-kilobyte blocks, using a
memory size of 40 megabytes. Suppose the disk transfer rate is 40 megabytes per
second.
a. Find the cost of sorting the relation, in seconds,
b. How many merge passes are required?
Exercise 06:
Design sort-based algorithm for computing the relational division operation.
Given two relations (tables): R(x,y) , S(y).
R and S : tables
x and y : column of R
y : column of S
R(x,y) div S(y) means gives all distinct values of x from R that are associated with all
values of y in S.