CSE 344 Midterm. Monday, November 9th, 2015, 9:30-10:20. Question Points Score Total: 70

Similar documents
CSE 344 Midterm. Monday, November 9th, 2015, 9:30-10:20. Question Points Score Total: 70

CSE 344 Midterm. Monday, Nov 4, 2013, 9:30-10:20. Question Points Score Total: 100

CSE 414 Midterm. Friday, April 29, 2016, 1:30-2:20. Question Points Score Total: 100

CSE 344 Midterm. November 9, 2011, 9:30am - 10:20am. Question Points Score Total: 100

CSE 344 Midterm. November 9, 2011, 9:30am - 10:20am. Question Points Score Total: 100

CSE344 Midterm Exam Fall 2016

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

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

CSEP 514 Midterm. Tuesday, Feb. 7, 2017, 5-6:20pm. Question Points Score Total: 150

1 (10) 2 (8) 3 (12) 4 (14) 5 (6) Total (50)

Fundamentals of Database Systems

Introduction to Database Systems CSE 444

Midterm Exam #2 (Version B) CS 122A Spring 2018

Midterm Exam #2 (Version B) CS 122A Spring 2018

CSE 344 Midterm. Wednesday, Oct. 31st, 2018, 1:30-2:20. Question Points Score Total: 100

Announcements. Two typical kinds of queries. Choosing Index is Not Enough. Cost Parameters. Cost of Reading Data From Disk

CSE 344 Midterm Exam

CSE 344 Final Examination

CSE344 Midterm Exam Winter 2017

CSE 414 Final Examination

CSE 344 Midterm Nov 1st, 2017, 1:30-2:20

CSE 344 Midterm. Friday, February 8, 2013, 9:30-10:20. Question Points Score Total: 100

CSE414 Midterm Exam Spring 2018

CSE 344 APRIL 20 TH RDBMS INTERNALS

Score. 1 (10) 2 (10) 3 (8) 4 (13) 5 (9) Total (50)

Introduction to Data Management CSE 344. Lecture 12: Cost Estimation Relational Calculus

CS 564 Final Exam Fall 2015 Answers

Database Systems CSE 414

Midterm Exam #2 (Version C) CS 122A Spring 2018

CSE 414 Midterm. April 28, Name: Question Points Score Total 101. Do not open the test until instructed to do so.

CSE 344 Final Examination

Chapter 12: Query Processing

Query Processing. Debapriyo Majumdar Indian Sta4s4cal Ins4tute Kolkata DBMS PGDBA 2016

CSE 344 MAY 7 TH EXAM REVIEW

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

Where Are We? Next Few Lectures. Integrity Constraints Motivation. Constraints in E/R Diagrams. Keys in E/R Diagrams

CSE 444, Winter 2011, Final Examination. 17 March 2011

CSE 344 Midterm. Monday, February 6, 2012, 9:30-10:20. This is a closed book exam. You have 50. Please write your answers in the space provided.

CSE 544 Principles of Database Management Systems

Fundamentals of Database Systems

CSE 344 Final Examination

Query optimization. Elena Baralis, Silvia Chiusano Politecnico di Torino. DBMS Architecture D B M G. Database Management Systems. Pag.

CPSC 310: Database Systems / CSPC 603: Database Systems and Applications Exam 2 November 16, 2005

Hash table example. B+ Tree Index by Example Recall binary trees from CSE 143! Clustered vs Unclustered. Example

CSE 344 Final Review. August 16 th

Introduction to Database Systems CSE 414. Lecture 26: More Indexes and Operator Costs

University of Waterloo Midterm Examination Sample Solution

Chapter 13: Query Processing

CSE 344 Final Examination

CSE 344 Midterm. Wednesday, Nov. 1st, 2017, 1:30-2:20. Question Points Score Total: 100

University of California, Berkeley. (2 points for each row; 1 point given if part of the change in the row was correct)

CSE 344 JANUARY 19 TH SUBQUERIES 2 AND RELATIONAL ALGEBRA

Examples of Physical Query Plan Alternatives. Selected Material from Chapters 12, 14 and 15

Relational Query Optimization. Highlights of System R Optimizer

Midterm Exam (Version B) CS 122A Spring 2017

Chapter 12: Query Processing. Chapter 12: Query Processing

Administrivia. CS 133: Databases. Cost-based Query Sub-System. Goals for Today. Midterm on Thursday 10/18. Assignments

CS 186, Fall 1999 Midterm 2 Professor Hawthorn

! A relational algebra expression may have many equivalent. ! Cost is generally measured as total elapsed time for

Chapter 13: Query Processing Basic Steps in Query Processing

McGill April 2009 Final Examination Database Systems COMP 421

R & G Chapter 13. Implementation of single Relational Operations Choices depend on indexes, memory, stats, Joins Blocked nested loops:

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

