Sie sind auf Seite 1von 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,DeptAddress) with following functional dependencies:

Project-Budget Project Department Dept-Address

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 FDs ?


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

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:
ystart with simple atomic formulas (get tuples from relations or make comparisons of values) ybuild bigger and better formulas using the logical connectives.

TRC Formulas
An Atomic formula is one of the following:
R Rel R.a op S.b R.a op constant constant op R.a

op is one of A formula can be:


an atomic formula

,>,=,, ,
where p and q are formulas

R (p ( R)) R ( p ( R))

p,pq,pq where variable R is a tuple variable


where variable R is a tuple variable

Free and Bound Variables


The use of quantifiers $Xand is said to bind X in the formula.
{T | p(T)}
X

in a formula

Let us revisit the definition of a query:


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.

A variable that is not bound is free.

bid 101 102 103 104


sid
22 29 31 32 58 64 71 74 85 95

bname Interlake Interlake Clipper Marine


sname
Vinod Deepu Silvia Jeffrey Kim Kingsley Samulya Victor Kalyan Praveen

color blue red green red


rating
7 1 8 8 10 7 10 9 3 3

Boats

Sid 22 22 22 22 31 31 31 64 64 74

Bid 101 102 103 104 102 103 104 101 102 103

Day 10/10/11 10/10/11 10/8/11 10/7/11 11/10/11 11/6/11 11/12/98 9/5/11 9/8/11 9/8/11

age
35.0 33.0 35.5 45.5 45.0 35.0 16.0 45.0 33.5 33.5

Sailors

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 whove reserved boat #103 {S | SSailors S.rating > 7 R(RReserves 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 whove reserved a red bo


{S | SSailors S.rating > 7 R(RReserves R.sid = S.sid B(BBoats B.bid = R.bid B.color = red))}

Division (makes more sense here???)


Find sailors whove reserved all boats (hint, use )

{S | SSailors BBoats ( RReserves (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 whove reserved all Red boats {S | SSailors B Boats ( B.color = red R(RReserves S.sid = R.sid B.bid = R.bid))} Alternatively {S | SSailors B Boats ( B.color red R(RReserves S.sid = R.sid B.bid = R.bid))}

a b is the same as a b
b T F

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.
F

T a

If a is not true, we dont care about b, the expression is always true.

Das könnte Ihnen auch gefallen