CS122D Spring 2021 Midterm
CS122D Spring 2021 Midterm
Midterm Exam
STUDENT NAME
Instructions
The allowed time for the exam this time will be 80 minutes. Be sure to pay
attention to the time and to budget your exam time accordingly! (Also, don't
forget to periodically save your answers.)
The exam is open pre-prepared cheat sheet, open book, open notes, open
web browser, and even open data platforms. However, you are not allowed to
communicate with or otherwise interact with any other students (or friends)
during the course of the exam, and this includes your HW brainstorming buddy.
This exam is to be a solo effort!
Read each question carefully, in its entirety, and then answer each part of the
question.
If you don't understand something, make your best guess; if you find
ambiguities in a question, note the interpretation that you are taking.
Acknowledgement: I certify that I am taking this exam myself, on my own, with
honesty and integrity, without interaction with others during the exam, and
without having obtained any information about the exam's content from others
prior to taking it.
True
False
A Running Example
This being a database class, we'll need some data for the exam! To that end,
we'll use the following relational schema:
Here is a tiny handful of relational example data for questions involving queries
and/or their results:
Here is the same data in JSON form (e.g., for MongoDB):
NOTE: You needn't need to load any of this data into anything for this exam!
You should be able to look at each question and the sample data and then
answer based on your experience and knowledge. The intent here is for you to
think, applying the principles that you've learned, and not to need to use the
different systems to answer the questions. (You may want to pdf-print or
screen-shot the example data so that you can refer to it in another window
during the exam. Do not do try opening the exam twice in different windows, as
that may end badly if you do a "save" in the wrong window!)
Save Answer
Q2 Executive Briefing
24 Points
Choose the best alternative from among the offered answers to each of the
following questions.
Q2.1
3 Points
Yes
No
Save Answer
Q2.2
3 Points
Consider the following JSON object. If MongoDB were used to store the
sample JSON data from our running example in two collections named
customers and orders, would MongoDB allow the insertion of this object into
orders?
Yes
No
Save Answer
Q2.3
3 Points
Now consider the relational version of our running example. Suppose that the
real data is several TB in size, including 500GB of customer records, and that
the following SQL query must be run frequently:
Suppose the data is currently stored in a parallel RDBMS with 5 nodes. If this
query is currently too slow by a factor of two, and the number of customers is
expected to double by year-end, about how many nodes should the system
aim to have in order to meet the company's storage and speed requirements at
the end of the year?
10
15
20
25
Save Answer
Q2.4
3 Points
Many parallel RDBMSs use parallel hash joins to process large join queries
such as the one in the previous question. What happens when the sizes of the
input tables are such that each node's share of the smaller table is larger than
the amount of main memory available on a node?
Save Answer
Q2.5
3 Points
no index
Save Answer
Q2.6
3 Points
And which indexing choice would likely be best for a SQL query like:
no index
Save Answer
Q2.7
3 Points
True
False
Save Answer
Q2.8
3 Points
main-memory cache
key-value server
document store
grocery store
Save Answer
Q3 SQL Revisited
12 Points
Show what each of the following analytical SQL queries would print (including
the output column names) if they were run against the sample relational tables
from our running example. The exact format of your answer isn't critical;
something like the following CSV-like format would be just fine:
eno,ename,dept,salary
1,"Sue","Software",110000
2,"Fred","Hardware",95000
Q3.1
8 Points
Save Answer
Q3.2
4 Points
Save Answer
An ER model just turned up, and something seems amiss when comparing it to
the sample data. The designers who gave us our running example's sample
data and its schema may have been a little sloppy, perhaps? Let's explore how
the customer information might have ended up looking if it had originated from
a proper ER design process. Suppose that the following ER diagram had
resulted from a first interview with the the data's stakeholders:
Further suppose that their application sometimes needs to ask queries about
all customers, sometimes about just US customers, and sometimes just about
rated customers.
Q4.1
2 Points
Take a careful look at the sample customer data. Its design is actually pretty
close to one of the standard design patterns for translating ER designs
involving inheritance into relational schemas.
union tables
mashup tables
Save Answer
Q4.2
2 Points
One or more columns are missing from the current customers schema in order
to properly capture the ER design and meet the application's query needs.
Use the SQL syntax ALTER TABLE tabname ADD colname coltype; to fix the
problem:
Save Answer
Q4.3
2 Points
Yes
No
Save Answer
Q4.4
3 Points
Look carefully at the sample data. Do all of the sample customers satisfy the
constraints implied by the ER schema? Answer by identifying any/all rows that
are in violation of the ER schema as it's currently specified.
C01
C02
C03
C04
C05
Save Answer
Q4.5
2 Points
Okay, it's time to "use the force" -- i.e., engage your brain and your common
sense. Assume that the sample data is right and that something went wrong
when the initial stakeholder interview transcript was translated into ER form.
Which of the following aspects of the given ER diagram makes the least sense
of all and thus needs to be changed?
custid as primary key
non-optionality of name
disjoint IsA
covering IsA
optionality of rating
optionality of zipcode
Save Answer
Q5 Insistent on Consistent?
12 Points
Q5.1
2 Points
What would the output of the SELECT query be if it were run at time t0, before
any of the updates, instead of at time t3 as shown?
null
2925
3000
3425
3500
4000
Save Answer
Q5.2
4 Points
What could the output of the SELECT query be at time t3 if all of the operations
were done under eventual consistency? E.g., assume that the UPDATEs and the
SELECT are each done at consistency level CL=1 in Cassandra.
null
2925
3000
3425
3500
4000
Save Answer
Q5.3
4 Points
What could the output of the SELECT query be at time t3 if all of the operations
were done under strong consistency? E.g., assume that the UPDATEs and the
SELECT are each done at consistency level CL=ALL in Cassandra.
null
2925
3000
3425
3500
4000
Save Answer
Save Answer
Q5.4
2 Points
Are there any other consistency level choices that the UPDATEs and SELECT
could have used to achieve strong consistency for the SELECT in Cassandra?
Yes
No
Save Answer
We can move this data to Cassandra by appropriately adjusting the data types
(e.g., VARCHAR(40) --> TEXT, INTEGER --> INT, and so on) and removing the
NOT NULL constraints since CQL doesn't support those. Suppose we do that,
keeping the schemas and keys otherwise the same. We could then insert our
sample data, which as a reminder looks as follows:
Now let's consider how Cassandra will respond to some queries with the keys
specified above as well as with some other possible alternatives.
Q6.1
3 Points
Save Answer
Q6.2
3 Points
Save Answer
Q6.3
3 Points
Save Answer
Q6.4
3 Points
Save Answer
Q6.5
8 Points
Save Answer
It's time to make sure your MongoDB knowledge isn't mangled, which means
that the JSON version of our running example will now be the focus:
Suppose that these customers and orders have been loaded into a pair of
MongoDB collections.
Q7.1
5 Points
Which of the following are true statements about MQL's support for joins:
joins are supported in both the find and aggregate MQL APIs
joins work when both argument collections are large and sharded
Save Answer
Q7.2
3 Points
Save Answer
Q7.3
8 Points
Which of the following pymongo MQL snippets would lead Atlas to compute an
output equivalent to what the following SQL query would print:
MQL snippet 2
MQL snippet 3
MQL snippet 4
Save Answer
Q7.4
4 Points
Show the JSON result that would be produced by dumping the cursor from this
MQL snippet using the sample JSON data:
Save Answer