EECS 647: Introduction to Database Systems

CSE 444 Final Exam. August 21, Question 1 / 15. Question 2 / 25. Question 3 / 25. Question 4 / 15. Question 5 / 20.

CSE 544 Principles of Database Management Systems. Magdalena Balazinska Fall 2007 Lecture 7 - Query execution

Database System Concepts

Database Applications (15-415)

Lecture 17: Query execution. Wednesday, May 12, 2010

Query Processing and Query Optimization. Prof Monika Shah

EXAMINATION PAPER. Exam in: INF-2700 Database Systems Date: Thursday Time: Kl 15:00-19:00 Place: Åsgårdveien 9. Approved aids: None

CS 186, Fall 1999 Midterm 2 Professor Hawthorn

CSE 344 Final Exam. March 17, Question 1 / 10. Question 2 / 30. Question 3 / 18. Question 4 / 24. Question 5 / 21.

2.2.2.Relational Database concept

CSE 344 APRIL 27 TH COST ESTIMATION

Introduction to Query Processing and Query Optimization Techniques. Copyright 2011 Ramez Elmasri and Shamkant Navathe

CSE 344 FEBRUARY 21 ST COST ESTIMATION

CPSC 421 Database Management Systems. Lecture 19: Physical Database Design Concurrency Control and Recovery

Midterm Exam #2 (Version A) CS 122A Winter 2017

What happens. 376a. Database Design. Execution strategy. Query conversion. Next. Two types of techniques

Plan for today. Query Processing/Optimization. Parsing. A query s trip through the DBMS. Validation. Logical plan

Announcements. From SQL to RA. Query Evaluation Steps. An Equivalent Expression

Before we talk about Big Data. Lets talk about not-so-big data

Midterm 1: CS186, Spring I. Storage: Disk, Files, Buffers [11 points] cs186-

Database Systems CSE 414

Database Systems CSE 414

CS 222/122C Fall 2017, Final Exam. Sample solutions

Announcements. Agenda. Database/Relation/Tuple. Discussion. Schema. CSE 444: Database Internals. Room change: Lab 1 part 1 is due on Monday

Fundamentals of Database Systems

Query Optimization. Query Optimization. Optimization considerations. Example. Interaction of algorithm choice and tree arrangement.

Course No: 4411 Database Management Systems Fall 2008 Midterm exam

Database Systems Management

DBMS Query evaluation

Advanced Database Systems

CSE 544 Principles of Database Management Systems. Alvin Cheung Fall 2015 Lecture 7 - Query optimization

CSE 190D Spring 2017 Final Exam

Announcement. Reading Material. Overview of Query Evaluation. Overview of Query Evaluation. Overview of Query Evaluation 9/26/17

Midterm 1: CS186, Spring I. Storage: Disk, Files, Buffers [11 points] SOLUTION. cs186-

Implementation of Relational Operations

CSE 414 Final Examination. Name: Solution

Transcription:

CSE 344 Midterm Monday, November 9th, 2015, 9:30-10:20 Name: Question Points Score 1 30 2 30 3 10 Total: 70 This exam is CLOSED book and CLOSED devices. You are allowed ONE letter-size page with notes (both sides). You have 50 minutes; budget time carefully. Please read all questions carefully before answering them. Some questions are easier, others harder. Plan to answer all questions, do not get stuck on one question. If you have no idea how to answer a question, write your thoughts about the question for partial credit. Good luck! 1

1 SQL and Indexing 1. (30 points) Consider the following database for a summer camp: Camper(cid,name) Team(gid,age) Assignment(cid,gid) Relation Camper contains a tuple for each camper with name name and unique id cid. Each tuple in relation Team holds the unique id of a team and the age of the campers assigned to that team. Finally, table Assignment captures the assignments of campers to teams. Primary keys are underlined. (a) (10 points) For each query below, indicate if the query correctly returns the name of all campers who have not yet been assigned to a team. Anywhere between zero and all queries compute the correct answer. Each query is syntactically correct. 1. SELECT C.name FROM Camper C LEFT OUTER JOIN Assignment A ON C.cid = A.cid WHERE A.gid IS NULL 2. SELECT C.name FROM Camper C WHERE C.cid NOT IN (SELECT A.cid FROM Assignment A) 3. SELECT C.name FROM Camper C INNER JOIN Assignment A ON C.cid = A.cid GROUP BY C.cid, C.name HAVING count(*) = 0 Solution: (1) and (2) Page 2

