Relational database design database systems

Chapter VIII database Relational Database Design

Lossy & lossless decomposition decomposition

The quality of a database depends largely on the quality of design ER diagrams

The data table:

Redundant data, and if the teacher is not a department, it is not information indicating the department (dept_name, building, budget)

So we can consider it to decompose:

分解为 teacher(ID,name,salary,dept_name) dept(dept_name,building,budget)

The decomposition can solve the redundancy problem, but if decomposition is always good?

Consider employee (ID, name, street, city, salary) is decomposed into employee1 (ID, name), and employee2 (name, street, city, salary), loss of data relationships will produce. As part of the data will lead to erroneous connection if the presence of the same name, it is natural to connect the two tables, lose some information.

Decomposition lossy lossy decomposition: lossless decomposition referring to a pattern of relationships decomposition, the original model of the relationship between any valid value after the decomposition relations not recover by natural join operations

Decomposition decomposition lossless Lossless : lossless decomposition when referring to the relationship between mode decomposition, the relationship between the original model any valid value after the decomposition relations should be able to recover by the natural join operation

A first domain & atom Paradigm

If the element is not a sub-field unit, the field of atomic (Atomic)

If all the domain attributes of a relational schema R atoms are said to satisfy the relational model of the first paradigm (1NF)

Functional Dependencies

Subset of R K is r (R) of the super-code conditions: in any legal instance relation r (R) is, for all tuples instances r, the total meet t1 and t2: if t1 ≠ t2, the t1 [K] ≠ t2 [K ]. that K different tuples are different, i.e., that uniquely identifies the tuple K

考虑一个关系r(R ),令α∈R且β∈R

  • 对于r(R )的给定实例,该实例满足函数以来α→β的条件是:对实例中的所有元组对,若t1[α]=t2[α],则t1[β]=t2[β]
  • 如果在r(R )的每个合法实例都满足α→β,则该函数依赖在r(R )上成立

(想想函数的定义,α→β,也就是说对于相同的α,映射到的β必须相同,当然对于不同的α,映射的β也可以相同,但是不能够存在相同的α对应的β不同的情况,和函数的定义基本一致)

对于该关系来说,函数依赖A->B不满足,函数依赖A->C是满足的

一些函数依赖是在所有关系中都成立的,称为平凡的(trivial),通常,如果β∈α,则形如α→β的函数依赖是平凡的

BCNF:

具有函数依赖集F的关系模式属于BCNF的条件:对于F+(F的闭包)中所有形如α→β的函数依赖,下面二者至少一项成立:

  • α→β是平凡的函数依赖
  • α是模式R的一个超码

前面提到的关系instr_dept (ID, name, salary, dept_name, building, budget ) 不满足BCNF,因为存在dept_name->budget的函数依赖,而dept_name并不是超码。

如果R是不属于BCNF的一个模式,则存在至少一个α→β,其中α不是超码,则可以用下面两个模式取代R:

  • (α∪β)
  • (R-(β-α))

对于instr_dept (ID, name, salary, dept_name, building, budget ),存在α=dept_name,β={building,budget},使得α→β成立,故将其分解为:(α∪β)={dept_name,building,budget},(R-(β-α))={ID,name,salary,dept_name}

第三范式 3NF

具有函数依赖集F的关系模式属于BCNF的条件:对于F+(F的闭包)中所有形如α→β的函数依赖,下面三者至少一项成立:

  • α→β是平凡的函数依赖
  • α是模式R的一个超码
  • β-α中的每个属性A都包含于R的一个候选码中

很显然,BCNF是比3NF更严格的范式

函数依赖理论

如果给定关系模式r(R ),r(R )的每一个满足F的实例也满足f,则称R上的函数依赖f被r上的函数依赖集F逻辑蕴含。(就是说通过现有的函数依赖可以推导出f,则f实际上也是蕴含在该关系模式中的函数依赖)

F的闭包通常记为F+ ,指的是被F逻辑蕴含的所有函数依赖的集合

Armstrong’s 公理:

  • 自反律:若α为一属性集且β∈α,则α→β成立
  • 增补律:若α→β成立且γ为一属性集,则γα→γβ成立
  • 传递律:若α→β和β→γ成立,则α→γ

Armstrong’s公理的推论:

  • 合并律:若α→β和α→γ成立,则α→βγ
  • 分解率:若α→βγ成立,则α→β和α→γ成立
  • 伪传递律:若α→β和γβ→δ,则αγ→δ成立

求属性集的闭包的例子:

属性闭包的运用:

  • 判断α是否为超码,可以计算α的闭包α+,如果α+包含R中所有元素,则为超码
  • 通过检查是否β∈α+,可以检查α→β是否成立

正则覆盖 Canonical Cover:

无关属性:如果去除函数依赖中的一个属性不改变该函数依赖集的闭包,则称该属性为无关的。

无关属性的形式定义:考虑函数依赖集F及F中的函数依赖α→β

  • 如果A∈α并且F逻辑蕴含(F-{α→β})∪{(α-A)→β},则属性A在α中是无关的

  • 如果A∈β并且函数依赖集(F-{α→β})∪{α→(β→A)}逻辑蕴含F,则属性A在β中是无关的

    (也就是说,把A在该函数依赖中去掉后,F+并不变,则A为无关属性)

例如:假如F中有AB->C和A->C,则B在AB->C中是无关的,因为A->C可以推出AB->C

检验一个属性在α->β是否无关,通常考虑的是,将该属性从α->β中去除,然后看剩下的函数依赖是否可以推出原α->β,或者直接查看去掉该元素后的α或者β的闭包是否可以包含该元素

计算函数依赖集的正则覆盖:

F的正则覆盖Fc与F具有相同的闭包

正则覆盖未必是唯一的

在这里插入图片描述

无损分解

R1和R2是R的无损分解,如果以下函数依赖中至少有一个属于F+:

  • R1∩R2->R1
  • R1∩R2->R2

也就是R1∩R2是R1或R2的超码,R上的分解就是无损分解

分解算法

BCNF分解:

检查是否满足BCNF分解:

  • 检查非平凡的函数依赖α->β是否违反BCNF,可以计算α的属性闭包,验证其是否包含所有属性,即验证它是否是R的一个超码
  • 检查关系模式是否属于BCNF,仅须检查给定集合F中的函数依赖是否违反BCNF即可,不用检查F+中所有的函数依赖,但是如果一个关系分解后,就不能用此方法。

为了检查R分解后的关系R是否属于BCNF:

  • 对于Ri中属性的每个子集α,确保α的属性闭包要么不包含Ri-α的任何元素,要么包含Ri的所有元素

BCNF分解算法:需要注意的是这是一个无损分解

3NF分解算法:

在这里插入图片描述

多值依赖

令r(R )为一关系模式,并且α∈R且β∈R。多值依赖α->->β在R上成立的条件是,在关系r(R )的任意合法实例中,对于r中任意一对满足t1[α]=t2[α]的元组对t1和t2,r中都存在t3和t4,使得

  • t1[α] = t2 [α] = t3 [α] = t4 [α]
  • t3[β] = t1 [β]
  • t3[R – β] = t2[R – β]
  • t4 [β] = t2[β]
  • t4[R – β] = t1[R – β]

在这里插入图片描述

  • 若α->β,则α->->β
  • 若α->->β,则α->->R-α-β

第四范4NF

函数依赖和多值依赖集为D的关系模式r(R )属于第四范式(4NF)的条件是,对D+中所有形如α->->β的多值依赖,下面二者至少一项成立:

  • α->->β是一个平凡的多值依赖
  • α是R的一个超码

4NF模式一定属于BCNF

实际上就4中范式的冗余度而言:

4NF<BCNF<3NF<1NF

4NF分解算法:

在这里插入图片描述

发布了68 篇原创文章 · 获赞 36 · 访问量 1万+

Guess you like

Origin blog.csdn.net/dingdingdodo/article/details/102777933