Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
CSE 232A Midterm Winter 2007 P1 Your Name: P2 P3 Total/70 Your Student ID: You have 80 minutes for this open-book and open-slides exam. Good luck! Problem 1 (20 points) True or false (no justification required): 1. If R and S are over attributes AB, πA (R − S) = πA (R) − πA (S) -Answer: 2. If R and S are over attributes AB, σA=0 (R − S) = σA=0 (R) − σA=0 (S) -Answer: 1 3. If R and S are over attributes AB, πA (R ∪ S) = πA (R) ∪ πA (S) -Answer: 4. If R and S are over attributes AB, πA (R ∩ S) = πA (R) ∩ πA (S) -Answer: 5. If R has attributes AB and S1 , S2 have attribute B, R ÷ (S1 ∩ S2 ) = (R ÷ S1 ) ∩ (R ÷ S2 ) -Answer: 6. If R has attributes AB and S1 , S2 have attribute B, R ÷ (S1 ∪ S2 ) = (R ÷ S1 ) ∪ (R ÷ S2 ) -Answer: Given a unary operator o taking a set as argument and returning a set, we say that o is monotonic if for every pair of sets S1 , S2 , whenever S1 ⊆ S2 , we have o(S1 ) ⊆ o(S2 ). If o is a binary operator from pairs of sets to sets, we call o monotonic in its first argument if for every sets S1 , S2 , S, whenever S1 ⊆ S2 , we have o(S1 , S) ⊆ o(S2 , S). o is monotonic in its second argument if for every sets S1 , S2 , S, whenever S1 ⊆ S2 , we have o(S, S1 ) ⊆ o(S, S2 ). 7. The RA selection operator σ is monotonic. -Answer: 2 8. The RA projection operator Π is monotonic. -Answer: 9. The RA Cartesian product operator is monotonic in both arguments. -Answer: 10. The RA set difference operator − is monotonic in both arguments. -Answer: 3 Problem 2 (10 points) Given relation R(A, B, C), express the fact that A, B is a key on R using an algebraic dependency of the kind E1 ⊆ E 2 where E1 , E2 are valid RA expressions. That is, denoting with E(D) the result of applying query E on database D, find E1 and E2 such that for every database D (which contains a relation R), the above key constraint holds if and only if E1 (D) ⊆ E2 (D). You are not allowed to use ∅ as one of the RA expressions. Moreover, E1 , E2 cannot be unsatisfiable queries. That is, there must exist some databases D1 , D2 such that the result of E1 on D1 is non-empty, and so is that of E2 on D2 . 4 Problem 3 (40 points) Consider the following schema of a boat rental agency: sailor(sname:string, rating: integer) boat(bname:string, color: string, rating: integer) reservation(sname:string, bname: string, day: date) The rating attribute for boats indicates the minimum rating required of a sailor to qualify for sailing (and therefore reserving) that boat. Find the names of the highest-rated boats reserved by Popeye. Express this query in (i) tuple calculus, (ii) SQL, (iii) domain calculus, (iv) QBE, (v) relational algebra. –Answer: (i) (ii) (iii) 5 (iv) (v) 6