COMP9315 24T1 Exercises 08
Query Optimisation and Execution
DBMS Implementation

[Show with no answers]   [Show with all answers]


  1. 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)
    
    1. Write an SQL query that returns all of the addresses in Randwick that are the destination of a trip on March 4, 2005.

      [show answer]

    2. Give a naive translation of the SQL query into a relational algebra expression.

      [show answer]

    3. Translate the naive relational algebra expression into an equivalent expression using pushing of selections and projections.

      [show answer]

    4. Translate the optimized relational algebra expression into the most directly corresponding SQL query.

      [show answer]


  2. What are the possible join trees (without cross-products) for each of the following queries:

    1. select * from R,S,T where R.a=S.b and S.c=T.d

      [show answer]

    2. select * from R,S,T where R.a=S.b and T.c=R.d

      [show answer]

    3. select * from R,S,T where R.a=S.b and S.c=T.d and T.e=R.f

      [show answer]

    4. 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

      [show answer]

    Do not include trees/sub-trees that are reflections of other tree/subtrees.


  3. 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:

    1. select * from R where not a=k
    2. select * from R where a=k and b=j
    3. select * from R where a in (k,l,m,n)

    where j, k, l, m, n are constants.

    [show answer]


  4. 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:

    [show answer]