CSE 444, Winter 2011, Midterm Examination 9 February 2011

Similar documents
Name Class Account UNIVERISTY OF CALIFORNIA, BERKELEY College of Engineering Department of EECS, Computer Science Division J.

CSE 444, Fall 2010, Midterm Examination 10 November 2010

CSE 444 Midterm Exam

CSE 444 Midterm Exam

INSTITUTO SUPERIOR TÉCNICO Administração e optimização de Bases de Dados

ACID Properties. Transaction Management: Crash Recovery (Chap. 18), part 1. Motivation. Recovery Manager. Handling the Buffer Pool.

Midterm 2: CS186, Spring 2015

Atomicity: All actions in the Xact happen, or none happen. Consistency: If each Xact is consistent, and the DB starts consistent, it ends up

UNIT 9 Crash Recovery. Based on: Text: Chapter 18 Skip: Section 18.7 and second half of 18.8

COMPSCI/SOFTENG 351 & 751. Strategic Exercise 5 - Solutions. Transaction Processing, Crash Recovery and ER Diagrams. (May )

The transaction. Defining properties of transactions. Failures in complex systems propagate. Concurrency Control, Locking, and Recovery

Crash Recovery. The ACID properties. Motivation

Crash Recovery. Chapter 18. Sina Meraji

Transaction Management: Crash Recovery (Chap. 18), part 1

some sequential execution crash! Recovery Manager replacement MAIN MEMORY policy DISK

COURSE 4. Database Recovery 2

ARIES (& Logging) April 2-4, 2018

Computer Science 304

CAS CS 460/660 Introduction to Database Systems. Recovery 1.1

Transactions and Recovery Study Question Solutions

Crash Recovery CMPSCI 645. Gerome Miklau. Slide content adapted from Ramakrishnan & Gehrke

Database Recovery Techniques. DBMS, 2007, CEng553 1

Last time. Started on ARIES A recovery algorithm that guarantees Atomicity and Durability after a crash

Introduction. Storage Failure Recovery Logging Undo Logging Redo Logging ARIES

Review: The ACID properties. Crash Recovery. Assumptions. Motivation. More on Steal and Force. Handling the Buffer Pool

Introduction to Database Systems CSE 444

Database Administration and Tuning

AC61/AT61 DATABASE MANAGEMENT SYSTEMS JUNE 2013

A tomicity: All actions in the Xact happen, or none happen. D urability: If a Xact commits, its effects persist.

Slides Courtesy of R. Ramakrishnan and J. Gehrke 2. v Concurrent execution of queries for improved performance.

CSE 344 Midterm. Wednesday, February 19, 2014, 14:30-15:20. Question Points Score Total: 100

Crash Recovery Review: The ACID properties

Chapter 17: Recovery System

Failure Classification. Chapter 17: Recovery System. Recovery Algorithms. Storage Structure

CS122 Lecture 18 Winter Term, All hail the WAL-Rule!

Problems Caused by Failures

IMPORTANT: Circle the last two letters of your class account:

CS 245 Final Exam Winter 2016

Database Management Systems Paper Solution

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Database Systems: Fall 2008 Quiz I

CSE344 Final Exam Winter 2017

CSE 544, Winter 2009, Final Examination 11 March 2009

In these relations, vin is a foreign key in ORDER referring to the CAR relation, and techid is a foreign key

CPSC 310: Database Systems / CSPC 603: Database Systems and Applications Final Exam Fall 2005

A7-R3: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS

CS 186 Databases. and SID:

IMPORTANT: Circle the last two letters of your class account:

Database Recovery. Lecture #21. Andy Pavlo Computer Science Carnegie Mellon Univ. Database Systems / Fall 2018

UNIVERSITY OF CALIFORNIA Department of EECS, Computer Science Division. Final Exam: Introduction to Database Systems

Name: Database Systems ( 資料庫系統 ) Midterm exam, November 15, 2006

The University of British Columbia Computer Science 304 Practice Final Examination

Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Administrivia. Last Class. Faloutsos/Pavlo CMU /615

