some relational operators intersection –result are all those tuples that are present in both of...

19
Some relational operators • intersection – result are all those tuples that are present in both of the “input” relations Married couples Bob Mary Jim Debbie Janice Tom Fayetteville Residents Jim Debbie Frank Joan Fred Elaine Intersection Jim Debbie

Upload: charlotte-walker

Post on 13-Dec-2015

214 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Some relational operators intersection –result are all those tuples that are present in both of the “input” relations Married couples Bob Mary Jim Debbie

Some relational operators

• intersection– result are all those tuples that are present in

both of the “input” relationsMarried couplesBob MaryJim DebbieJanice Tom

Fayetteville ResidentsJim DebbieFrank JoanFred Elaine

IntersectionJim Debbie

Page 2: Some relational operators intersection –result are all those tuples that are present in both of the “input” relations Married couples Bob Mary Jim Debbie

UnionMarried couplesBob MaryJim DebbieJanice Tom

Fayetteville ResidentsJim DebbieFrank JoanFred Elaine

UNIONBob MaryJim DebbieJanice TomFrank JoanFred Elaine

Page 3: Some relational operators intersection –result are all those tuples that are present in both of the “input” relations Married couples Bob Mary Jim Debbie

DifferenceMarried couplesBob MaryJim DebbieJanice Tom

Fayetteville ResidentsJim DebbieFrank JoanFred Elaine

DIFFERENCEBob MaryJanice Tom

Page 4: Some relational operators intersection –result are all those tuples that are present in both of the “input” relations Married couples Bob Mary Jim Debbie

Join

• parcel, owner• PARCEL(Parcel_ID, SIZE, Use, ETC…, Owner-ID)• OWNER(Owner-ID, Last_name, First_name, Street,

Town, ZIP)• JOIN• 123 240 acres, agricultural, Jones, Bob, Main,

Weddington, 23456• 567 1 acre, residential, Smith, Bill, College,

Fayetteville, 72701

Page 5: Some relational operators intersection –result are all those tuples that are present in both of the “input” relations Married couples Bob Mary Jim Debbie

Cartesian product• Important term “Cartesian product”

– results when two (or more) relations are “joined”

– see example on page 481– important concept because can be the

unexpected result of a join operation

Page 6: Some relational operators intersection –result are all those tuples that are present in both of the “input” relations Married couples Bob Mary Jim Debbie

Suppose we have our parcel data base

• owner table, parcel table etc.

• we wish to have list of all owned parcels

• suppose we have 4 owners and 6 parcels

• we could have a Cartesian product that had 24 “parcel owner” tuples even though there are only six parcels

Page 7: Some relational operators intersection –result are all those tuples that are present in both of the “input” relations Married couples Bob Mary Jim Debbie

Relational Projection

• selection of particular single attribute (COLUMNS) from a relation

• OWNER(Owner-ID, Last_name, First_name, Street, Town, ZIP)

• PROJECT Last_name– Smith

– Jones

– Brown

Page 8: Some relational operators intersection –result are all those tuples that are present in both of the “input” relations Married couples Bob Mary Jim Debbie

Restriction aka selection

• selection of particular tuples (ROWS) based on a criteria or condition– parcels larger than 200 acres

• the condition is called a predicate

Page 9: Some relational operators intersection –result are all those tuples that are present in both of the “input” relations Married couples Bob Mary Jim Debbie

Division

• given two tables • Desired_Land_USE(land-use) - where land use is

agriculture and timber• PARCEL(Parcel_ID, SIZE, Use, ETC…, Owner-

ID)• DIVISION

– result those parcels where Use is either agriculture or timber

Page 10: Some relational operators intersection –result are all those tuples that are present in both of the “input” relations Married couples Bob Mary Jim Debbie

Different operations

• can be grouped by – whether they operate on tuples or attributes

• all ate tuples except for projection

– how many relations they involve• single relation

– conditional selection

– restriction

– projection

• multiple relations (2..N)– joins

• binary - two relations– all others

