



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Question 1 Evaluation of selections Consider a relation with this schema: Employees( eid : integer, ename : string, sal : integer, title : string, age : integer) Suppose that the following indexes, all using Alternative (2) for data entries, exist: a) a hash index on eid , b) a B+ tree index on sal , c) a hash index on age , d) a clustered B+ tree index on < age , sal >. Each Employees record is 100 bytes long, and you can assume that each index data entry is 20 bytes long. The Employees relation contains 10,000 pages and each page holds 20 data records. Consider each of the following selection conditions and, assuming that the reduction factor (RF) for each term that matches an index is 0.1, compute the cost of the most selective access path for retrieving all Employees tuples that satisfy the condition (including file scan and various kinds of index scan): (1) sal > 100 (2) age = 25 (3) eid = 1000 (4) sal > 200 ∧ age > 20 Question 2 Output of join algorithms Suppose we have two unary (one attribute only) relations, R and S: R S
7 8 2 4 9 2 8 1 3 3 9 2 1 7 3 3 6 Show the result of joining R and S using each of the following algorithms. List the results in the order that they would be output by the join algorithm. Note that the result relation contains only one attribute , which is the common attribute between R and S. (1) Nested loops join (one tuple at a time). Use R for the outer loop and S for the inner loop.
(2) Sort merge join. (3) Hash join. Assume there are two hash buckets, numbered 0 and 1, and that the hash function sends even values to bucket 0 and odd values to bucket 1. In Phase II, use R as the “build” relation and S as the “probe” relation. Assume that bucket 0 is read first and that the contents of a bucket are read in the same order as they were written. Question 3 Hybrid hash join Consider a join of relations R and S using hash join, where M = # pages_in_R = 400 pages and N = # pages_in_S = 500 pages. Assume that we have B = 40 pages of memory available in our buffer. We notice that there is more than enough memory, so we keep one of the hash buckets in memory to avoid writing it during the partitioning phase and then re-reading it during the probing phase. Assuming that all buckets have the same size. (1) How many buckets should be used in order to still be able to perform the join in two passes? (2) What would be the cost in number of I/Os of the operation proposed in part 1? Question 4 Query Optimization Consider the following schema: Sailors(sid, sname, rating, age) Boats(bid, bname, size) Reserves(sid, bid, day) Reserves.sid is a foreign key to Sailors and Reserves.bid is a foreign key to Boats.bid. We are given the following information about the database: Sailors contains 1000 records with 20 records per page. Boats contains 100 records with 10 records per page. Reserves contains 10,000 records with 40 records per page. There are 100 values for Reserves.sid. There are 50 values for Reserves.bid. There are 1000 values for Reserves.day In the following queries, assume that a System R style optimizer is used. Consider Query 1: SELECT S.sid, S.sname, B.bname FROM Sailors S, Reserves R, Boats B WHERE S.sid = R.sid AND R.bid = B.bid AND R.day = 'July 4, 2003'; ( 1) Assuming uniform distribution of values and column independence, estimate the number of tuples returned by this query.
System catalog and statistics. As we learned in class, the query planner needs to estimate the number of rows retrieved by a query in order to make good choices of query plans. One important type of the statistics is the total number of entries in each table and index, as well as the number of disk blocks occupied by each table and index. This information is kept in the table pg_class , in the columns reltuples and relpages. We can look at it with queries similar to this one: SELECT relname, relkind, reltuples, relpages FROM pg_class WHERE relname LIKE 'author%'; The view pg_stats provides additional information about each attribute. Of particular importance are:
AND a.name < 'David J. DeWitt'; What is the query plan that PostgreSQL uses for this query? Briefly explain why PostgreSQL chooses this plan. (4) Finally, let us change the query to: SELECT * FROM papers p, authors a, paperauths pa WHERE pa.paperid = p.id AND pa.authid = a.id AND a.name > 'David J. DeWitt' What is the query plan that PostgreSQL uses for this query? Briefly explain why PostgreSQL chooses this plan.