Docsity

Recall - Database Management System | COP 5725, Study notes of Computer Science

Partial preview of the text

Download Recall - Database Management System | COP 5725 and more Study notes Computer Science in PDF only on Docsity!

Recall

‰^

how (design) theory can help us achieve a better database schema ‰^ what the concept of functional dependencies is ‰^ how to check the validity of a functional dependency with respect to a table

What you should have learned after this lecture ...

‰^

what the

Armstrong axioms

are

‰^

what the

closure

+ F

is

‰^

how a

closure

+ F

is computed

‰^

how to determine whether a given FD is contained in the closure of a set of FDs ‰^

what a

canonical cover

of a set of functional dependencies is

‰^

how a

canonical cover

is computed

‰^

Although Armstrong’s axioms are complete, it is comfortable to add three furtherinference rules: −^

union rule

: If

A^
→^

B^ and

A^
→^

C^ holds, then also

A^
→^
B^ ∪
C^

holds.

−^

decomposition rule

: If

A^
→^
B^ ∪
C^

holds, then also

A^
→^

B^ and

A^
→^

C^ holds.

−^

pseudotransitivity rule

: If

A^
→^

B^ and

B^
∪^ C
D^

holds, then also

A^
∪^
C^ →
D

holds. ‰^

example: −^

supplier

relation with the schema

supplier

(sname, saddr, product, price)

−^

Valid FDs: {sname}

{saddr}, {sname, product}

{price}, {sname}

{sname},

{sname, product}

{product}

−^

It is to be shown: {sname, product}

{saddr} is also satisfied.

We have: {sname}

{saddr}.

Due to the augmentation rule we obtain: {sname, product}

{saddr, product}.

Due to the decomposition rule we hence obtain: {sname, product}

{saddr}.

‰^

computing the closure

+ F
+^ F
=^ F

repeat

for each

functional dependency

f^ in

+ F

do

apply reflexivity and augmentation rules to

+ F

add the resulting functional dependencies to

+ F

od

for each

pair of functional dependencies

f^1

and

f^2

in^ F

+^ do

if^ f

and 1

f^2

can be combined using transitivity

then

add the resulting functional dependency to

+ F

fi od

until

+ F

does not change any further

Containment of a FD in a closure

+ F
‰^

question: Let

F^

be a set of FDs and

A^
→^

B^ a FD. Does

A^
→^
B^ ∈
+ F

hold?

‰^

problem: explicit calculation of

+ F

is too expensive

‰^

instead: calculation of the

closure

+ A

of the attribute set

A^

regarding the set

F
−^
+^ A

consists of all attributes that are functionally determined by

A.
−^

If^ B

⊆^
+ A

holds, then also

A^
→^
B^ ∈
+ F

holds.

‰^

algorithm for inferring

+ A

algorithm

AttrClosure

( F ,^
A )

// input: a set

F^

of FDs and a set

A^

of attributes

// output: the complete set

+ A

of attributes for which holds:

A^
→^
+ A
+ A
:=^
A ;

repeat

OldA

+^ =
+ A

foreach

FD
B^
→^
C^ ∈
F^

do

if^ B

⊆^
+^ A

then

+ A
:=^
+ A
∪^
C ;

until

+ A

=^ OldA

+;^ return

+ A

Example

‐^

Compute

Attribute

Closure

Given a relation

R {A,B,C,D,E}

and a set of FDs

F: AB

C

A^ →

D

D

E

AC

B

X^

+XF

A AB B D

X^

+XF

A^

{A,

D,

E}

AB

{A,

B,

C,

D,

E}

(Hence

AB

is^

a^ key)

B^

{B}

D^

{D,

E}

Recall

that

a^

key has

uniqueness and

minimality

properties.

Example

‐^

Compute

Attribute

Closure

Given a relation

R {A,B,C,D,E}

and a set of FDs

F: AB

C

A^ →

D

D

E

AC

B

Attribute

Closure

‰^

Application Areas: query optimization,

AI

, knowledge

compilation, redundant constraint elimination, etc. ‰^

Worst case behavior of our naïve algorithm is quadratic in

the size of F. ‰^

Linear algorithms exist, but are more complicated.

A. Mora, G. Aguilera, M. Enciso, P. Cordero, I. P. del Guzman." A new closure algorithm based in logic: SLFD-Closure versusclassical closures

". I

NTELIGENCIA

A^ RTIFICIAL

Canonical cover ‰^

In general, distinct equivalent sets of FDs exist. Two sets

F^

and

G^

of FDs are called

equivalent

iff^

+^ F
=^ G

+^ holds.

‰^

Definition of equivalence is convincing, because the equality of the closures for

F^ and

G^ implies that the same FDs can be inferred from

F^

and

G.
‰^

For a given set

F^