CompSci 516 Database Systems

Transactions. Transaction. Execution of a user program in a DBMS.

CSE 344 Midterm. Wednesday, February 19, 2014, 14:30-15:20. Question Points Score Total: 100

CS 4604: Introduc0on to Database Management Systems. B. Aditya Prakash Final Review

MASSACHUSETTS INSTITUTE OF TECHNOLOGY

Outline. Purpose of this paper. Purpose of this paper. Transaction Review. Outline. Aries: A Transaction Recovery Method

CSE 344 Final Examination

Attach extra pages as needed. Write your name and ID on any extra page that you attach. Please, write neatly.

Homework 6 (by Sivaprasad Sudhir) Solutions Due: Monday Nov 27, 11:59pm

Homework 2: Query Processing/Optimization, Transactions/Recovery (due February 16th, 2017, 9:30am, in class hard-copy please)

Transaction Management. Readings for Lectures The Usual Reminders. CSE 444: Database Internals. Recovery. System Crash 2/12/17

CSEN 501 CSEN501 - Databases I

McGill April 2009 Final Examination Database Systems COMP 421

Page 1. Goals for Today" What is a Database " Key Concept: Structured Data" CS162 Operating Systems and Systems Programming Lecture 13.

3 February 2011 CSE-3421M Test #1 p. 1 of 14. CSE-3421M Test #1. Design

6 February 2014 CSE-3421M Test #1 w/ answers p. 1 of 14. CSE-3421M Test #1. Design

Database Applications (15-415)

6.830 Lecture Recovery 10/30/2017

Final Review. May 9, 2017

CS186 Final Exam Spring 2016

Final Review. May 9, 2018 May 11, 2018

Aries (Lecture 6, cs262a)

Transaction Management Overview

Homework 7: Transactions, Logging and Recovery (due April 22nd, 2015, 4:00pm, in class hard-copy please)

Final Exam CSE232, Spring 97

CS 245 Final Exam Winter 2017

Administrivia. CS186 Class Wrap-Up. News. News (cont) Top Decision Support DBs. Lessons? (from the survey and this course)

CSE 544 Principles of Database Management Systems. Fall 2016 Lectures Transactions: recovery

CSE 444 Midterm Exam

Goals for Today. CS 133: Databases. Final Exam: Logistics. Why Use a DBMS? Brief overview of course. Course evaluations

CS122 Lecture 19 Winter Term,

One Size Fits All: An Idea Whose Time Has Come and Gone

Lecture 16: Transactions (Recovery) Wednesday, May 16, 2012

CS/B.Tech/CSE/New/SEM-6/CS-601/2013 DATABASE MANAGEMENENT SYSTEM. Time Allotted : 3 Hours Full Marks : 70

Introduction to Data Management. Lecture #26 (Transactions, cont.)

Review: The ACID properties. Crash Recovery. Assumptions. Motivation. Preferred Policy: Steal/No-Force. Buffer Mgmt Plays a Key Role

Name :. Roll No. :... Invigilator s Signature : DATABASE MANAGEMENT SYSTEM

6.830 Lecture Recovery 10/30/2017

SQL: Part II. Announcements (September 18) Incomplete information. CPS 116 Introduction to Database Systems. Homework #1 due today (11:59pm)

CSE 344 Final Examination

CSE 190D Database System Implementation

CSE 344 Final Examination

Database Systems Management

CSCE 4523 Introduction to Database Management Systems Final Exam Spring I have neither given, nor received,unauthorized assistance on this exam.

Database Systems ( 資料庫系統 ) Practicum in Database Systems ( 資料庫系統實驗 ) 9/20 & 9/21, 2006 Lecture #1

Transaction Management Overview. Transactions. Concurrency in a DBMS. Chapter 16

Chapter 16: Recovery System. Chapter 16: Recovery System

Babu Banarasi Das National Institute of Technology and Management

Transcription:

