0% found this document useful (0 votes)
33 views3 pages

Post-Class Assignment Transactions

Uploaded by

A Crazy Chipmunk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views3 pages

Post-Class Assignment Transactions

Uploaded by

A Crazy Chipmunk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Post-class assignment

(Transactions)

You will need to submit this assignment through Gradescope. The assignment will be
autograded, and you can submit as many times as you wish before the deadline. The last
submission is the one that will count, so make sure it contains all your responses.

Important note: The autograder uses the standard notation of start transaction,
commit, and rollback. It will not recognize other notations, such as begin and end. Please
use the standard notation. (You do not have to worry about this for the Java code.)

Assume the following schema for a database of a video rental store:

RentalPlans(pid, name, max_movies, fee)


Customers(cid, login, password, fname, lname, pid)
MovieRentals(mid, cid, status)

RentalPlans contains information on the available plans the Video Store offers to their
customers; they have a plan id (pid), a name for the plan, a maximum number of movies
a customer with that plan can rent (max movies), and the monthly cost of the plan (fee).
Customers contains information on customers; customer id, login and password informa-
tion, first and last names, and finally, the rental plan the customer is signed up for (pid).
MovieRentals records the movie ids (mid) that a customer (cid) has rented, and their status,
which can be open or closed. Open means the movie is currently rented out to the customer,
whereas closed means it has been returned.

1. Q1: Write a transaction that increases the fee of the prime plan by 1 dollar and reduces
the fee of the basic plan by 1 dollar. Submit the necessary statements in file Q1.sql.

1
CMPSCI 345 Post-class assignment Transactions

2. Q2: Multiple users and applications may access and modify the customer database con-
currently. Suppose that one application, operating on Machine 1, updates the RentalPlans
table with the following code:

update RentalPlans
set max_movies=100
where name=‘rental plus’;

select * from RentalPlans;

(a) Write a statement that, when executed concurrently on a different machine, e.g.,
Machine 2, may cause Machine 1 to experience a lost update. Submit your statement in
file Q2a.sql.

(b) Rewrite the code for Machine 1 so that the lost update problem does not happen, no
matter what might be executed on Machine 2. Submit the revised code in file Q2b.sql.

3. Q3: There are two machines, Machine 1 and Machine 2, working on the customer
database at the same time. Machine 1 updates the RentalPlans table with the fol-
lowing code:

start transaction;

update RentalPlans
set fee=19.99
where name = ‘basic’;

update RentalPlans
set fee=29.99
where name = ‘prime’;

commit;

Write a transaction that contains 2 update statements that, when executed concurrently
on Machine 2, may cause a deadlock. Submit your answer as a query in file Q3.sql.

Page 2
CMPSCI 345 Post-class assignment Transactions

4. Q4: Complete the sentence: When you set a transaction’s isolation level to REPEAT-
ABLE READ

1. that transaction is not allowed to write data that has been read by other transac-
tions.
2. that transaction will see the same result if it repeats the same SELECT query.
3. that transaction will be given priority compared to other transactions.
4. all other transactions need to wait for this transaction to finish.

Format your answer in a query as follows:

SELECT answer

where answer is 1, 2, 3, or 4, e.g., SELECT 1. Submit your answer as a query in file


Q4.sql.

5. Q5: Complete step 10 of this week’s activity sheet. Your goal is to implement the
fastsearch functionality in the provided Query.java. The provided starter code already
contains placeholders for where your code should go. Make sure that you compile and
test your code locally; Gradescope is not a development or debugging environment. The
autograder will test both the output of your method and its speed. Make sure that your
fastsearch function formats its output information in the same manner as the regular
search function. It is normal for the autograder to take a few minutes to complete its
evaluation. If it is taking much longer, likely your fastsearch is not fast.
Submit your revised Query.java.

Important note: The autograder times the performance of your code to evaluate Q5.
Occasionally, some steps may run a bit slower than normal for unknown reasons, which
could potentially cause an autograder test to fail when it shouldn’t. If you find that your
code passes at least one test for Q5 (especially test 1 or test 3, which are the hardest),
but fails in others, it may be worthwhile to simply re-run the autograder. When in
doubt, please contact us through Piazza.

Page 3

You might also like