Camper(cid,name) Team(gid,age) Assignment(cid,gid) (b) (10 points) Write a SQL query that computes the number of campers in each age group but only for age groups below 9 years old. Note that multiple teams can have campers with the same age. Solution: The following are two possible solutions: SELECT T.age, COUNT(A.cid) FROM Team T LEFT OUTER JOIN Assignment A ON A.gid = T.gid WHERE T.age < 9 GROUP BY T.age SELECT T.age, COUNT(A.cid) FROM Team T LEFT OUTER JOIN Assignment A ON A.gid = T.gid GROUP BY T.age HAVING T.age < 9 Page 3

Camper(cid,name) Team(gid,age) Assignment(cid,gid) (c) (10 points) Consider the following query. For each index below, indicate if it can potentially speed up the query if it is the only index that exists. SELECT C.name FROM Camper C, Team T, Assignment A WHERE C.cid = A.cid AND T.gid = A.gid AND T.age > 6 1. Index on Camper(cid) 2. Index on Camper(name) 3. Index on Camper(cid,name) 4. Index on Camper(name,cid) 5. Index on Team(gid) 6. Index on Team(age) 7. Index on Team(gid,age) 8. Index on Team(age,gid) Solution: 1. Yes 2. No 3. Yes 4. No 5. Yes 6. Yes 7. Yes 8. Yes Page 4

2 Relational Algebra, Datalog, and Relational Calculus 2. (30 points) Consider the following database schema. Relation Item lists objects with their unique id (oid), category, and price. Relation Gift has one tuple for every person pid that offered a gift to a recipient rid. Gift.oid references Item.oid. Item(oid,category,price) Gift(pid, rid, oid) (a) (10 points) Write a Relational Algebra expression in the form of a logical query plan (i.e., draw a tree) that is equivalent to the SQL query below. SELECT O1.category, MAX(ABS(O1.price - O2.price)) FROM Gift G1, Gift G2, Item O1, Item O2 WHERE G1.pid = G2.rid AND G2.pid = G1.rid AND O1.oid = G1.oid AND O2.oid = G2.oid AND O1.category = O2.category GROUP BY O1.category HAVING count(*) > 5 Page 5

π c3,m σ cnt > 5 γ c3, count(*) -> cnt, max( abs(p3-p4) ) -> m oid=oid3 oid2=oid4 c3=c4 pid=rid2 pid2=rid ρ pid2,rid2,oid2 ρ oid3,c3,p3 ρ oid4,c4,p4 Solution: Gift Gift Item Item Page 6

Item(oid,category,price) Gift(pid, rid, oid) (b) (10 points) Write a Datalog query that returns the identifier of all people who offered or received a ring as a gift but never offered nor received a book. Solution: RingPeople(x) :- Gift(x,,o), Item(o, ring, ) RingPeople(x) :- Gift(,x,o), Item(o, ring, ) BookPeople(x) :- Gift(x,,o), Item(o, book, ) BookPeople(x) :- Gift(,x,o), Item(o, book, ) Answer(x) :- RingPeople(x), NOT BookPeople(x) Page 7

Item(oid,category,price) Gift(pid, rid, oid) Person(pid) (c) (10 points) State what each of the following relational calculus queries computes. (a) P (x) = o. c. p. r. (Person(x) Item(o, c, p) Gift(x, r, o)) (b) P (x) = Person(x) ( o. c. p. (Item(o, c, p) r.gift(x, r, o))) (c) P (x) = Person(x) ( o. r. (Gift(x, r, o) p.gift(p, x, o))) Solution: 1. People who offered an item as a gift. 2. People who offered every single item as a gift. 3. People who offered as a gift only items they received as gift. Page 8

3 Query Evaluation 3. (10 points) (a) (10 points) Describe how a relational database management system (DBMS) evaluates a query. (A) What happens from the moment the DBMS receives a SQL statement in the form of a string to the moment it returns results to the user? More complete answers will receive more points. (B) How does the presence of an index affect what happens? Solution: When a DBMS receives a query string as input, it performs the following actions: 1. Parses the string into an internal format. Checks that the query is syntactically valid, that the table names and attributes names exist, and that the user is authorized to access the given tables. 2. The query is then transformed into a logical query plan and subsequently into a physical query plan. The logical query plan is a relational algebra expression. The physical query plan is a logical query plan with extra information on how to access data from disk (e.g., use an index or not), which algorithm to use for each operator (e.g., use a hash join or a nested loop join), and whether to pipeline results between operators or materialize any intermediate relations to disk. The process of selecting the physical query plan for a query is called query optimization. In a cost-based optimizer, the DBMS selects the physical query plan with the lowest estimated cost. The cost is a function of the estimated number of I/O operations, CPU operations, and network bandwidth when applicable. 3. Finally, the selected query plan is executed by calling open()/next()/close() recursively from the top of the query plan. Results are returned to the application. The presence of an index gives rise to a larger space of possible physical plans to consider. An index can serve to fetch data from disk or it can serve in an index-nested loop join to look up matching tuples. Page 9