补
关系模式
R
(
A
1
,
A
2
,
.
.
.
,
A
n
)
R(A_1, A_2,...,A_n)
R(A1,A2,...,An),
R
R
R上的关系
r
r
r。如果
d
o
m
(
R
)
dom(R)
dom(R)表示关系
R
R
R上所有无组的集合。则:
r
ˉ
=
d
o
m
(
R
)
−
r
\bar{r} = dom(R) -r
rˉ=dom(R)−r
设
R
(
A
,
B
)
,
d
o
m
(
A
)
=
a
1
,
a
2
,
a
3
,
d
o
m
(
B
)
=
b
1
,
b
2
,
r
=
{
(
a
1
,
b
1
)
,
(
a
1
,
b
2
)
,
(
s
2
,
b
1
)
}
R(A,B),dom(A)={a_1,a_2,a_3},dom(B)={b_1,b_2}, r = \{(a1, b1), (a1, b2), (s2, b1) \}
R(A,B),dom(A)=a1,a2,a3,dom(B)=b1,b2,r={(a1,b1),(a1,b2),(s2,b1)}, 则:
r ˉ = { ( a 1 , b 1 ) , ( a 1 , b 2 ) , ( a 2 , b 1 ) , ( a 2 , b 2 ) , ( a 3 , b 1 ) , ( a 3 , b 2 ) } − r 1 = { ( a 2 , b 2 ) , ( a 3 , b 1 ) , ( a 3 , b 2 ) } \begin{aligned} \bar{r} &= \{(a1, b1), (a1, b2), (a2, b1), (a2, b2), (a3, b1), (a3, b2) \} \ - r_1 \\ &= \{(a2, b2), (a3, b1), (a3, b2)\} \end{aligned} rˉ={(a1,b1),(a1,b2),(a2,b1),(a2,b2),(a3,b1),(a3,b2)} −r1={(a2,b2),(a3,b1),(a3,b2)}
有效补
关系模式
R
(
A
1
,
A
2
,
A
3
,
.
.
.
,
A
n
)
R(A_1,A_2,A_3,...,A_n)
R(A1,A2,A3,...,An),属性
A
i
A_i
Ai的有效值域:
a
d
o
m
(
A
i
,
r
)
=
{
d
∣
d
∈
D
i
,
∃
t
∈
r
,
t
[
A
i
]
=
d
}
adom(A_i,r)=\{d|d\in D_i, \exist t \in r, t[A_i] =d \}
adom(Ai,r)={d∣d∈Di,∃t∈r,t[Ai]=d}
定义
r
r
r有效补为:
r
~
=
a
d
o
m
(
A
,
r
)
−
r
\tilde{r} = adom(A,r) - r
r~=adom(A,r)−r
设
R
(
A
,
B
,
C
)
,
d
o
m
(
A
)
=
a
1
,
a
2
,
d
o
m
(
B
)
=
Z
,
d
o
m
(
C
)
=
c
1
,
c
2
R(A,B,C),dom(A)={a_1,a_2},dom(B)=Z,dom(C)={c_1,c_2}
R(A,B,C),dom(A)=a1,a2,dom(B)=Z,dom(C)=c1,c2,
如果 r = { ( a 1 , 1 , c 1 ) , ( a 1 , 2 , c 2 ) , ( a 2 , 1 , c 1 ) , ( a 2 , 2 , c 1 ) , ( a 2 , 3 , c 2 ) } r= \{ (a_1,1,c_1),(a_1,2,c_2), (a_2, 1, c_1), (a_2,2,c_1), (a_2,3,c_2) \} r={(a1,1,c1),(a1,2,c2),(a2,1,c1),(a2,2,c1),(a2,3,c2)}
则:
a
d
o
m
(
A
,
r
)
=
{
a
1
,
a
2
}
a
d
o
m
(
B
,
r
)
=
{
1
,
2
,
3
}
a
d
o
m
(
C
,
r
)
=
{
c
1
,
c
2
}
a
d
o
m
(
R
,
r
)
=
{
(
a
,
b
,
c
)
∣
a
∈
a
d
o
m
(
A
,
r
)
,
b
∈
a
d
o
m
(
B
,
r
)
,
c
∈
a
d
o
m
(
C
,
r
)
}
−
r
=
{
(
a
1
,
1
,
c
2
)
,
(
a
1
,
2
,
c
1
)
,
(
a
1
,
3
,
c
1
)
,
(
a
1
,
3
,
c
2
)
(
a
2
,
1
,
c
2
)
,
(
a
2
,
2
,
c
2
)
,
(
a
2
,
3
,
c
1
)
}
adom(A,r) = \{a_1,a_2\} \\ adom(B,r) = \{ 1,2,3 \} \\ adom(C,r) = \{c_1,c_2\} \\ \begin{aligned} adom(R,r) &= \{(a, b, c) | a \in adom(A,r), b \in adom(B,r), c \in adom(C,r)\} - r \\ &= \{ (a_1, 1, c_2), (a_1, 2, c_1), (a_1, 3, c_1), (a_1, 3, c_2) (a2, 1, c_2), (a_2, 2, c_2), (a_2, 3, c_1) \} \end{aligned}
adom(A,r)={a1,a2}adom(B,r)={1,2,3}adom(C,r)={c1,c2}adom(R,r)={(a,b,c)∣a∈adom(A,r),b∈adom(B,r),c∈adom(C,r)}−r={(a1,1,c2),(a1,2,c1),(a1,3,c1),(a1,3,c2)(a2,1,c2),(a2,2,c2),(a2,3,c1)}
应用:当
∣
r
~
∣
<
∣
r
∣
|\tilde{r}| < |r|
∣r~∣<∣r∣ 可作为数据压缩的方法。
连接
连 接 : R ▹ ◃ S 等 值 连 接 : R [ R . B = S . B ] S t h e t a 连 接 : R [ R . B θ S . C ] S \begin{aligned} 连接&:\ R \triangleright \triangleleft S \\ 等值连接&:\ R[R.B=S.B]S \\ theta连接&:\ R[R.B \ \theta \ S.C ]S \end{aligned} 连接等值连接theta连接: R▹◃S: R[R.B=S.B]S: R[R.B θ S.C]S
其中 θ ∈ { ≥ , > , < , ≤ , = , ≠ } \theta \in \{\ge,\gt, \lt, \le, =, \neq\} θ∈{≥,>,<,≤,=,=}
除法
设关系
r
(
R
)
、
s
(
S
)
,
S
⊆
R
,
R
′
=
R
−
S
r(R)、s(S),S \subseteq R,R'=R-S
r(R)、s(S),S⊆R,R′=R−S, 则:
r
÷
s
=
{
t
∣
t
r
∈
r
,
t
s
∈
s
,
t
=
t
r
(
R
′
)
∨
t
r
(
S
)
=
t
s
,
t
▹
◃
s
⊆
r
}
r \div s= \{ t| t_r \in r,t_s \in s, t = t_r(R') \vee t_r(S) = t_s, t\triangleright \triangleleft s \subseteq r \}
r÷s={t∣tr∈r,ts∈s,t=tr(R′)∨tr(S)=ts,t▹◃s⊆r}