[英]BCNF decomposition algorithm explanation
I looked in Decomposing a relation into BCNF answers and tried it on my homework, but i don't get the correct answers, so i ask for help in BCNF decomposition 我看了将一个关系分解为BCNF答案,并在作业中进行了尝试,但是我没有得到正确的答案,所以我寻求BCNF分解的帮助
Consider R=(ABCDEG)
& F={BG->CD, G->A, CD->AE, C->AG, A->D}
. 考虑
R=(ABCDEG)
& F={BG->CD, G->A, CD->AE, C->AG, A->D}
。
I start pick A->D
. 我开始选择
A->D
Now i got S=(AD), R'=(ABCEG).
现在我得到
S=(AD), R'=(ABCEG).
I pick G->A
. 我选择
G->A
Now i got S=(AD,AG) R'=(BCEG)
. 现在我得到
S=(AD,AG) R'=(BCEG)
。
I pick C->G
. 我选择
C->G
Now i think i need to get S=(AD,AG,CG)
and R'=(BCE)
, But the answer in the end is (AD,AG,CGE,BC)
.what went wrong? 现在我认为我需要得到
S=(AD,AG,CG)
和R'=(BCE)
,但是最后的答案是(AD,AG,CGE,BC)
。出了什么问题? or perhaps, a better algorithm? 还是更好的算法?
To convert a relation R
and a set of functional dependencies( FD's
) into 3NF
you can use Bernstein's Synthesis . 要将关系
R
和一组功能依赖项( FD's
)转换为3NF
,可以使用Bernstein的Synthesis 。 To apply Bernstein's Synthesis - 应用伯恩斯坦综合-
FD's
is a minimal cover FD's
集是最小覆盖范围 FD
and make it its own sub-schema. FD
并使其具有自己的子模式。 For example in your case: 例如,在您的情况下:
R = {A,B,C,D,E,G} R = {A,B,C,D,E,G}
FD's = {BG->CD,G->A,CD->AE,C->AG,A->D} FD = {BG-> CD,G-> A,CD-> AE,C-> AG,A-> D}
First we check whether the FD's
is a minimal cover ( singleton right-hand side , no extraneous left-hand side attribute, no redundant FD ) 首先,我们检查
FD's
是否为最小覆盖率( 单例右侧,无多余左侧属性,无冗余FD )
D
from LHS of CD->A
and CD->E
since D
is an extraneous attribute here (As we can get D
from C
since C->A and A->D ). D
从LHS CD->A
和CD->E
自D
是这里的外来属性(如我们可以得到D
从C
因为C-> A和A-> d)。 So we now have {BG->C, BG->D, G->A, C->A, C->E, C->G, A->D} Second we make each FD
its own sub-schema. 其次,我们使每个
FD
都有自己的子模式。 So now we have - ( the keys for each relation are in bold ) 现在我们有了-( 每个关系的键都以粗体显示 )
R 1 ={ B,G ,C} R 1 = { B,G ,C}
R 2 ={ G ,A} R 2 = { G ,A}
R 3 ={ C ,E} R 3 = { C ,E}
R 4 ={ C ,G} R 4 = { C ,G}
R 5 ={ A ,D} R 5 = { A ,D}
Third we see if any of the sub-schemas can be combined. 第三,我们看是否可以组合任何子模式。 We see that R 3 and R 4 can be combined as they have the same key.
我们看到R 3和R 4可以组合,因为它们具有相同的键。 So now we have -
所以现在我们有-
S 1 = {B,G,C} S 1 = {B,G,C}
S 2 = {A,G} S 2 = {A,G}
S 3 = {C,E,G} S 3 = {C,E,G}
S 4 = {A,D} S 4 = {A,D}
This is in 3NF . 这是在3NF中 。 Now to check for BCNF we check if any of these relations (S 1 ,S 2 ,S 3 ,S 4 ) violate the conditions of BCNF ( ie for every functional dependency
X->Y
the left hand side ( X
) has to be a superkey ) . 现在检查BCNF我们检查是否有任何这些关系(S 1,S 2,S 3,S 4)的违反BCNF的条件( 即对于每个函数依赖
X->Y
左手侧( X
) 必须 超级钥匙 )。 In this case none of these violate BCNF and hence it is also decomposed to BCNF . 在这种情况下,这些都没有违反BCNF ,因此也分解为BCNF 。
Note My final answer above is (AD,AG,CGE,BCG)
. 注意我上面的最终答案是
(AD,AG,CGE,BCG)
。 The solution you expect is (AD,AG,CGE,BC)
but that's wrong. 您期望的解决方案是
(AD,AG,CGE,BC)
但这是错误的。 The last relation here (S 1 ) should also have the G
attribute as shown above. 如上所示,此处的最后一个关系(S 1 )也应具有
G
属性。
Give input: A relation R0 with set (Minimal) of FD's S0. 给定输入:关系R0与FD的S0设置为(最小值)。
Output : A decomposition of R into a collection of relations, all of which are in BCNF 输出:R分解为关系的集合,所有关系都在BCNF中
Algo: R <- R0, and S <- S0 Repeat till R is in BCNF. 算法:R <-R0,S <-S0重复直到R在BCNF中。 If there is a FD X -> Y that violates BCNF condition.
如果存在FD X-> Y违反BCNF条件。 Compute {X}+ , and choose {X}+ as one relation as R1, and another R2 as {(R - X + ) UX} Map FD set S on R1 and R2 (determine FDs on R1 and R2).
计算{X} +,并将{X} +作为一个关系选择为R1,将另一个R2选择为{(R-X +)UX}将FD集S映射到R1和R2上(确定R1和R2上的FD)。 Recursively repeat the algo on R1 and R2.
递归地在R1和R2上重复该算法。
Rule: 1.Should be attribute preserving. 规则:1.应保留属性。 2.Should be lossless 3.Should be FD preserving
2.应该无损3.应该保留FD
Example: R(xyz) FD xy -> z; key : xy z-> y;
例如:R(xyz)
FD xy -> z; key : xy z-> y;
FD xy -> z; key : xy z-> y;
Solve: z-> y violet the BCNF condition. 解决:z-> y紫表示BCNF条件。
So decompose relation R {z}+= yz; R1(yz) where key is z and R2(xz) key is x
因此分解关系R
{z}+= yz; R1(yz) where key is z and R2(xz) key is x
{z}+= yz; R1(yz) where key is z and R2(xz) key is x
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.