正常形式:4 对 5

Normal forms: 4 vs 5

我很难理解 4NF、5NF 以及它们的区别。

这是我向不了解 4/5NF 的人描述的方式(或者,我将如何描述实现它的步骤)。我这样说是因为这将显示我真正理解的内容。

通常,N:N 实体关系应该通过为它们可能的组合加入 table 来实现。如果有 3 个或更多的实体与 N:N 关系相关联,则应慎重考虑:

  1. 更通用(包括)的解决方案是实现一个连接 table,其中包含所有实体作为字段,以及它们的所有组合作为值(行)
  2. 但是,如果这些实体之间的关系不是真正的 每个全元组的情况,而是(一些)的(笛卡尔)积 他们的二元 N:N 关系,然后仔细考虑最小值 需要两个字段的数量 table。
  3. 概括 2,总是喜欢(当然,如果它是正确的)加入 tables 的字段越少越好。显然,如果没有用,请不要创建连接 table。
  4. 区分上述内容的一个有用提示是,当插入完成后,如果您的内心(!)告诉您您正在做冗余或无效的事情,那么您应该选择后面的方法之一。

E1) 维基百科关于 4NF 的页面示例: https://en.wikipedia.org/wiki/Fourth_normal_form

我们有实体 Restaurant、Pizza Variety 和 Delivery Area。我们可以通过一个连接 table 来实现他们的多对多关系,包括所有三个。但是,如果正确地考虑数据,这些三元组只是 2 个 N:N 关系的产物:Restaurant:Pizza 和 Restaurant:Delivery 面积。如果 "A1 Pizza" 餐厅决定将 "Thin Crust" 比萨品种纳入其保留范围,那么我将不得不在 "A1 Pizza" 会感觉 4.redundant,或者只插入特定的送货区域,感觉会 4.invalid,因为没有商店会向送货区域提供更少的品种(或者至少,假设我们的规范是这样说的) ).

E2) 维基百科关于 5NF 的页面示例: https://en.wikipedia.org/wiki/Fifth_normal_form

我们有实体销售员、品牌和类型。我们可以通过一个连接 table 来实现他们的多对多关系,包括所有三个。但是,由于 "the following rule applies" 部分,三元组实际上是可用的 3 个 N:N 关系的(笛卡尔)乘积,因此,正确的方法是有 3 个连接 tables为了它。 "Note how this setup helps to remove redundancy." 部分很像我的 4.th 点。

尽管文章指出 "Also note that the table is in 4NF",但事实是,如果 table 拥有它应有的所有行以覆盖 "following rule",那么就覆盖不了4NF了!对吗?

那么..什么是 E1 和 E2 之间的差异使其中之一成为 4NF,而 其他 5NF 示例?

What is the difference between E1 and E2 which makes one of them a 4NF and the other a 5NF example?

非 4NF 和非 5NF 关系都表现出由于 JD 导致的更新异常; 4NF 表示二进制 JD 没有异常,5NF 表示任何元数的 JD 没有异常。维基百科示例规范化为 4NF 摆脱了二进制 JD——关系是一个有问题的双向连接。 5NF 的规范化摆脱了 3 向 JD——关系是一个有问题的 3 向连接。 (因为它是从 4NF 开始的,所以它不可能有任何有问题的二进制 JD。)


一个关系(值或变量)在 5NF 中,当它可以无损分解的每一种方式(即进入连接回它的投影)(即相应的 JD(连接依赖)保持)组件可以连接以某种顺序返回,其中每个连接的公共列是原始的超级键。 (Fagin 的 PJ/NF 论文的隶属度算法。)4NF 的定义是相同的,只是它可以无损分解为 two 投影的方式很重要(即相应的 JD 是二进制)(即对应的 MVD(多值依赖)成立)。

(这样一个允许的 JD 具有这样的连接序列被称为 "implied by the CKs (candidate keys)"。)

这个想法是,如果我们可以分解成连接回原始的投影,那么我们应该,除了超级键上的连接不会导致任何 problems/anomalies。

当 FD(函数依赖)S -> A 与属性集 R 保持关系时,该关系在 S U {A} & R - {A} 上是无损可分解的。所以 JD {S U {A}, R - {A}} 成立 & MVD S ->> {A} 成立。

来自

Relation Meanings/Predicates

On the other hand, suppose you knew the relation's meaning to the extent that you knew that it holds tuples that make a true statement from a (characteristic) predicate expressible as the conjunction of others, say

    ticket Ticket was submitted by a person with first name Vname
AND there is a person with name Vname Nname
AND ticket Ticket was submitted by a person with last name Nname

Join is designed so that the predicate of its output is the AND of the predicates of its inputs. So you would know to check for whether any corresponding decompositions of the original satisfy the JD (ie whether the relations from the conjuncts are projections of the original) and so to check whether the JD is implied by the original's CKs.

The point of normalization to higher NFs is that a JD holds when a relation's predicate can be expressed as the conjunction of others and their relations are projections of the original, so we can use the simpler separate relations instead, except we might as well JOIN/AND the relations/predicates on pairwise shared CKs because there are still no update anomalies. (If FD {x, ...} -> a holds then a certain MVD holds & a certain binary JD holds and the predicate of the relation can be expressed as ... AND a = f(x, ...).)

区别不是很重要,因为4NF本身并不重要,除非你对数据库设计理论的历史感兴趣。

5NF 要求 table 满足的每个连接依赖关系 (JD) 都必须由 table 的超键隐含。 4NF 只关注多值依赖 (MVD) 的概念,但由于 MVD 总是意味着存在相应的 JD,因此根本不需要关注 4NF。 4NF 存在的历史原因是它恰好首先被发明,然后被 5NF 有效地取代——就像 3NF 被 EKNF/BCNF.

取代一样

两者 维基百科示例:

  1. BCNF 中的 table 开头(整个标题是关键)。
  2. table有冗余。
  3. 引入一个规则,实际上spells-out可以分解table。
  4. 分解 table 删除冗余。
  5. 分解后,投影(新 tables)都在 6NF 中(因此在 5、4、..、1 中)

这就是为什么很难看出区别的原因。唯一真正的区别是在第一种情况 (E1) 中 table 被分解为 两个 投影,而在第二种情况 (E2) 中分解为 三个.

这实际上遵循DB-history。以下内容可能无法准确描述历史事件,但足够接近:
曾几何时,一群 DB-mathematicians 聚在一起喝一杯(会议),其中一个人说:"Hey, look at this: I have a table in BCNF, it has redundancy, it can be decomposed into two projections and the redundancy is gone"。他们:思考、思考、喝酒、数学、更多数学,最终有人定义了一种叫做 多值依赖性 4NF 的东西。他们又喝了几杯,high-five,然后回家。
时间流逝,雪花飘落,融化。他们再次聚在一起,你猜怎么着? "Hey guys, a table in BCNF, but this time it can be decomposed into three projections." 同上冗余。他们又想又喝。最后一个 4NF 定义并没有削减它。数学,数学,思考,喝酒,思考。尤里卡,所以有人提出了加入依赖的概念,5NF诞生了。聚会一直持续到深夜。剩下的就是历史了,从那以后他们一直在混淆每个人的 s@!t。

什么是连接依赖?通俗地讲:如果将关系 R 分解为 N 个投影 (X1 ... XN),然后将这些投影连接回去,则必须得到相同的关系。不应有额外的或缺失的元组(对于列也是如此)。顺便说一句,什么是 多值 依赖?好吧,这是 join dependency 的一个特例——一个 join dependency exactly two components (N=2).

了解规则如何spells-out加入依赖项take a look at this SO Q/A