Name: CSE 444, Winter 2011, Midterm Examination 9 February 2011 Rules: Open books and open notes. No laptops or other mobile devices. Please write clearly. Relax! You are here to learn. An extra page is provided in case you run out of space, but make sure to put a forward reference. Question Max Grade 1 30 2 30 3 18 4 22 Total 100 1

1. (30 points) SQL For a given quarter, the table Student lists all students registered at the University, the table Course lists all courses offered, and the table Enrollment encodes the students that attend any course in the current quarter. Student ( sid, sname ) Course ( cid, cname ) Enrollment ( cid, sid ) Enrollement.sid is a foreign key that references Student.sid. Enrollement.cid is a foreign key that references Course.cid. (a) (8 points) Assume that no two courses have the same name. Call a course big if the number of students enrolled is at least 50. Write a SQL query that returns the names of all big courses in decreasing order of their enrollment size. SELECT cname FROM Course C, Enrollment E WHERE C.cid = E.cid GROUP BY cname HAVING COUNT(*) >= 50 ORDER BY COUNT(*) DESC 2

(b) (8 points) A classmate of a student is another student who is enrolled in at least one same class. Write a SQL query that returns all pairs of classmates. You should return their student IDs, as their names do not uniquely identify them. SELECT DISTINCT E1.sid AS sid1, E2.sid AS sid2 FROM Enrollment E1, Enrollment E2 WHERE E1.cid = E2.cid AND E1.sid!= E2.sid 3

(c) (14 points) Write a SQL query that computes for each student id in the Student table the total number of different classmates that this student has across all courses. Note that a student may be so busy with research (or parties ) that he or she may choose not to enroll to any course that quarter, and hence has no classmates. Such students should still appear in the result, with 0 as the number of their classmates. Hint: this is not required, but it may help you to make use of an earlier query. We can use our query from the previous question in a subquery: SELECT S.sid, COUNT(T.sid2) FROM Student S LEFT OUTER JOIN (SELECT DISTINCT E1.sid AS sid1, E2.sid AS sid2 FROM Enrollment E1, Enrollment E2 WHERE E1.cid = E2.cid AND E1.sid!= E2.sid) T ON S.sid = T.sid1 GROUP BY S.sid Slightly different alternative: SELECT S.sid, COUNT(DISTINCT T.sid2) FROM Student S LEFT OUTER JOIN (SELECT DISTINCT E1.sid AS sid1, E2.sid AS sid2 FROM Enrollment E1, Enrollment E2 WHERE E1.cid = E2.cid) T ON S.sid = T.sid1 AND S.sid!= T.sid2 GROUP BY S.sid 4

2. (30 points) Conceptual Design (a) (12 points) A friend is impressed by your skills in CSE 444, and asks you to help her design a database to model doctors offices across Seattle. She started the E/R diagram below which already contains all the entity sets, their attributes and relationships she wants you to consider. You need to finish the diagram and define a number of constraints to ensure that you model the semantics of an office as closely as possible. Make sure that you do not impose additional constraints not defined by the model. i. (4 points) An office may be managed by at most one doctor. A doctor is uniquely identified by their badgeid, and may manage more than one office. Draw the necessary constraints to capture this requirement. ii. (5 points) An office is identified by its address, and contains one or more exam rooms. A room can be identified by its room number, and the office that it is in. Capture these constraints by drawing on or modifying the diagram where necessary. iii. (3 points) When a patient visits an office, he or she has a consultation with a doctor in an examination room. Each patient is uniquely identified by their SSN. Draw your answer directly onto the figure below. Make sure that any arrows, lines, double lines etc, are clearly visible. phone# address badgeid name Office Manages Doctor ssn Inside Consults Pa6ent name phone# Exam Room room# 5

(b) (12 points) Convert the E/R diagram below to a database schema. Indicate the keys for each table in your answer. You do not need to write SQL DDL commands. a b c d A R B isa f g h e C S D A ( c, a, b ) B ( c, d ) C ( a, c, e ) D ( g, h ) S ( a, c, g, f ) Explanation: Entity A is weak and dependent on B. Hence, the key of A needs to include the key of B. C is a refinement of A and, hence, needs to include the key of A. 6

