COMP9315 24T1 |
Exercises 08 Query Optimisation and Execution |
DBMS Implementation |
Consider the following tables relating to trips on a suburban bus network
Trip(fromPlace:integer, toPlace:integer, tripDate:date) Place(placeId:integer, address:string, suburb:string)
Write an SQL query that returns all of the addresses in Randwick that are the destination of a trip on March 4, 2005.
Give a naive translation of the SQL query into a relational algebra expression.
Translate the naive relational algebra expression into an equivalent expression using pushing of selections and projections.
Translate the optimized relational algebra expression into the most directly corresponding SQL query.
What are the possible join trees (without cross-products) for each of the following queries:
select * from R,S,T where R.a=S.b and S.c=T.d
select * from R,S,T where R.a=S.b and T.c=R.d
select * from R,S,T where R.a=S.b and S.c=T.d and T.e=R.f
select * from R,S,T,U
where R.a=S.b and S.c=T.d and T.e=R.f and T.g=U.h and S.i=U.j
Do not include trees/sub-trees that are reflections of other tree/subtrees.
Consider a table R(a,b,c) and assume that
Calculate the expected number of tuples in the result of each of the following queries:
where j, k, l, m, n are constants.
Consider the following tables relating to retail sales:
create table Item ( iname text, category text, primary key (name) ); create table Store ( sname text, city text, street text, primary key (city,street) ); create table Transaction ( item text references Item(iname), store text references Store(sname), tdate date, primary key (item,store,tdate) );
Consider the following query (expressed as SQL and relational algebra):
select category,city from Item, Store, Transaction where iname=item and store=sname and tdate='20-12-2004' and city='Sydney'; JoinResult = Item Join[iname=item] Transaction Join[store=sname] Store SelectResult = Sel[tdate='20-12-2004' and city='Sydney'](JoinResult) FinalResult = Proj[category,city](SelectResult)
Show the three most promising
relational algebra expressions
that the query optimizer is likely to consider; then find the most
efficient query plan and estimate its cost.
Assume 50 buffer pages and the following statistics and indices: