Figure P6.8b The Dependency Diagram for Problem 8b

HW2 (75 PTS)
Deadline: This HW is due through the assignments tab on Blackboard by 11:59 PM on 11/30/2014.
NORMALIZATION
7. (16 pts) The dependency diagram in Figure Q6.7 indicates that authors are paid royalties for
each book that they write for a publisher. The amount of the royalty can vary by author, by
book, and by edition of the book.
Figure Q6.7 Book royalty dependency diagram
a. Based on the dependency diagram, create a database whose tables are at least in 2NF,
showing the dependency diagram for each table.
The normalization results are shown in Figure Q6.7a.
Figure Q6.7a The 2NF normalization results for Question 7a.
1
b. Create a database whose tables are at least in 3NF, showing the dependency diagram for
each table.
The normalization results are shown in Figure Q6.7b.
Figure Q6.7b The 3NF normalization results for Question 7b.
2
3. (24 pts) Using the INVOICE table structure shown in Table P6.3, do the following:
Table P6.3 Sample INVOICE Records
Attribute Name
INV_NUM
PROD_NUM
SALE_DATE
PROD_LABEL
Sample Value
211347
AA-E3422QW
15-Jan-2014
Rotary sander
VEND_CODE
VEND_NAME
QUANT_SOLD
PROD_PRICE
211
NeverFail, Inc.
1
$49.95
Sample Value
211347
QD-300932X
15-Jan-2014
0.25-in. drill
bit
211
NeverFail, Inc.
8
$3.45
3
Sample Value
211347
RU-995748G
15-Jan-2014
Band saw
Sample Value
211348
AA-E3422QW
15-Jan-2014
Rotary sander
Sample Value
211349
GH-778345P
16-Jan-2014
Power drill
309
BeGood, Inc.
1
$39.99
211
NeverFail, Inc.
2
$49.95
157
ToughGo, Inc.
1
$87.75
a. Write the relational schema, draw its dependency diagram and identify all dependencies,
including all partial and transitive dependencies. You can assume that the table does not
contain repeating groups and that any invoice number may reference more than one
product. (Hint: This table uses a composite primary key.)
The solutions to both problems (3a and 3b) are shown in Figure P6.3a.
b. Remove all partial dependencies, write the relational schema, and draw the new
dependency diagrams. Identify the normal forms for each table structure you created.
NOTE
You can assume that any given product is supplied by a single vendor but a vendor can
supply many products. Therefore, it is proper to conclude that the following dependency
exists:
PROD_NUM → PROD_DESCRIPTION, PROD_PRICE, VEND_CODE, VEND_NAME
(Hint: Your actions should produce three dependency diagrams.)
Figure P6.3a The Dependency Diagrams for Problems 3a and 3b
4
c. Remove all transitive dependencies, write the relational schema, and draw the new
dependency diagrams. Also identify the normal forms for each table structure you created.
To illustrate the effect of Problem 3's complete decomposition, we have shown Problem 3a's
dependency diagram again in Figure P6.3c.
Figure P6.3c The Dependency Diagram for Problem 3c
5
8. (15 pts) Use the dependency diagram shown in Figure 6.8 to work the following problems.
FIGURE P6.8 Initial Dependency Diagram for Problem 8
A
B
C
D
E
F
G
a.
Break up the dependency diagram in Figure 6.8 to create two new dependency
diagrams, one in 3NF and one in 2NF.
The dependency diagrams are shown in Figure P6.8a.
Figure P6.8a The Dependency Diagram for Problem 8a
A
D
3 NF
A
B
C
E
F
G
Transitive dependency
Note that this is not a transitive dependency,
because C does not determine another non-key
Attribute value. Instead, C determines the value
of a key attribute.
6
2 NF
b. Modify the dependency diagrams you created in Problem 8a to produce a collection of
dependency diagrams that are all in 3NF. (Hint: One of your dependency diagrams will be
in 3NF, but not in BCNF.)
The solution is shown in Figure P6.8b.
Figure P6.8b The Dependency Diagram for Problem 8b
c. Modify the dependency diagrams in Problem 8b to produce a collection of dependency
diagrams that are all in 3NF and BCNF.
The solution is shown in Figure P6.8c. Note that the A, C, and E attributes in the first three
structures can be used as foreign keys in the fourth structure.
Figure P6.8c The Dependency Diagrams for Problem 8c
TRANSACTION RECOVERY AND CONCURRENCY CONTROL
1. (4 pts) Remember that in the optimistic approach to concurrency control, the assumption is
that conflict is unlikely, so no precautionary measures are taken. This issue is only dealt with
in the validation phase. Given this, why might it take a long time to complete transactions
when an optimistic approach to concurrency control is used?
Because the optimistic approach makes the assumption that conflict from concurrent transactions is
unlikely, it does nothing to avoid conflicts or control the conflicts. The only test for conflict occurs
during the validation phase. If a conflict is detected, then the entire transaction restarts. In an
environment with few conflicts from concurrency, this type of single checking scheme works well.
In an environment where conflicts are common, a transaction may have to be restarted numerous
times before it can be written to the database.
2. A) (4 pts) Consider the following schedule:
T1
T2
7
Begin transaction
Read_item(customer ‘A’)
Write_item(customer ‘A’)
Begin transaction
Read_item(customer ‘A’)
Read_item(order ‘123’)
Write_item(order ‘123’)
What occurs for i) wait-die and ii) wound-wait?
Since T1 begins before T2, it has an earlier timestamp. Therefore, for the wait-die scheme, T2,
which is younger will be rolled back (possibly multiple times), until T1 finishes, and it can finally
acquire the needed lock. For wound-wait, T2 would wait until T1 finishes and then acquire the
needed lock.
B) (4 pts) Now, consider the following schedule:
T1
T2
Begin transaction
Begin transaction
Read_item(customer ‘A’)
Write_item(customer ‘A’)
Read_item(customer ‘A’)
Read_item(order ‘123’)
Write_item(order ‘123’)
What occurs for i) wait-die and ii) wound-wait?
Since T2 begins before T1, it has an earlier timestamp. Therefore, for the wait-die scheme, T2,
which is older, would wait until T1 finishes and then acquire the needed lock. For wound-wait, T2
would “wound” (i.e., force the rollback) of T1, and acquire the needed lock.
DATABASE TUNING
3. (4 pts) Give an example of one kind of query that will benefit from an index and another which
will not benefit from an index. Note I do not need the sql code – you can simply state in English
what the query does, and which index would be/ would not be useful in that context.
For example, a sum query over column such as sum(quantity) would not be speeded up by an index
over the quantity column, since all rows do have to be gone over. Alternatively a query such as
selecting a particular product (for example, select product_name where product_id = 1001) would
get speeded up if there is an index on product_id.
4. (4 pts) Consider the following query. Which columns would you recommend indexing and
why?
SELECT P_CODE, P_DESCRIPT, P_QOH, P_PRICE, V_CODE
8
FROM PRODUCT
WHERE V_CODE = ‘21344’
ORDER BY
P_CODE;
This query uses one WHERE condition and one ORDER BY clause. The conditional expression
uses the V_CODE column in an equality comparison. In this case, creating an index on the
V_CODE attribute is recommended. If V_CODE is declared to be a foreign key, the DBMS may
already have created such an index automatically. If the DBMS does not generate the index
automatically, create one manually.
The ORDER BY clause uses the P_CODE column. Create an index on the columns used in an
ORDER BY is recommended. However, because the P_CODE column is the primary key of the
PRODUCT table, a unique index already exists for this column and therefore, it is not necessary to
create another index on this column.
9