

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!


CPS 216 Spring 2005 Homework # Assigned: Thursday, April 21 Due: Thursday, April 28
Problem 1.
Consider tables R ( A , B , C ), S ( C , D ), and T ( D , E ). Transform the following query into an equivalent query that:
(a) π R. B , S. D , T. E σ( R. A =10) and ( R. C = S. C ) and ( S. D = T. D ) and ( R. A > T. E ) ( R × S × T )
Suppose we have the following statistics:
Estimate the number of the rows returned by the following queries:
(b) σ A =10 R (c) σ A =10 or B = “Bart” R (d) R S (e) R S T
For the following question, further suppose that:
(f) What is the best execution plan (in terms of number of I/O’s performed) you can come up with for the query σ R. B = “Bart” and S. D = 100 ( R S )? Describe your plan and show the calculation of its I/O cost.
Problem 2.
Consider the following relational schema and SQL query. The database stores information about employees, departments, and company finances (organized on a per-department basis).
CREATE TABLE Emp(eid INT NOT NULL PRIMARY KEY, did INT, salary INT, hobby CHAR(20)); CREATE TABLE Dept(did INT NOT NULL PRIMARY KEY, name CHAR(20), floor INT, phone CHAR(10));
CREATE TABLE Finance(did INT NOT NULL PRIMARY KEY, budget FLOAT, sales FLOAT, expenses FLOAT); SELECT d.name, f.budget FROM Emp e, Dept d, Finance f WHERE e.did = d.did AND d.did = f.did AND d.floor = 1 AND e.salary > 59000 AND e.hobby = ‘yodeling’;
(a) Identify a logical plan (using relational algebra operators) that reflects the order of operations a decent query optimizer would choose. (b) List all join orders (i.e., the orders in which pairs of tables are joined to compute the query result) considered by a query optimizer that follows the heuristic of considering only left-deep plans without cross products. (c) Suppose that the following information is available:
Problem 3.
For this problem, you are going to experiment with the query optimizer in IBM DB2. You can see the execution plan chosen by the optimizer using the following command in shell: dynexpln -d dbcourse -q ” query ” -g -t Here, query is a string containing the SQL query (with no terminating “;”) that you wish to optimize. The output should be fairly self-explanatory. For the questions below, write meaningful queries over the system catalog tables including syscat.tables, syscat.columns, syscat.indexes, etc. To see what information is available in these tables, you can use the describe command: db2 “describe select * from table ” It describes the schema of the specified table.
(a) Write a query for which the optimizer chooses a nested-loop join (NLJOIN). (b) Write a query for which the optimizer chooses a sort-merge join (MSJOIN). (c) Write a join query involving three tables. Note the join order chosen by the optimizer.