Вы находитесь на странице: 1из 22

Database Systems&Applications Lecture 18 Preserving FD's &Tuple Calculus

A decomposition of a relation R, on which the dependencies F hold, into relations R1and R2 is dependency preserving if:

(FR1 FR2)+ = F+

Where FR1 is the set of dependencies that apply between attributes only in R1 and

similarly FR2 is the set of dependencies that apply between attributes only in R2.

Preserving FD's

Consider a relation (Project,Project-Budget,Department,Dept- Address) with following functional dependencies:

Project-Budget(Project,Project-Budget,Department,Dept- Address) with following functional dependencies: Department Dept-Address Project

Department

Dept-Address

Address) with following functional dependencies: Project-Budget Department Dept-Address Project

Project

Address) with following functional dependencies: Project-Budget Department Dept-Address Project
Address) with following functional dependencies: Project-Budget Department Dept-Address Project
Address) with following functional dependencies: Project-Budget Department Dept-Address Project
Address) with following functional dependencies: Project-Budget Department Dept-Address Project

Preserving FD's

We decompose the PROJECTS relation into two relations on which two corresponding sets of FDs held:

(Project,Project-Budget,Department)

(Department, Dept-Address)

Is it preserving FD’s ?

Relational Calculus

Introduction

Procedural Query language

query specification involves giving a step by step process of obtaining the query result e.g., relational algebra

usage calls for detailed knowledge of the operators involved

difficult for the use of non-experts

Declarative Query language

query specification involves giving the logical conditions the results are required to satisfy

easy for the use of non-experts

Tuple relational Calculus … a DQL

Tuple relational calculus

Calculus has variables, constants, comparison ops, logical connectives and quantifiers.

TRC: Variables range over (i.e., get bound to) tuples.

Like SQL.

• TRC is simple subset a of first-order logic.

Expressions in the calculus are called formulas.

Answer : tuple is an assignment of constants to variables that make the formula evaluate to true.

First-Order Predicate Logic

Predicate: is a feature of language which you can use to make a statement about something, e.g., to attribute a property to that thing.

Peter is tall. We predicated tallness of peter or attributed tallness to peter.

A predicate may be thought of as a kind of function which applies to individuals and yields a proposition.

Proposition logic is concerned only with sentential connectives such as and, or, not.

Predicate Logic, where a logic is concerned not only with the sentential connectives but also with the internal structure of atomic propositions

First order predicate logic

First-order predicate logic, first-order says we consider predicates on the one hand, and individuals on the other; that atomic sentences are constricted by applying the former to the latter; and that quantification is permitted only over the individuals.

First-order logic permits reasoning about propositional connectives and also about quantification.

All men are motal Peter is a man Peter is mortal

Tuple Relational Calculus

Query has the form: {T | p(T)}

p(T) denotes a formula in which tuple variable T appears.

Answer is the set of all tuples T for which the formula p(T) evaluates to true.

Formula is recursively defined:

start with simple atomic formulas (get tuples from relations or make comparisons of values)

build bigger and better formulas using the logical connectives.

TRC Formulas

An Atomic formula is one of the following:

R

R.a op S.b R.a op constant constant op R.a

Rel

op is one of

A formula can be:

an atomic formula

,>,=, , ³,¹

where p and q are formulas where variable R is a tuple variable where variable R is a tuple variable

Øp,pÙq,pÚq

R  (p( R) ) ∃R  ( p( R) )

Free and Bound Variables

• The use of quantifiers

$X

and

X in a formula

is said to bind X in the formula.

– A variable that is not bound is free.

• Let us revisit the definition of a query:

– {T | p(T)}

There is an important restriction

—the variable T that appears to the left of `|’ must be the only free variable in the formula p(T). —in other words, all other tuple variables must be bound using a quantifier.

bid

bname

color

101

Interlake

blue

102

Interlake

red

103

Clipper

green

104

Marine

red

red 103 Clipper green 104 Marine red Boats sid sname rating age 22 Vinod 7 35.0

Boats

sid sname rating age 22 Vinod 7 35.0 29 Deepu 1 33.0 31 Silvia 8
sid
sname
rating
age
22
Vinod
7
35.0
29
Deepu
1
33.0
31
Silvia
8
35.5
32
Jeffrey
8
45.5
58
Kim
10
45.0
64
Kingsley
7
35.0
71
Samulya
10
16.0
74
Victor
9
45.0
85
Kalyan
3
33.5
95
Praveen
3
33.5

Sid

Bid

Day

22

101

10/10/11

22

102

10/10/11

22

103

10/8/11

22

104

10/7/11

31

102

11/10/11

31

103

11/6/11

31

104

11/12/98

64

101

9/5/11

64

102

9/8/11

74

103

9/8/11

Sailors

11/6/11 31 104 11/12/98 64 101 9/5/11 64 102 9/8/11 74 103 9/8/11 Sailors Reserves

Reserves

Selection and Projection

Find all sailors with rating above 7

{S |S Sailors

S.rating > 7}

Find names and ages of sailors with rating above 7.

{P | S1 Sailors(S1.rating > 7 P.sname = S1.sname P.age = S1.age)}

Note, here P is a tuple variable of 2 fields (i.e. {P} is a projection of sailors), since only 2 fields are ever mentioned and P is never used to range over any relations in the query.

Joins

Find sailors rated > 7 who’ve reserved boat #103

{S | S Sailors S.rating > 7

R(R Reserves R.sid = S.sid

R.bid = 103)}

Note the use of

to find a

tuple in Reserves that `joins

with’ the Sailors tuple under consideration.

Joins (continued)

nd sailors rated > 7 who’ve reserved a red bo

{S | S Sailors S.rating > 7 R(R Reserves R.sid = S.sid B(B Boats B.bid = R.bid B.color = ‘red’))}

Division (makes more sense here???)

Find sailors who’ve reserved all boats (hint, use

)

{S | S Sailors B Boats ( R Reserves (S.sid = R.sid B.bid = R.bid))}

Find all sailors S such that for each tuple B in Boats there is a tuple in Reserves showing that sailor S has reserved it.

Division – a trickier example…

Find sailors who’ve reserved all Red boats

{S | S Sailors

B

Boats ( B.color = ‘red’

R(R Reserves S.sid = R.sid B.bid = R.bid))}

Alternatively…

{S | S Sailors

B

Boats ( B.color π ‘red’

R(R Reserves S.sid = R.sid B.bid = R.bid))}

a

T

F

a

b is the same as a

b

b

T F T F T T
T
F
T
F
T
T

If a is true, b must be true for the implication to be true. If a is true and b is false, the implication evaluates to false.

If a is not true, we don’t care about b, the expression is always true.