1 / 8

Relational Algebra & Calculus

Relational Algebra & Calculus. Chapter 4, Part A (Relational Algebra) Query Formulation Exercise. Exercises. Given relational schema: Sailors (sid, sname, rating, age) Reservation (sid, bid, date) Boats (bid, bname, color) Find names of sailors who’ve reserved boat #103

corina
Download Presentation

Relational Algebra & Calculus

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra) Query Formulation Exercise

  2. Exercises Given relational schema: Sailors (sid, sname, rating, age) Reservation (sid, bid, date) Boats (bid, bname, color) • Find names of sailors who’ve reserved boat #103 • Find names of sailors who’ve reserved a red boat • Find sailors who’ve reserved a red or a green boat • Find sailors who’ve reserved a red and a green boat • Find the names of sailors who’ve reserved all boats

  3. Solution 2: • Solution 3: 1) Find names of sailors who’ve reserved boat #103 • Solution 1:

  4. A more efficient solution -- why more efficient? 2) Find names of sailors who’ve reserved a red boat • Boats (bid, bname, color) • Information about boat color only available in Boats; so need an extra join: A query optimizer can find this, given the first solution!

  5. What happens if is replaced by in this query? 3) Find sailors who’ve reserved a red or a green boat • Can identify all red or green boats, then find sailors who’ve reserved one of these boats: • Can also define Tempboats using union! (How?)

  6. 4) Find sailors who’ve reserved a red and a green boat • Previous approach won’t work! Why? • Must identify sailors who’ve reserved red boats, sailors who’ve reserved green boats, then find the intersection (note thatsid is a key for Sailors):

  7. 4) Find sailors who’ve reserved a red and a green boat • Previous approach won’t work! Why? • Must identify sailors who’ve reserved red boats, sailors who’ve reserved green boats, then find the intersection (note thatsid is a key for Sailors):

  8. 5) Find the names of sailors who’ve reserved all boats • Uses division; schemas of the input relations to division (/) must be carefully chosen: • To find sailors who’ve reserved all ‘Interlake’ boats: .....

More Related