Relational Database Design

(read 7.1 - 7.3)

Why Some Designs Are Bad

Suppose that instead of relations customer, purchased and flyrod, the flyshop uses a database design with only one relation called purchases.

Purchases-scheme = (name, address, cust-num, flyrod-stock-num, date, manufacturer, length, line-weight)

The relation purchases is equivalent to: customer tex2html_wrap_inline27tex2html_wrap_inline29 purchased tex2html_wrap_inline27tex2html_wrap_inline29 flyrod

Problems associated with this design:

Appropriate decomposition often helps solve problems associated with repitition of information and inability to store information.

Return to Table of Contents

Decomposition

Is more decomposition helpful always helpful?

Decompose flyrod into relations make and model:

make = tex2html_wrap_inline37
model = tex2html_wrap_inline39

If the flyrod relation is:

flyrod
manufacturer length line-weight flyrod-stock-num
G. Loomis 8.5 6 1
Orvis 9.5 9 2
Thomas and Thomas 9.5 3 4

then:

make
flyrod-stock-num manufacturer length
1G. Loomis 8.5
2Orvis 9.5
4Thomas and Thomas 9.5

model
length line-weight
8.5 6
9.5 9
9.5 3

If we want to know the length of the flyrod make with flyrod-stock-num of 3, we need to compute: make tex2html_wrap_inline27tex2html_wrap_inline29 model

flyrod-stock-num manufacturer lengthline-weight
1G. Loomis 8.5 6
2Orvis 9.59
2Orvis 9.5 3
4Thomas and Thomas 9.5 9
4Thomas and Thomas 9.53

Now flyrod-stock-num is no longer a superkey!

Note that flyrod tex2html_wrap_inline45 make tex2html_wrap_inline27tex2html_wrap_inline29 model, but make tex2html_wrap_inline27tex2html_wrap_inline29 model has tuples that are not in flyrod. We no longer know if the flyshop stocks one or two flyrod models. Even though make tex2html_wrap_inline27tex2html_wrap_inline29 model has more tuples than flyrod, we've actually lost information that was contained in the flyrod relation!

A decomposition that results in loss of information is a lossy decomposition (or lossy-join decomposition). A decomposition that does not result in loss of information is a lossless-join decomposition.

Clearly, a database design should not have a lossy decomposition.

Note that if length tex2html_wrap_inline35 line-weight or length tex2html_wrap_inline35 {flyrod-stock-num, manufacturer}, then this decomposition would not be lossy (because all tuples in make tex2html_wrap_inline27tex2html_wrap_inline29 model result from tuples of make and manufacturer that agree on length).

Formally, a set of relation schemes tex2html_wrap_inline67 is a decomposition of a relation scheme R if:

R = tex2html_wrap_inline69

(all attributes of R appear in at least one tex2html_wrap_inline71 )

If r(R), it is always true that:

tex2html_wrap_inline75 tex2html_wrap_inline27tex2html_wrap_inline29 tex2html_wrap_inline81 tex2html_wrap_inline27tex2html_wrap_inline29 ... tex2html_wrap_inline27tex2html_wrap_inline29 tex2html_wrap_inline93

because for any tex2html_wrap_inline95 :

tex2html_wrap_inline97 tex2html_wrap_inline27tex2html_wrap_inline29 tex2html_wrap_inline103 tex2html_wrap_inline27tex2html_wrap_inline29 ... tex2html_wrap_inline27tex2html_wrap_inline29 tex2html_wrap_inline115

The decomposition tex2html_wrap_inline67 of R is a lossless-join decomposition if for all relations r(R) (that is, the relations r satisfy all of the functional dependencies on R),

tex2html_wrap_inline123 tex2html_wrap_inline27tex2html_wrap_inline29 tex2html_wrap_inline81 tex2html_wrap_inline27tex2html_wrap_inline29 ... tex2html_wrap_inline27tex2html_wrap_inline29 tex2html_wrap_inline93

We can test for lossy decompositions as follows. Let tex2html_wrap_inline143 be a decomposition of a relation scheme R with set of functional dependencies F. This decomposition is a lossless-join decomposition if at least one of:

is logically implied by F (i.e., in tex2html_wrap_inline149 ).

Consider a relation scheme:

Cust-purchases-scheme = (name, address, cust-num, flyrod-stock-num, date)

with F = {cust-num tex2html_wrap_inline35 name, address}

If we decompose Cust-purchases-scheme into:

Customer-scheme = (name, address, cust-num)
Purchased-scheme = (cust-num, flyrod-stock-num, date)

then Customer-scheme tex2html_wrap_inline153 Purchased-scheme = {cust-num}

To show that this is a lossless-join decomposition, we need to show cust-num tex2html_wrap_inline35 {name, address, cust-num} or cust-num tex2html_wrap_inline35 {cust-num, flyrod-stock-num, date}

Proof (of cust-num tex2html_wrap_inline35 {name, address, cust-num}):

  1. cust-num tex2html_wrap_inline35 name, adress (given)
  2. cust-num tex2html_wrap_inline35 cust-num (reflexivity)
  3. cust-num tex2html_wrap_inline35 name, address, cust-num (1, 2, union rule)

Thus, this decomposition is a lossless-join decomposition.

Return to Table of Contents