Operators for a Relational Data Model
description
Transcript of Operators for a Relational Data Model
![Page 1: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/1.jpg)
Operators for a Relational Data Model
Matt DubeDoctoral Student, Spatial Information Science and Engineering
![Page 2: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/2.jpg)
Monday’s Class Mathematical definitions that underlie the relational
data model: Domain: set of inputs for a particular attribute Type: structure of the members of that set Cartesian Product: combination of members of one
set with every member of another set…and another…and another
Relation: subset of the Cartesian product of the attribute domains
Key: unique identifying attributes for a relation
![Page 3: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/3.jpg)
Discussion of Assignment
Think of an example in your particular discipline where a relational data model might be helpful.
What are the attributes?
What are their domains?
What would you key the database with?
Why?
![Page 4: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/4.jpg)
Stepping Up from Relations
Having only useful data was a motivating concern for us
How do we go about that?Operators are the critical component that
allows us to transform a relational database of large size to one which is more manageable
There are six of these operators to be concerned with
![Page 5: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/5.jpg)
ProjectionProjection is the first of the operatorsMathematical example:
Projection is the “shadow” of a vector of any sort onto a lower dimensional surface.
Think of a right triangle: the lower leg is always shorter than the hypotenuse (why?)
Projection thus represents only considering certain attributes of interest
![Page 6: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/6.jpg)
Projection ExampleWhat is the projection here?
Dimensional reduction (Z coordinate removed)
![Page 7: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/7.jpg)
Notationπ< pertinent attributes > (R)
New relation is thus a subset of a different space
That different space is a component of the original domain
![Page 8: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/8.jpg)
Table ProjectionName Major Schoo
lGende
rAndrew ECE UMain
eM
Guillaume
GIS UMaine
M
Valeryia ECO UMaine
F
Lisa GIS UMaine
F
Eric BUA UMaine
M
Chris SIE UMaine
M
Name GenderAndrew M
Guillaume MValeryia F
Lisa FEric M
Chris M
![Page 9: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/9.jpg)
Problem with Projection What dictates the usefulness of a projection?
Is the key involved?
What if a key isn’t involved?
If the key isn’t involved, duplicates are removed to preserve relation status = missing data!
Order not important…attributes can be listed in any order in the projection function (analogous to rotation)
![Page 10: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/10.jpg)
SelectionSelection is the second operator, and is the
converse of projectionMathematical example:
Intersections in a Venn DiagramSelection takes a list of specific properties and
find things which satisfy that list
![Page 11: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/11.jpg)
Selection ExampleWhat is the selection here?
What do these foxy ladies want to wear today?
![Page 12: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/12.jpg)
Notationσ< selection criteria > (R)
New relation is thus a subset of the original relation
![Page 13: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/13.jpg)
Table SelectionName Major Schoo
lGende
rAndrew ECE UMain
eM
Guillaume
GIS UMaine
M
Valeryia ECO UMaine
F
Lisa GIS UMaine
F
Eric BUA UMaine
M
Chris SIE UMaine
M
Name Major
School
Gender
Andrew ECE UMaine
M
Valeryia ECO UMaine
F
Eric BUA UMaine
M
Chris SIE UMaine
M
![Page 14: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/14.jpg)
Properties of SelectionSelection is in the same application space as
the original relationKey structure is thus the sameSelection is associative
Associativity: Being able to interchange the groupings Addition and multiplication are associative
operators you are familiar with already
![Page 15: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/15.jpg)
RenamingRenaming is the third operatorMathematical example:
Equivalent termsCompact = Closed and Bounded
Renaming is used when combining relationsWhy would that be potentially necessary?
Notation for this is ρ attribute / attribute (R)
![Page 16: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/16.jpg)
Cartesian ProductWe went over this a bit mathematically, but
now we are going to apply it to relations themselves
Mathematical Example: The X,Y Plane (or the X,Y,Z space, or any other
similar type of space)Take all possible combinations of relation
records between 2 or more relations
![Page 17: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/17.jpg)
Cartesian Product Example
What is this a Cartesian Product of?
Truth values for P, Q, and R
P Q RT T TT T FT F TT F FF T TF T FF F TF F F
PTF
PTF
QTF
RTF
![Page 18: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/18.jpg)
Cartesian ProductName PetGeorge Fluffy
Karl Rover
State CityDelaware DoverOregon Corvallis
Name Pet State CityGeorge Fluffy Delawar
eDover
Karl Rover Delaware
Dover
George Fluffy Oregon CorvallisKarl Rover Oregon Corvallis
![Page 19: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/19.jpg)
Properties of a Cartesian Product
How big will a Cartesian Product be? Treat this generally:
Relation R has x rows and y columns Relation S has z rows and w columns
R x S has x * z rows and y + w columns Why? The key of a Cartesian product needs to involve at least
one attribute from both R and S. Why?
![Page 20: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/20.jpg)
UnionUnion is the fifth operatorMathematical Example:
Addition of positive integers is a natural union Addition of sets
Union thus takes relations and binds them together
![Page 21: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/21.jpg)
Union ExampleWhat is this a union of?
The 50 States and Puerto Rico and the Virgin Islands
![Page 22: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/22.jpg)
What does a Union have?
Unioned attributes always have identical domains Why?
Do unioned attributes have to have identical names? No Think of unioning two sets together. Did those sets have the
same names? Unions are commutative
Commutativity: Changing the order is irrelevant Addition and multiplication are commutative operators Difference between this and associativity?
![Page 23: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/23.jpg)
Commutative vs. Associative
![Page 24: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/24.jpg)
DifferenceDifference is the sixth and final operatorMathematical example:
Subsets
Difference produces a subset not in common
![Page 25: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/25.jpg)
Difference ExampleWhat is the difference here?
![Page 26: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/26.jpg)
Unary and N-ary Operators
Unary operators only have one operand (in this case they only involve one relation)
Projection, Selection, RenamingN-ary operators involve N operands (in this
case they involve N relations)Cartesian Product, Union, DifferenceCan you classify the six?
![Page 27: Operators for a Relational Data Model](https://reader035.fdocuments.in/reader035/viewer/2022062301/56816133550346895dd08aa3/html5/thumbnails/27.jpg)
FridayDeriving relations and operators in our first
order languagesCombinations of relations JoinsAlgebras