-
The previous example might seem to suggest that we should decompose schema
as much as possible.
Careless decomposition, however, may lead to another form of bad design.
-
Consider a design where Lending-schema is decomposed into two schemas
Branch-customer-schema = (bname, bcity, assets, cname)
Customer-loan-schema = (cname, loan#, amount)
-
We construct our new relations from lending by:
branch-customer =
customer-loan =
Figure 7.2: The decomposed lending relation.
-
It appears that we can reconstruct the lending relation by performing
a natural join on the two new schemas.
-
Figure 7.3 shows what we get by computing
branch-customer customer-loan.
Figure 7.3: Join of the decomposed relations.
-
We notice that there are tuples in branch-customer
customer-loan that are not in lending.
-
How did this happen?
- The intersection of the two schemas is cname,
so the natural join is made on the basis of equality in the cname.
- If two lendings are for the same customer, there will be four
tuples in the natural join.
- Two of these tuples will be spurious - they will not appear
in the original lending relation, and should not appear in the database.
- Although we have more tuples in the join,
we have less information.
- Because of this, we call this a lossy or lossy-join
decomposition.
- A decomposition that is not lossy-join is called a lossless-join
decomposition.
- The only way we could make a connection between branch-customer
and customer-loan was through cname.
-
When we decomposed Lending-schema into Branch-schema
and Loan-info-schema, we will not have a similar problem.
Why not?
Branch-schema = (bname, bcity, assets)
Branch-loan-schema = (bname, cname, loan#, amount)
- The only way we could represent a relationship between tuples in
the two relations is through bname.
- This will not cause problems.
- For a given branch name, there is exactly one assets value and branch
city.
-
For a given branch name, there is exactly one assets value and exactly
one bcity; whereas a similar statement
associated with a loan depends on the customer,
not on the amount of the loan (which is not unique).
-
We'll make a more formal definition of lossless-join:
-
In other words, a lossless-join decomposition is one in which, for any
legal relation r, if we decompose r and then ``recompose'' r, we
get what we started with - no more and no less.