Midterm 11au
Midterm 11au
Name:
• This exam is open book and open notes but NO laptops or other portable devices.
• 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
CSE 344 Midterm November 9, 2011
• pid is a unique paper identifier and the primary key of the Paper table.
• rid is a unique reviewer identifier and the primary key of the Reviewer table.
• Reviews.rid is a foreign key that references Reviewer.rid.
• Reviews.pid is a foreign key that references Paper.pid.
• A reviewer is assigned zero or more papers.
• A paper is assigned zero or more reviewers.
(a) (15 points) Write a SQL query that finds all papers with fewer than three review-
ers assigned to them. The output of the query should be a list of paper titles. The
result should include papers without any reviewers assigned to them.
Page 2
CSE 344 Midterm November 9, 2011
Paper(pid, title)
Reviewer(rid, name)
Reviews(rid, pid)
(b) (15 points) Write a SQL query that finds the reviewers with the most papers
assigned to them. There can be more than one such reviewer. The output of the
query should be a list of reviewer names. A reviewer should be listed if no other
reviewer has strictly more papers to review.
Page 3
CSE 344 Midterm November 9, 2011
Paper(pid, title)
Reviewer(rid, name)
Reviews(rid, pid)
(c) (10 points) Suggest 2 indexes that would speed-up your queries from the previous
questions. Explain why you are selecting these indexes.
Page 4
CSE 344 Midterm November 9, 2011
Page 5
CSE 344 Midterm November 9, 2011
Neighbors(name1,name2,duration)
Colleagues(name1,name2,duration)
(b) (15 points) Write a Datalog query that returns all neighbors who do not have
any colleagues in common.
Page 6
CSE 344 Midterm November 9, 2011
Neighbors(name1,name2,duration)
Colleagues(name1,name2,duration)
(c) (10 points) Indicate if the following relational calculus queries are correct or not
(true or false). Note: This is not meant to be a tricky question. Errors, if any,
should be reasonably obvious. You do NOT need to correct wrong queries:
TRUE/FALSE
• Find all people who have only neighbors that are also their colleagues.
TRUE/FALSE
• Find all people who have only neighbors that have at least one colleague.
TRUE/FALSE
Page 7
CSE 344 Midterm November 9, 2011
<!DOCTYPE game [
<!ELEMENT game (player*)>
<!ELEMENT player (rank,score)>
<!ATTLIST player name CDATA #REQUIRED >
<!ELEMENT rank (#PCDATA )>
<!ELEMENT score (#PCDATA )>
]>
(a) (20 points) Write an XQuery expression that reformats a valid XML document, as
per the above DTD, into one that matches the following DTD. In this new format,
we want to group “Beginner” players into one category and “Advanced” players
into another category:
<!DOCTYPE game [
<!ELEMENT game (category*)>
<!ELEMENT category (rank, player*)>
<!ELEMENT player (name, score) >
<!ELEMENT rank (#PCDATA )>
<!ELEMENT name (#PCDATA )>
<!ELEMENT score (#PCDATA )>
]>
Answer (write an XQuery):
Page 8