DB06_Algorithms
DB06_Algorithms
Algorithms
FIT
Outline
Functional Dependencies
• To recollect:
• A set of attributes X functionally determines a set of attributes Y if
the value of X determines a unique value for Y.
• Our goal here is to determine the properties of functional
dependencies and to find out the ways of manipulating them.
• IR1, IR2, IR3 form a sound and complete set of inference rules
• These are rules hold and all other rules that hold can be deduced
from these
• The last three inference rules, as well as any other inference rules,
can be deduced from IR1, IR2, and IR3 (completeness property)
Closure
• For example, consider the following relation schema about classes held at a
university in a given academic year.
CLASS ( ClassID, Course#, Instr_name, Credit_hrs, Text, Publisher,
Classroom, Capacity).
• Let F, the set of functional dependencies for the above relation include the
following f.d.s:
FD1: ClassID Course#, Instr_name, Credit_hrs, Text, Publisher, Classroom, Capacity;
FD2: Course# Credit_hrs;
FD3: {Course#, Instr_name} Text, Classroom;
FD4: Text Publisher
FD5: Classroom Capacity
These f.d.s above represent the meaning of the individual attributes and the relationship
among them and defines certain rules about the classes.
Note that each closure above has an interpretation that is revealing about the
attribute(s) on the left-hand-side. The closure of {Classid} + is the entire relation CLASS
indicating that all attributes of the relation can be determined from Classid and hence it
is a key.
• Goals:
• Lossless join property (a must)
• Algorithm 15.3 tests for general losslessness.
• Dependency preservation property
• Observe as much as possible
• Algorithm 15.5 decomposes a relation into BCNF components by
sacrificing the dependency preservation.
• Claim 1:
• It is always possible to find a dependency-preserving decomposition
D with respect to F such that each relation Ri in D is in 3NF.
4. Repeat the following loop until a complete loop execution results in no changes to S
{for each functional dependency X Y in F
{for all rows in S which have the same symbols in the columns corresponding to attributes
in X
{make the symbols in each column that correspond to an attribute in Y be the same in all
these rows as follows:
If any of the rows has an “a” symbol for the column, set the other rows to that same “a”
symbol in the column.
If no “a” symbol exists for the attribute in any of the rows, choose one of the “b” symbols
that appear in one of the rows for the attribute and set the other rows to that same “b”
symbol in the column ;};
};
};
5. If a row is made up entirely of “a” symbols, then the decomposition has the lossless join
property; otherwise it does not.
• Example
Figure 15.1 Nonadditive join test for n-ary decompositions.
(a) Case 1: Decomposition of EMP_PROJ into EMP_PROJ1 and EMP_LOCS fails test.
(b) A decomposition of EMP_PROJ that has the lossless join property.
• Example
Nonadditive join test for n-ary
decompositions. (Figure 15.1)
(c) Case 2: Decomposition of
EMP_PROJ into EMP, PROJECT,
and WORKS_ON satisfies test.
• when some tuples have NULL values for attributes that will be used to
join individual relations in the decomposition that may lead to
incomplete results.
• E.g., see Figure 15.2(a), where two relations EMPLOYEE and
DEPARTMENT are shown. The last two employee tuples—‘Berger’ and
‘Benitez’—represent newly hired employees who have not yet been
assigned to a department (assume that this does not violate any
integrity constraints).
• If we want to retrieve a list of (Ename, Dname) values for all the
employees. If we apply the NATURAL JOIN operation on EMPLOYEE and
DEPARTMENT (Figure 15.2(b)), the two aforementioned tuples will not
appear in the result.
• In such cases, LEFT OUTER JOIN may be used. The result is shown in
Figure 15.2 (c).
• The dangling tuple problem. (a) The relation EMPLOYEE_1 (includes all attributes of
EMPLOYEE from Figure 15.2(a) except Dnum). (b) The relation EMPLOYEE_2 (includes
Dnum attribute with NULL values). (c) The relation EMPLOYEE_3 (includes Dnum
attribute but does not include tuples for which Dnum has NULL values).