lt18-preservefd
-
Upload
haneesha-muddasani -
Category
Documents
-
view
215 -
download
0
Transcript of lt18-preservefd
-
7/29/2019 lt18-preservefd
1/22
Database Systems&ApplicationsLecture 18Preserving FD's &Tuple Calculus
-
7/29/2019 lt18-preservefd
2/22
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 attributesonly in R1 and
similarly FR2 is the set of dependencies that apply between attributes
only in R2.
-
7/29/2019 lt18-preservefd
3/22
Preserving FD's
Consider a relation (Project,Project-Budget,Department,Dept-Address) with following functional dependencies:
Project-Budget
Project Department
Dept-Address
-
7/29/2019 lt18-preservefd
4/22
We decompose the PROJECTS relation into two relations on whichtwo corresponding sets of FDs held:
(Project,Project-Budget,Department)
(Department, Dept-Address)
Is it preserving FDs ?
Preserving FD's
-
7/29/2019 lt18-preservefd
5/22
Relational Calculus
-
7/29/2019 lt18-preservefd
6/22
Introduction
Procedural Query language
query specification involves giving a step bystep process of obtaining the query resulte.g., relational algebra
usage calls for detailed knowledge of the
operators involved
difficult for the use of non-experts
-
7/29/2019 lt18-preservefd
7/22
Declarative Query language
query specification involves giving the logicalconditions the results are required to satisfy
easy for the use of non-experts
-
7/29/2019 lt18-preservefd
8/22
Tuple relational Calculus ..aDQL
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.
-
7/29/2019 lt18-preservefd
9/22
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.
-
7/29/2019 lt18-preservefd
10/22
First-Order Predicate Logic
Predicate: is a feature of language which you can useto make a statement about something, e.g., toattribute a property to that thing.
Peter is tall. We predicated tallness of peter or attributedtallness to peter.
A predicate may be thought of as a kind of function whichapplies to individuals and yields a proposition.
Proposition logic is concerned only with sententialconnectives such as and, or, not.
Predicate Logic, where a logic is concerned not only
with the sentential connectives but also with the
-
7/29/2019 lt18-preservefd
11/22
First order predicate logic
First-order predicate logic, first-order says we considerpredicates on the one hand, and individuals on theother; that atomic sentences are constricted byapplying the former to the latter; and that quantificationis permitted only over the individuals.
First-order logic permits reasoning about propositionalconnectives and also about quantification.
All men are motal
Peter is a man
Peter is mortal
-
7/29/2019 lt18-preservefd
12/22
Tuple Relational Calculus
Queryhas the form: {T|p(T)}
p(T)denotes a formula in which tuple variable Tappears.
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.
-
7/29/2019 lt18-preservefd
13/22
TRC FormulasAn Atomic formula is one of the following:
R RelR.aopS.b
R.aopconstant
constantop R.aop is one of
Aformula 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,pq,pq
R
( p(R )
)
R ( p (R ) )
-
7/29/2019 lt18-preservefd
14/22
Free and Bound Variables
The use of quantifiers and in a formulais said to bindX in the formula. A variable that is not bound is free.
Let us revisit the definition of a query: {T|p(T)}
$XX
There is an important restriction
the variable Tthat appears to the left of `|must be the onlyfree variable in the formulap(T).
in other words, all other tuple variables mustbe bound using a quantifier.
-
7/29/2019 lt18-preservefd
15/22
bid bname color
101 Interlake blue
102 Interlake red
103 Clipper green
104 Marine red
sid sname rating age
22 Vinod 7 35.0
29 Deepu 1 33.031 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
Boats 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
ReservesSailors
-
7/29/2019 lt18-preservefd
16/22
Selection and Projection
Find all sailors with rating above 7
{S |S Sailors S.rating > 7}
-
7/29/2019 lt18-preservefd
17/22
Find names and ages of sailors with ratingabove 7.
{P | S1 Sailors(S1.rating > 7P.sname = S1.snameP.age = S1.age)}
Note, here P is a tuple variable of 2 fields (i.e. {P} is
a projection ofsailors), since only 2 fields are evermentioned and P is never used to range over anyrelations in the query.
-
7/29/2019 lt18-preservefd
18/22
Find sailors rated > 7 whove reserved boat #103
{S | SSailors S.rating > 7
R(RReserves R.sid= S.sid
R.bid = 103)}
Joins
Note the use of
to find atuple in Reserves that `joinswith the Sailors tuple underconsideration.
-
7/29/2019 lt18-preservefd
19/22
Joins (continued)
d sailors rated > 7 whove reserved a red b
{S | S
Sailors
S.rating > 7R(RReserves R.sid = S.sid
B(BBoats B.bid = R.bid B.color = red))}
-
7/29/2019 lt18-preservefd
20/22
Division (makes more sense here???)
Find all sailors S such that for each tuple B in Boatsthere is a tuple in Reserves showing that sailor Shas reserved it.
Find sailors whove reserved all boats
(hint, use )
S | SSailors
BBoats (RReserves(S.sid = R.sid B.bid = R.bid))}
-
7/29/2019 lt18-preservefd
21/22
Division a trickier example
{S | SSailors B Boats ( B.color = red R(RReserves S.sid = R.sid
B.bid = R.bid))}
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
-
7/29/2019 lt18-preservefd
22/22
a b is the same as a b
If a is true, b must be true for theimplication to be true. If a istrue and b is false, theimplication evaluates to false.
If a is not true, we dont careabout b, the expression isalways true.
a
T
F
T F
b
T
T T
F