将关系分解为更小的子关系的过程称为分解。 DBMS 需要分解来将关系转换为特定的范式,这进一步减少了关系中的冗余、异常和不一致。
DBMS 中主要有两种类型的分解——
- 无损分解
- 有损分解
无损和有损连接分解的区别:
Lossless | Lossy |
---|---|
The decompositions R1, R2, R2…Rn for a relation schema R are said to be Lossless if there natural join results the original relation R. | The decompositions R1, R2, R2…Rn for a relation schema R are said to be Lossy if there natural join results into additon of extraneous tuples with the the original relation R. |
Formally, Let R be a relation and R1, R2, R3 … Rn be it’s decomposition, the decomposition is lossless if –
|
Formally, Let R be a relation and R1, R2, R3 … Rn be it’s decomposition, the decomposition is lossy if –
|
There is no loss of information as the relation obtained after natural join of decompositions is equivalent to original relation.Thus, it is also referred to as non-additive join decomposition | There is loss of information as extraneous tuples are added into the relation after natural join of decompositions. Thus, it is also referred to as careless decomposition. |
The common attribute of the sub relations is a superkey of any one of the relation. | The common attribute of the sub relation is not a superkey of any of the sub relation. |
示例 1:
示例检查是否给定的 Decomposition Lossless Join Decomposition。
假设有一个关系模式 R(A, B, C)。 R1(A, B) 和 R2(B, C) 是它的分解。
A | B | C |
---|---|---|
a1 | b1 | c1 |
a2 | b1 | c1 |
a1 | b2 | c2 |
A | B |
---|---|
a1 | b1 |
a2 | b1 |
a1 | b2 |
B | C |
---|---|
b1 | c1 |
b1 | c1 |
b2 | c2 |
现在为了分解是无损的,
R1 ⨝ R2 ⨝ R3 .... ⨝ Rn = R
A | B | C |
---|---|---|
a1 | b1 | c1 |
a2 | b1 | c1 |
a1 | b2 | c2 |
R ⊂ R1 ⨝ R2 ⨝ R3 .... ⨝ Rn
这种分解是无损的。
示例 2:
示例检查是否给定的 Decomposition Lossy Join Decomposition。
假设有一个关系模式 R(A, B, C)。 R1(A, B) 和 R2(A, C) 是它的分解。
A | B | C |
---|---|---|
a1 | b1 | c1 |
a2 | b1 | c1 |
a1 | b2 | c2 |
a1 | b3 | c3 |
A | B |
---|---|
a1 | b1 |
a2 | b1 |
a1 | b2 |
a1 | b3 |
A | C |
---|---|
a1 | c1 |
a2 | c1 |
a1 | c2 |
a1 | c3 |
现在分解是有损的,
R1 ⨝ R2 = R then, R1 ⨝ R2 is
A | B | C |
---|---|---|
a1 | b1 | c1 |
a1 | b1 | c2 |
a2 | b1 | c1 |
a1 | b2 | c2 |
a1 | b2 | c1 |
a1 | b3 | c3 |
a1 | b3 | c1 |
As, R1 ⨝ R2 = R,
这种分解是有损的。
因此,我们可以确定分解是无损的还是有损的。