Chap12 Practice Key
Chap12 Practice Key
Chap12 Practice Key
r(A, B, C) s(C, D, E)
30,000 tuples 60,000 tuples
25 tuples fit on 1 block 30 tuples fit on 1 block
a) Estimate the number of disk block accesses required for a natural join of r and s using
a nested-loop join if r is used as the outer relation.
b) Estimate the number of disk block accesses required for a natural join of r and s using
a block nested-loop join if s is used as the outer relation. Assume that there are more
than 2000 memory buffers available to facilitate this operation, where each memory
buffer can buffer one disk block.
Note that the question is set up in such a way to enable the best-case
scenario (i.e. enough buffers to cache the s relation) for a block-nested
loop join. If instead the worst case is identified, the part marks would
be given for the worst-case formula ( br x bs + br ) and for identification
of br = 1200 and bs = 2000.
select t.branch_name
from branch t, branch s
where t.assets > s.assets and s.branch_city = 'Burnaby';
Write an efficient relational algebra expression that is equivalent to this query and
JUSTIFY your choice with an explanation.
ΠT.branch_name((Πbranch_name, assets (ρ T (branch))) ⋈T.assets > S.assets
(Πassets (σ (branch_city = ‘Burnaby’) (ρ S (branch)))))
Each employee record is 20 bytes long and each department record is 40 bytes long.
There are 20,000 tuples in the employee table and 5000 tuples in the department table.
The dept_id attribute in employee is a foreign key of the department relation. The file
system supports a page size of 4000 bytes and there are 12 buffer pages available to
the database. Assume we are using the number of page I/O’s as the measure of a
query’s cost. The following indices exist:
Let N = the number of tuples retrieved with this query. For what values of N would a
sequential table scan of the employee relation be cheaper than processing the query
using the index? Explain your answer.
Given that there are 20000 tuples of 20 bytes, the employee relation
occupies 100 pages of 4000 bytes apiece. To retrieve N tuples using the
secondary index on age, N page I/O’s are required. To perform a full
table scan of the employee relation would require 100 page I/O’s, so if we
expect more than 100 tuples to be returned by the query, it would be
cheaper to do a full table scan than to use the secondary index.
b) Consider the SQL query
select *
from employee, department
where employee.dept_id = department.dept_id
What evaluation plan would a query optimizer likely choose to get the least estimated
cost?
employee ⋈ department