Late Penalty:
Submission:
COMP643 Advanced Database Management Assignment 2
Work not received by the due time incurs an immediate penalty of up to 25% of the marks available. No work will be accepted after Sunday 26th May 2024 5:00 p.m.
via COMP643 on LEARN
Part 1 – Transaction Management and Concurrency Control (60 points)
Agri Markets sell products to customers. The relational diagram in Figure 1 represents the main entities for Agri’s database.
Figure 1- The Agri Markets Entity Relationship Diagram (ERD)
Note the following important characteristics:
• A customer may make many purchases, each one represented by an invoice.
o The cus_balance is updated with each credit purchase or payment and represents
the amount the customer owes.
o The cus_balance is increased (+) with every credit purchased and decreased (-) with
every customer payment.
o The date of last purchase (cus_datelstpur) is updated with each new purchase made
by the customer.
o The date of the last payment (cus_datelstpmt) is updated with each payment made
by the customer.
Note: Q1.
An invoice represents a set of products purchased by a customer.
o An Invoice can have many invoice lines, one for each product purchased.
o The inv_total represents the total cost of the invoice including taxes.
o The inv_terms can be “30”, “60”, or “90” (representing the number of days of credit)
or “cash” or “cheque” or “cc”.
o Theinv_statuscanbe“open”,“paid”or“cancel”.
A product’s quantity on hand (p_qtyoh) is updated (decreased) with each product sale. A customer may make many payments. The payment type (pmt_type) can be one of the following:
o “cash” for cash payments.
o “cheque” for cheque payments.
o “cc” for credit card payments.
The payment details (pmt_details) are used to record data about check or credit card payments.
o The bank, account number, and cheque number for cheque payments.
o The issuer, credit card number, and expiration date for credit card payments.
Not all entities are represented in this example. Use only the attributes indicated.
Using this database, write the SQL code to represent each of the following transactions. Use
BEGIN TRANSACTION to group the SQL statements in logical transactions. (10 points)
-
On 20 Apr 2024, customer 10010 makes a credit purchase (60 days) of two units of product 23109-HB with a unit price of $9.95 and one unit of product WR3-TT3 with a unit price of $119.95. The tax rate is 10%. The invoice number is 20001, and this invoice has two product lines.
-
On 5 May 2024, customer 10010 makes a payment of $100 in cash. The payment ID is 5001.
Create a simple transaction log (using the format shown in Lecture 9) to represent the actions and transactions in Q1a. (10 points)
Using the two-phase locking protocol, create a chronological list of locking, unlocking and data manipulation activities that would occur during the complete processing of the transaction described in Q1a. (10 points)
For the following schedule, assume that the shared locks are requested immediately before each read operation, and exclusive locks are requested before every write operation. Unlocks occur immediately after the COMMIT statement.
Q2. Q3.
Q4.
Step
1 2 3 4 5 6 7 8
T1
Read(X)
Write(Y) COMMIT
T2
Write(Y) Write(X)
COMMIT
T3
Write(Y)
COMMIT
2|Page
-
Add lock and unlock requests (using shared/exclusive locks) and explain why this schedule will cause a deadlock. You will need to rewrite the schedule to show the lock and unlock requests. (10 points)
-
Assume that the timestamp for transaction T(i) is i, explain how this deadlock will be handled using wait/die and wound/wait schemes. (10 points)
Q5. Given the concurrent transactions shown in Figure 2. At time 9, a crash occurred.
Figure 2- Timeline of Concurrent Transactions
-
Describe in detail the database recovery process using the deferred-write technique for each transaction (5 points).
-
Describe in detail the database recovery process using the write-through technique for each transaction (5 points).
3|Page
Part 2 – Database Performance Tuning and Query Optimisation (40 points)
The following relational database schema is used to keep track of customer orders for roses at Lincoln Rose Farm:
Customer (cust_num, cust_name, cust_city, cust_balance) Orders (order_num, cust_num, order_date, order_total) Orderline (line_num, order_num, prod_num, line_qty, line_total) Product (prod_num, prod_desc, prod_price, prod_qoh)
The following SQL query is used to select all customers from Christchurch with a balance greater than 0 who have ordered “Ausblush” rose.
SELECT cust_name
FROM (((customer
INNER JOIN orders on customer.cust_num = orders.cust_num)
inner join orderline on orders.order_num = orderline.order_num)
inner join product on orderline.prod_num = product.prod_num)
where product.prod_desc = "Ausblush"
and customer.cust_city = "Christchurch"
and customer.cust_balance > 0.00;
Assume:
-
There are 10 customers, 10 products, 10 orders, and 22 order lines.
-
“Ausblush” has been ordered 7 times.
-
There are 6 customers who are based in “Christchurch” who has ordered “Ausblush”.
-
There are 5 customers who are based in “Christchurch” and who has a balance greater than
0.00 who has ordered “Ausblush”.
-
There is only one product with prod_desc equals to “Ausblush”.
-
Q1. Create two alternative access plans and show their respective I/O costs using the example table shown in Week 10 Lecture. (20 points)
-
Q2. You have been asked to optimise the performance of the query.
-
a) Identify and describe what indexes should be created and why? (10 points)
-
b) Revise your access plan and the I/O cost for the selected plan from Q1 assuming the indexes you have identified are applied. (10 points)
-
4|Page
Part 3 – Database Security (20 points)
Q1. In Part 2, the database schema is used to process orders for roses. Orders are handled by the sales office. There are currently five staff in this office. Carol, the supervisor, needs to be able to see and update everything. Lim, Jane, and Billy do most of the routine work. They can add, update, and delete orders. They can view existing customers, but they cannot create new customers. Mina is a temporary staff member. She can process orders (add, update, and delete). For customer records, she is only allowed to view the cust_num and cust_name. Large orders above $1000 can only be handled by Carol and Billy.
-
What privileges should be granted to Carol with respect to the four tables? Explain your answer. (6 points)
-
List the privileges should be granted to Lim, Jane, and Billy. (4 points)
-
What privileges should be granted to Mina? (2 points)
-
What additional privileges do you need to grant Carol and Billy so that only these two can handle large orders above $1000. How do you ensure that the rest of the staff are not able to handle large orders? (5 points)
-
What steps do you need to take to ensure that the privileges are set correctly? (3 points)
5|Page