You are on page 1of 4

1 UCLA Computer Science Department Fall 2001 Instr: C. Zaniolo TAs: P.

Michael

Student Name and ID:

CS143 MIDTERM EXAM: Closed Book, 2 Hours Attach extra pages as needed. Write your name and ID on the extra pages. Please, write neatly.

Problem 1.1 1.2 1.3 2.1 2.2 2.3 2.4 Total

Score (20%) (15%) (15%) (10%) (20%) (10%) (10%) (100%)

Extra Credit: Midterm Score:

students who got two As and two Cs would not satisfy this query. Finally. Fall 2001 — Page: 2 Problem 1 Given a relation describing the courses taken by each student: Student(StudentID. G2 >∈ Student ∧ C1 = C2 ) ∧ ¬∃C3 .Course (Student × ρd (Student))) − ΠStudentID (σStudentID<3. (15 points) Write the same query in domain relational calculus (no aggregates!) {< S > | ∃C1 .StudentID FROM Student AS S2 WHERE S2. you can assume that students only take a course once. and (ii) took a grade of B or better in all classes he/she completed.StudentID∧Course=d.0) GROUP BY S1. C3 .CS143 Midterm. ΠStudentID (σStudentID=d. (Therefore. (20 points) Write an SQL query to find the ID of all students who (i) completed at least two classes. Grade) 1. C1 . G2 (< S.0. G3 (< S. G1 .0 (Student)) . G1 >∈ Student ∧ < S. the code for grades is numeric and the grade B is denoted by the number 3.) SELECT StudentID FROM Student AS S1 WHERE S1.Grade < 3. C2 . (15 points) Write the same query in relational algebra.0 } 3.StudentID NOT IN (SELECT S2. Course.StudentID HAVING count(S1*) >= 2. 2. G3 >∈ Student) ∧ G3 < 3. C2 . Also.

Estimate the number of pages accessed to retrieve this query.) Worst case: 25 at bottom level. The length of each tuple is 50 bytes. (10 points) How many blocks does the file use if there remains no empty record slot in the file blocks. for the best case and the worst case. 38! Next Level: 38/26. On this file. (20 points) Compute the blocks used at each level of the B+ tree. 26 at other levels B+ tree. One pointer per block: 25. The index is is organized as a B+ tree. Fall 2001 — Page: 3 Problem 2 We have 1 million employee tuples with unique key Eno. These are stored as fixed-length records in a file consisting of blocks of size 2048 bytes. (10 points) A query asking for the records of all employees whose Eno falls in a certain range returns 800 records. 3 blocks of index: 3+22=25. The B+ tree blocks contain 2048 bytes. 2048/50 = 40 records per block. . 800 take 20–22 blocks. This is the root! 3. The file records must be sorted on the key.4 take the FLOOR (not the ceiling). Cannot split in two blocks.000/50 = 500 Next Level: 10 The root:1 B+ tree. (10 points) Is this index a primary index or a secondary one? A sparse index can only be built on clustered data. Thus this is a primary index. N=51 pointers (50 at the leaf level.CS143 Midterm.000/25 = 1000 Next Level: 1000/26 = 38. 2. best case: Leaf level: sparse index. we build a sparse index on Eno. Primary indexes are clustered. where each key takes 18 bytes and each pointer takes 22 bytes (the leaf nodes are chained together as in the textbook). 1. 4. worst Case: Leaf nodes: 25. 106 /40 = 25000.

(5 points) Can you express set difference r(A. But set difference is not monotonic.A=s.B =s. Expression of these operators are also monotonic. Thus set difference cannot be expressed using those four operators. . B ) ∩ s(A.CS143 Midterm.B (r × s) 2. selection. projection. Those four operators are monotonic. B ) = σr. 1. B ) using these four operators? Intersection on compatible relations can be expressed as an equijoin on all columns: r(A. B ) using these four operators? Your answers should either express intersection/difference using these operators or explain why such an expression does not exist. cartesian product. Fall 2001 — Page: 4 Extra Credit Problem Given the following four operators: union.A∧r. B ) ∩ s(A. B ) − s(A. (5 points) Can you express set intersection r(A.