Page 11: Some relational operators intersection –result are all those tuples that are present in both of the “input” relations Married couples Bob Mary Jim Debbie

Normalization• can be viewed essentially as the reduction of repetition in relations

– ex:• Not normalized

– PARCELS(Parcel-ID, Owner, Size,….» 123 SMITH 200» 123 JONES 200» 123 BROWN» 345 WATER» 555 WHITE

• Normalize– PARCEL(Parcel-ID, Size, Etc, ….– OWNER(Last_name, First_Name, Parcel-ID, etc…)

• Fully Normalized– PARCEL(Parcel-ID, Size, etc….)– OWNERSHIP(Parcel-ID, Owner-ID)– OWNERS(Owner-ID, Last_name, First_name, …..)

Page 12: Some relational operators intersection –result are all those tuples that are present in both of the “input” relations Married couples Bob Mary Jim Debbie

For spatial data

• Non-normalized spatial data– POLYGON(Polygon-ID,Segment-ID)

– COORD(Segment_ID,Start-X, Start-Y, End-X, End-Y)

– Example– Segment Start-X, Start-Y, End-X, End-Y

– 1 2 2 3 5

– 2 3 5 4 2

– 3 4 2 2 2

• What if we want to edit file and change location of one vertex?

• We must be sure to edit two records

Page 13: Some relational operators intersection –result are all those tuples that are present in both of the “input” relations Married couples Bob Mary Jim Debbie

Normalized spatial data– POLYGON(Polygon-ID,Segment-ID)– SEGMENT(Segment-ID, Start-point-ID, End-point-ID)– COORDS(Point-ID, X, Y)– SEGMENTS

• Segment-ID Start-point-ID End-point-ID

• 1 11 12

• 2 12 13

• 3 13 11

– COORDS• Point-ID X Y

• 11 2 2

• 12 3 5

• 13 4 2

Page 14: Some relational operators intersection –result are all those tuples that are present in both of the “input” relations Married couples Bob Mary Jim Debbie

Structured query language in geomatics

• SELECT <attribute list>

• FROM <table list>

• WHERE <condition>

Page 15: Some relational operators intersection –result are all those tuples that are present in both of the “input” relations Married couples Bob Mary Jim Debbie

Parcel Database Structure

Page 16: Some relational operators intersection –result are all those tuples that are present in both of the “input” relations Married couples Bob Mary Jim Debbie

Obtain addresses of neighbors of Anne

Page 17: Some relational operators intersection –result are all those tuples that are present in both of the “input” relations Married couples Bob Mary Jim Debbie

The SQL statement

Page 18: Some relational operators intersection –result are all those tuples that are present in both of the “input” relations Married couples Bob Mary Jim Debbie

Perimeter of Ann’s parcel• SELECT A.Parcel-ID• SUM(SQR ((D.X -E.X) * (D.X - E.X) + (D.Y - E.Y) * (D.Y -

E.Y)))• FROM OWNERS-PARCEL A, PARCEL-SEGMENT B,

SEGMENT-ENDPOINTS C, COORDINATES D, COORDINATES E

• WHERE A.Owner_name = ‘Ann”• AND A.Parcel-ID = B.Parcel-ID• AND B.Segment-ID = C.Segment-ID• AND C.Point1-ID = D.Point-ID• AND C.Point2-ID = E.Point-ID

Page 19: Some relational operators intersection –result are all those tuples that are present in both of the “input” relations Married couples Bob Mary Jim Debbie

Address of Parcel 345• SELECT Street-ID

• FROM PARCEL_SEGMENT, STREET-SEGMENT

• WHERE Parcel-ID = 345

• AND PARCEL-SEGMENT.Segment-ID = STREET-SEGMENT.Segment-ID

• SELECT Street-Name

• FROM PARCEL_SEGMENT, STREET-SEGMENT, STREET

• WHERE Parcel-ID = 345

• AND PARCEL-SEGMENT.Segment-ID = STREET-SEGMENT.Segment-ID

• AND STREET-SEGMENT.Street-ID = STREET.Street-ID