of FDs there exists a unique closure

+ F
‰^

drawbacks of the closure

+ F
−^

in general very many FDs in

+ F

so that the handling with

+ F

becomes difficult

−^

large redundant set of FDs that has to be checked as consistency tests for data-base modifications ‰^

goal: computation of a most possible small set of FDs which are equivalent to

F
→^

less effort for testing whether a new or updated tuple violates a FD

‰^

Fc^

is called

canonical cover

of a given set

F^

of FDs, if holds:

−^

+Fc

=^
+F
−^

In^ F

there are no FDs c^

A^
→^

B^ where

A^

or^ B

contain

extraneous

attributes, i.e., they

are reduced as much as possible.We cannot omit any attribute on the

left

sides of any FD, otherwise we would

change the semantics: ∀^ a

∈^
A^ : (

Fc^

−^ {
A^ →
B }
∪^
{( A
−^ {

a })

B })
+^ ≠

F^ c

+

Example

:^

schema

supplier

(sname,

saddr,

product,

price)

and

FDs

{sname, product}

{saddr} and {sname, product}

{price}. Can we omit one of

the attributes on the left sides?We cannot omit any attribute on the

right

sides of any FD, otherwise we would

change the semantics: ∀^ b

∈^
B^ : (

Fc^

−^ {
A^ →
B }
∪^
{ A^
→^
( B^
−^ {

b })})

+^ ≠

F^ c

+

−^

Each left side of the FDs in

Fc

occurs only once, i.e.,

if^ A

B^

and

A^
→^

C^ hold, then in

Fc

only the FD

A^
→^
B^ ∪
C^

is used.

‰^

algorithm for computing the canonical cover −^

step 1: For each FD

A^
→^
B^ ∈
F^

perform a

left reduction

: check for all

a^

∈^ A

whether the attribute

a^ is extraneous, i.e., whether

B^ ⊆

AttrClosure

( F ,^
A^ −

{ a

holds. If this is the case, replace

A^
→^

B^ by (

A^ −

{ a

})^ →
B.
−^

step 2: For each remaining FD

A^
→^
B^ ∈
F^

perform the

right reduction

: check for

all^

b^ ∈

B , whether the attribute

b^ is extraneous, i.e., whether

b^ ∈

AttrClosure

( F^
−^ { A
B }
∪^
{ A^
→^
( B^
−^ {

b })},

A )

holds. If this is the case, replace

A^
→^

B^ by

A^
→^
( B^

−^ { b

−^

step 3: Remove the FDs of the form

A^
→^

∅^ which perhaps have been produced in

the previous step. −^

step 4: By using the union rule replace all FDs of the form

A^
→^
B , ...,^1
A^
→^

Bn^

by

A^ →
B^1
∪^
...^ ∪

Bn

‰^

example −^

Given the set

F^
A^ →
B ,
B^
→^
C ,^
A^ ∪
B^
→^
C }.
−^

step 1:

A^
∪^ B
C^

is replaced by

A^
→^

C , because

B^

on the left side is extraneous

( C^

is already functionally dependent from

A^

by the first two FDs).

−^

step 2:

A^
→^

C^ is replaced by

A^
→^

∅, because

C^

on the right side is extraneous.

This results from the fact that

C^

⊆^ AttrClosure

({ A
B ,
B^
→^
C ,^
A^ →
A ).
−^

step 3:

A^
→^

∅^ is removed. We obtain:

Fc

A^ →
B ,
B^
→^
C }.
−^

step 4: Nothing to be done.

Example

– compute

Canonical

Cover

(F

)c

F = {A

B, ABCD

E, EF

G,

EF

H, ACDF

EG}

1.^

Discharging extraneous attribute from LHS of ABCD

E

F1 = {A

B, ACD

E, EF

G, EF

H, ACDF

EG}

2.^

Discharging extraneous attribute E from RHS of ACDF

EG

F2 = {A

B, ACD

E, EF

G, EF

H, ACDF

G}

Discharging extraneous attribute G from ACDF

G

F^3

= {A

B, ACD

E, EF

G, EF

H, ACDF

Ф^

3.^

ACDF

Ф^

is removed. We obtain:

F^4

= {A

B, ACD

E, EF

G, EF

H}

4.^

Applying the union rule on {EF

G, EF

H}, we get:

Fc

= {A

B, ACD

E, EF

GH}

Canonical Cover

‰^

A^ canonical cover

for

F^

is a set of dependencies

Fc

such that

-^

F logically implies all dependencies in F

andc,

-^

Fc^

logically implies all dependencies in F, and

-^

No functional dependency in F

contains an extraneousc

attribute, and

-^

Each left side of functional dependency in F

is uniquec

‰^

In some (vague) sense, it is a

minimal

version of

F

‰^

Read up algorithms to compute

Fc