Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 RELATIONAL ALGEBRA EXAMPLE l Consider the query: “Retrieve the names of parts instock at JFK”. l In Relational Algebra, this is  PName  [PartInfo ⋈

Similar presentations


Presentation on theme: "1 RELATIONAL ALGEBRA EXAMPLE l Consider the query: “Retrieve the names of parts instock at JFK”. l In Relational Algebra, this is  PName  [PartInfo ⋈"— Presentation transcript:

1 1 RELATIONAL ALGEBRA EXAMPLE l Consider the query: “Retrieve the names of parts instock at JFK”. l In Relational Algebra, this is  PName  [PartInfo ⋈   Loc=‘JFK’ (Instock)]

2 2 AN EXTENDED EXAMPLE l Let us now see this query performed on these tables. The first step is to perform the selection on Instock where the location is JFK: PINFO: Part# Subpart Of Part Name Part# Subpart Of Part Name 211 0 Coach Seat 211 0 Coach Seat 2114 211 Seat Cover 2114 211 Seat Cover 2116 211 Seat Belt 2116 211 Seat Belt 21163 2116 Seat Belt Buckle 21163 2116 Seat Belt Buckle 21164 2116 Seat Belt Anchor 21164 2116 Seat Belt Anchor 318 21164 Little Bolt 318 21164 Little Bolt 206 0 Overhead Console 206 0 Overhead Console 2061 206 Paging Switch 2061 206 Paging Switch 2066 206 Light Switch 2066 206 Light Switch 2068 206 Air Nozzle 2068 206 Air Nozzle INSTOCK : Part# Location Quantity 211 JFK 106 211 JFK 106 211 Boston 28 211 Boston 28 211 Ohare 77 211 Ohare 77 2114 JFK 6 2114 JFK 6 2114 Ohare 28 2114 Ohare 28 2116 Boston 341 2116 Boston 341 2116 Ohare 29 2116 Ohare 29 21164 Atlanta 36,391 21164 Atlanta 36,391

3 3 AN EXTENDED EXAMPLE l This shows the selection performed on Instock. l Next, perform the natural join of these two tables. PINFO: Part# Subpart Of Part Name Part# Subpart Of Part Name 211 0 Coach Seat 211 0 Coach Seat 2114 211 Seat Cover 2114 211 Seat Cover 2116 211 Seat Belt 2116 211 Seat Belt 21163 2116 Seat Belt Buckle 21163 2116 Seat Belt Buckle 21164 2116 Seat Belt Anchor 21164 2116 Seat Belt Anchor 318 21164 Little Bolt 318 21164 Little Bolt 206 0 Overhead Console 206 0 Overhead Console 2061 206 Paging Switch 2061 206 Paging Switch 2066 206 Light Switch 2066 206 Light Switch 2068 206 Air Nozzle 2068 206 Air Nozzle  loc=‘JFK’ (INSTOCK) : Part# Location Quantity 211 JFK 106 211 JFK 106 2114 JFK 6 2114 JFK 6

4 4 AN EXTENDED EXAMPLE l This shows the result of the natural join. Those elements of the Cartesian product with the same Part# are present here. l Next, perform the projection onto Part Name. PartInfo   Loc=‘JFK’ (Instock) PartInfo ⋈   Loc=‘JFK’ (Instock) Part# Subpart Of Part Name Location Quantity Part# Subpart Of Part Name Location Quantity 211 0 Coach Seat JFK 106 211 0 Coach Seat JFK 106 2114 211 Seat Cover JFK 6 2114 211 Seat Cover JFK 6

5 5 AN EXTENDED EXAMPLE l This shows the final result. It is the projection onto Part Name of the previous relation.  PName  [PartInfo   Loc=‘JFK’ (Instock)]  PName  [PartInfo ⋈   Loc=‘JFK’ (Instock)] Part Name Part Name Coach Seat Coach Seat Seat Cover Seat Cover

6 6 RELATIONAL CALCULUS l Consider the query: “Retrieve the names of parts instock at JFK”. l In symbols, this query is –Px.Pname where  Iy[Px  PartInfo  Iy  Instock  Px.P# = Iy.P#  Iy.loc = ‘JFK’]

7 7 Px.Pname where  Iy[Px.P# = Iy.P#  Iy.loc = ‘JFK’] PINFO: Part# Subpart Of Part Name Part# Subpart Of Part Name 211 0 Coach Seat 211 0 Coach Seat 2114 211 Seat Cover 2114 211 Seat Cover 2116 211 Seat Belt 2116 211 Seat Belt 21163 2116 Seat Belt Buckle 21163 2116 Seat Belt Buckle 21164 2116 Seat Belt Anchor 21164 2116 Seat Belt Anchor 318 21164 Little Bolt 318 21164 Little Bolt 206 0 Overhead Console 206 0 Overhead Console 2061 206 Paging Switch 2061 206 Paging Switch 2066 206 Light Switch 2066 206 Light Switch 2068 206 Air Nozzle 2068 206 Air Nozzle INSTOCK : Part# Location Quantity 211 JFK 106 211 JFK 106 211 Boston 28 211 Boston 28 211 Ohare 77 211 Ohare 77 2114 JFK 6 2114 JFK 6 2114 Ohare 28 2114 Ohare 28 2116 Boston 341 2116 Boston 341 2116 Ohare 29 2116 Ohare 29 21164 Atlanta 36,391 21164 Atlanta 36,391 PxIy IDEA: if the current arrangement of Px and Iy satisfy the formula, then this PX goes into the answer. Pname

8 8 Px.Pname where  Iy[Px.P# = Iy.P#  Iy.loc = ‘JFK’] PINFO: Part# Subpart Of Part Name Part# Subpart Of Part Name 211 0 Coach Seat 211 0 Coach Seat 2114 211 Seat Cover 2114 211 Seat Cover 2116 211 Seat Belt 2116 211 Seat Belt 21163 2116 Seat Belt Buckle 21163 2116 Seat Belt Buckle 21164 2116 Seat Belt Anchor 21164 2116 Seat Belt Anchor 318 21164 Little Bolt 318 21164 Little Bolt 206 0 Overhead Console 206 0 Overhead Console 2061 206 Paging Switch 2061 206 Paging Switch 2066 206 Light Switch 2066 206 Light Switch 2068 206 Air Nozzle 2068 206 Air Nozzle INSTOCK : Part# Location Quantity 211 JFK 106 211 JFK 106 211 Boston 28 211 Boston 28 211 Ohare 77 211 Ohare 77 2114 JFK 6 2114 JFK 6 2114 Ohare 28 2114 Ohare 28 2116 Boston 341 2116 Boston 341 2116 Ohare 29 2116 Ohare 29 21164 Atlanta 36,391 21164 Atlanta 36,391 PxIy Does the Current Px andIy Match? Yes, so Coach Seat goes in the answer Pname Coach Seat

9 9 Px.Pname where  Iy[Px.P# = Iy.P#  Iy.loc = ‘JFK’] PINFO: Part# Subpart Of Part Name Part# Subpart Of Part Name 211 0 Coach Seat 211 0 Coach Seat 2114 211 Seat Cover 2114 211 Seat Cover 2116 211 Seat Belt 2116 211 Seat Belt 21163 2116 Seat Belt Buckle 21163 2116 Seat Belt Buckle 21164 2116 Seat Belt Anchor 21164 2116 Seat Belt Anchor 318 21164 Little Bolt 318 21164 Little Bolt 206 0 Overhead Console 206 0 Overhead Console 2061 206 Paging Switch 2061 206 Paging Switch 2066 206 Light Switch 2066 206 Light Switch 2068 206 Air Nozzle 2068 206 Air Nozzle INSTOCK : Part# Location Quantity 211 JFK 106 211 JFK 106 211 Boston 28 211 Boston 28 211 Ohare 77 211 Ohare 77 2114 JFK 6 2114 JFK 6 2114 Ohare 28 2114 Ohare 28 2116 Boston 341 2116 Boston 341 2116 Ohare 29 2116 Ohare 29 21164 Atlanta 36,391 21164 Atlanta 36,391 Px Iy Does the Current Px and Iy Match? Pname Coach Seat Iy

10 10 Px.Pname where  Iy[Px.P# = Iy.P#  Iy.loc = ‘JFK’] PINFO: Part# Subpart Of Part Name Part# Subpart Of Part Name 211 0 Coach Seat 211 0 Coach Seat 2114 211 Seat Cover 2114 211 Seat Cover 2116 211 Seat Belt 2116 211 Seat Belt 21163 2116 Seat Belt Buckle 21163 2116 Seat Belt Buckle 21164 2116 Seat Belt Anchor 21164 2116 Seat Belt Anchor 318 21164 Little Bolt 318 21164 Little Bolt 206 0 Overhead Console 206 0 Overhead Console 2061 206 Paging Switch 2061 206 Paging Switch 2066 206 Light Switch 2066 206 Light Switch 2068 206 Air Nozzle 2068 206 Air Nozzle INSTOCK : Part# Location Quantity 211 JFK 106 211 JFK 106 211 Boston 28 211 Boston 28 211 Ohare 77 211 Ohare 77 2114 JFK 6 2114 JFK 6 2114 Ohare 28 2114 Ohare 28 2116 Boston 341 2116 Boston 341 2116 Ohare 29 2116 Ohare 29 21164 Atlanta 36,391 21164 Atlanta 36,391 Px Iy Does the Current Px and Iy Match? Pname Coach Seat Iy Seat Cover

11 11 Px.Pname where  Iy[Px.P# = Iy.P#  Iy.loc = ‘JFK’] PINFO: Part# Subpart Of Part Name Part# Subpart Of Part Name 211 0 Coach Seat 211 0 Coach Seat 2114 211 Seat Cover 2114 211 Seat Cover 2116 211 Seat Belt 2116 211 Seat Belt 21163 2116 Seat Belt Buckle 21163 2116 Seat Belt Buckle 21164 2116 Seat Belt Anchor 21164 2116 Seat Belt Anchor 318 21164 Little Bolt 318 21164 Little Bolt 206 0 Overhead Console 206 0 Overhead Console 2061 206 Paging Switch 2061 206 Paging Switch 2066 206 Light Switch 2066 206 Light Switch 2068 206 Air Nozzle 2068 206 Air Nozzle INSTOCK : Part# Location Quantity 211 JFK 106 211 JFK 106 211 Boston 28 211 Boston 28 211 Ohare 77 211 Ohare 77 2114 JFK 6 2114 JFK 6 2114 Ohare 28 2114 Ohare 28 2116 Boston 341 2116 Boston 341 2116 Ohare 29 2116 Ohare 29 21164 Atlanta 36,391 21164 Atlanta 36,391 Px Iy Does the Current Px and Iy Match? Pname Coach Seat Iy Seat Cover


Download ppt "1 RELATIONAL ALGEBRA EXAMPLE l Consider the query: “Retrieve the names of parts instock at JFK”. l In Relational Algebra, this is  PName  [PartInfo ⋈"

Similar presentations


Ads by Google