(c) (6 points) Suppose we are told that R(A, B, C, D) is in BCNF, and that 3 out of the 4 FDs listed below hold for R. Choose the FD that R does not satisfy, and explain your reasoning. 1 : A BCD 2 : BC A 3 : CD B 4 : D C The problem states that only 3 out of the given 4 FDs hold for R. So, there are 4 possibilities: If 2, 3, 4 are the ones that hold, then D is the only key, and therefore 2 would violate BCNF, so it s not a possibility. If 1, 3, 4 are the ones that hold, then the only key is A. But then both 3 and 4 would be in violation of BCNF, so this is not a good choice either. If 1, 2, 4 are the ones that hold, then the keys are A, and BC. But then both 4 would violate BCNF. If 1, 2, 3 are the ones that hold, then A, BC and CD are all keys, so none of them violates BCNF. Therefore, this is the right choice. So, 4 is the FD that doesn t hold based on the problem description. (Note that all 4 FDs could hold without violation of BCNF, but the problem definition tells you that only 3 hold, and under this assumption, there is only one possibility as listed above) 7

3. (18 points) Logging and Recovery Your database server crashed due to a power outage. After rebooting, you find the following log and checkpoint information on disk, and begin the recovery process. We assume that STEAL/NO FORCE policy is used, and we use the ARIES method for recovery. LSN Record prevlsn undonextlsn 30 update: T3 writes P5 null - 40 update: T4 writes P1 null - 50 update: T4 writes P5 40-60 update: T2 writes P5 null - 70 update: T1 writes P2 null - 80 Begin Checkpoint - - 90 update: T1 writes P3 70-100 End Checkpoint - - 110 update: T2 writes P3 60-120 T2 commit 110-130 update: T4 writes P1 50-140 T2 end 120-150 T4 abort 130-160 update: T5 writes P2 Null - 180 CLR: undo T4 LSN 130 150 50 Transaction Table at time of checkpoint Transaction ID lastlsn Status T1 70 Running T2 60 Running T3 30 Running T4 50 Running Dirty Page Table at checkpoint Page ID reclsn P5 50 P1 40 (a) (2 points) The log record at LSN 60 denotes an update to page P5 by transaction T2. Was this update to page P5 successfully written to disk? If yes, at what point could that have happened? The update at LSN 60 may have been written to disk; the log entry was flushed before the write itself. It was not yet flushed at the time of the checkpoint, but may have been flushed later. (b) (2 points) The log record at LSN 70 denotes an update to page P2 by transaction T1. Was this update successfully written to disk? If yes, at what point? Briefly explain your answers. The update at LSN 70 was flushed to disk before the Begin Checkpoint (LSN 80). We know this because it is not in the dirty page table at the time of the checkpoint. 8

(c) (6 points) At the end of the Analysis phase, what will the Transaction and Dirty Page Tables look like? Populate your answers in the tables below. Transaction ID lastlsn Status Page ID reclsn T1 90 Running T3 30 Running T4 180 Aborting T5 160 Running P1 40 P2 160 P3 90 P5 50 (d) (6 points) At which LSN in the log will REDO begin? Which log records will be redone? List their LSNs, and briefly justify your answers. Redo should begin at LSN 40, the smallest of the reclsns in the dirty page table. The following log records should be redone: 40, 50, 60, 90, 110, 130, 160, 180 30 is skipped because it precedes LSN 40. 70 is skipped because P 2.recLSN = 160 > 70. Entries that are not updates are skipped. The CLR record is not skipped, nor is the LSN that it undoes. 9

(e) (2 points) For each of the following questions circle the right answers. i. In an UNDO only logging scheme, what buffer management policies apply? (circle one of STEAL or NO STEAL, and one of FORCE or NO FORCE) STEAL / NO STEAL FORCE / NO FORCE ii. During recovery with REDO only logging, we cannot use a checkpoint for which we see a <START CKPT(... T i...)> record but no corresponding <END CKPT> record. TRUE / FALSE i. STEAL and FORCE, ii. TRUE 10

