POTD 7: Query cost estimation

Due 4-Apr-2024 6-Apr-2024, 12pm/noon EST

Purpose:

You may make a copy of a worksheet and complete this activity, type your answers in any text editor, or simply write on paper(s).

You may work alone or with 3-4 other students in this course.


  1. Consider the relations Q(a,b), R(a,c,d), S(b,d) with the following statistics:
    T(Q)	= 2500     = number of tuples in relation Q
    V(Q,a) 	= 30       = number of distinct values of attribute a in relation Q
    V(Q,b)	= 500	   = number of distinct values of attribute b in relation Q
    T(R)	= 6000	   = number of tuples in relation R
    V(R,a)	= 60       = number of distinct values of attribute a in relation R
    V(R,c)	= 20       = number of distinct values of attribute c in relation R
    V(R,d)	= 40       = number of distinct values of attribute d in relation R
    T(S)	= 1000     = number of tuples in relation S
    V(S,b)	= 250      = number of distinct values of attribute b in relation S
    V(S,d)	= 100      = number of distinct values of attribute d in relation S

    Estimate the size (number of tuples) of the result of the following query

    SELECT * 
    FROM R NATURAL JOIN S
    WHERE R.a = 22 AND S.b = 90
    [sample solution]
    solution to cost estimation, question 1

  2. Consider the relations instructor and department and the following statistics:
    instructor(ID, name, dept_name, salary)
        T(instructor)   = 13     #of tuples
        V(dept_name)    = 4      #of distinct values
    
    department(dept_name, building, budget)
        T(department)   = 5      #of tuples
        V(dept_name)    = 5      #of distinct values 

    Find the buildings of departments where more than two instructors are working

    1. Write a SQL query
      [sample solution]
      SELECT D.dept_name, D.building 
      ROM instructor I NATURAL JOIN department D 
      GROUP BY D.dept_name, D.building
      HAVING COUNT(*) > 2  
      
      Assume: each department is located in exactly one building 

    2. Draw an RA plan
      [sample solution]
      solution to cost estimation, question 2 (RA plan)

    3. Estimate the cardinality of each RA operator
      [sample solution]
      solution to cost estimation, question 2

Grading rubric

[Total: 10 points]: Done (or provide evidence of your attempt, full or reasonable effort)

(-2.5 points) for 24 hours late (submitted after 4-Apr-2024 12pm/noon EST, by 5-Apr-2024 12pm/noon EST)
(-5 points) for 48 hours late (submitted after 5-Apr-2024 12pm/noon EST, by 6-Apr-2024 12pm/noon EST)

(-2.5 points) for 24 hours late (submitted after 6-Apr-2024 12pm/noon EST, by 7-Apr-2024 12pm/noon EST)
(-5 points) for 48 hours late (submitted after 7-Apr-2024 12pm/noon EST, by 8-Apr-2024 12pm/noon EST)


Submission


Copyright © 2024 Upsorn Praphamontripong
Released under the Creative Commons License CC-BY-NC-SA 4.0 license.
Last updated 2024-03-31 20:24