4. (22 points) Concurrency Control In the schedules given below, the label R i (X) indicates a read of element X by transaction T i, and W i (X) indicates a write of element X by transaction T i. (a) (4 points) Draw the precedence graph for schedule 1. Is schedule 1 conflict-serializable? If so, what order of the three transactions defines a conflict-equivalent serial schedule? Schedule 1 R 2 (A) R 1 (C) R 2 (B) W 2 (B) R 3 (B) R 1 (A) R 3 (C) W 3 (C) W 1 (A) Schedule 1 is conflict-serializable because the precedence graph has no cycles. There is an arrow T 2 T 1 because of the conflict R 2 (A)... W 1 (A). There is an arrow T 2 T 3 because of the conflict W 2 (B)... R 3 (B). There is an arrow T 1 T 3 because of the conflict R 1 (C)... W 3 (C). The only possible conflict-equivalent serial schedule is (T 2, T 1, T 3 ) T 1 T 2 T 3 (b) (4 points) Draw the precedence graph for schedule 2. Is schedule 2 conflict-serializable? If so, what order of the three transactions defines a conflict-equivalent serial schedule? Schedule 2 R 2 (A) R 1 (C) R 2 (B) R 3 (B) W 2 (B) R 1 (A) R 3 (C) W 3 (C) W 1 (A) Schedule 2 is not conflict-serializable because the precedence graph has a cycle. There is an arrow T 2 T 1 because of the conflict R 2 (A)... W 1 (A). There is an arrow T 3 T 2 because of the conflict R 3 (B)... W 2 (B). There is an arrow T 1 T 3 because of the conflict R 1 (C)... W 3 (C). T 1 T 2 T 3 11

(c) (9 points) Can the two schedules from (a) and (b) occur under (non-strict) 2 Phase Locking? If yes, then add the proper lock/unlock actions to the corresponding schedule(s) in a way compliant with (non-strict) 2PL. Use L i (X) to denote transaction i locking element X, and U i (X) to denote transaction i releasing the lock on X. Assume only exclusive locks are used, and make sure that no locks remain held at the end of the schedule. The schedules below are the same ones as in the previous page, and repeated here for convenience with dotted spaces in-between the actions. You can use this dotted space to add the proper lock and unlock actions, or if you prefer you can rewrite the schedules including the locking actions in the empty space further down the page. If you believe a schedule cannot occur with 2PL, give a brief explanation. There are many correct answers to this question. As long as each piece of data is locked before used, each lock is not simultaneously held by multiple transactions, and no transaction locks data after it begins unlocking, the answer is correct. Schedule 1 L 2 (A) R 2 (A) L 1 (C) R 1 (C) L 2 (B) R 2 (B) W 2 (B) U 2 (B) U 2 (A) L 3 (B) R 3 (B) L 1 (A) R 1 (A) U 1 (C) L 3 (C) R 3 (C) W 3 (C) U 3 (C) W 1 (A) U 1 (A) U 3 (B) Schedule 2 cannot be produced by 2PL, as it is not conflict-serializable. 12

(d) (5 points) Circle TRUE or FALSE to reflect the validity of the following statements. i. For any schedules S 1 and S 2, if S 1 and S 2 are conflict serializable, then S 1 and S 2 are conflict equivalent. 1 TRUE / FALSE ii. A SIX lock is compatible with IS and IX locks, i.e. if a transaction holds a SIX lock on an object, then another transaction can take an IS or IX lock on the same object. TRUE / FALSE iii. An IX lock is compatible with an IS lock, i.e. if a transaction holds an IS lock on an object, then another transaction can take an IX lock on the same object. TRUE / FALSE iv. Strict 2PL prevents deadlocks. TRUE / FALSE v. In timestamp-based concurrency control, if a transaction gets aborted, it will be restarted with a new timestamp. TRUE / FALSE i. FALSE, ii. FALSE, iii. TRUE, iv. FALSE, v. TRUE 1 Two schedules are conflict equivalent, if every pair of conflicting actions appears in the same order in both schedules. 13

EXTRA PAGE 14