Sie sind auf Seite 1von 11

Database Systems &Applications

Lec14

Extended Operators of Relational Algebra

Example revisited....
Consider the following schema. People(PID,name,address,gender,age) Planet(Plname,colour,shade,Galaxy) Live(PID,Plname,migratedfrom,status) (A person can be migrated from one planet to another planet at any time. Depending on that the status will be living or shifted. By birth the value of migratedfrom for a given PID is NULL) Property(PrID,PID,Plname,type) GuestHouse(GID,No.of.Bed rooms) Haveasite(SID,sqfts)

Find the names of all people who is having property on all the planets.

Division
Goal: Produce the tuples in one relation, r, that match all tuples in another relation, s r (A1, An, B1, Bm) s (B1 Bm) r/s, with attributes A1, An, is the set of all tuples <a> such that for every tuple <b> in s, <a,b> is in r Can be expressed in terms of projection, set difference, and cross-product

Division (contd)

Division - Example
Schema for Student Registration System

Student (Id, Name, Addr, Status) Professor (Id, Name, DeptId) Course (DeptId, CrsCode, CrsName, Descr) Transcript (StudId, CrsCode, Semester, Grade) Teaching (ProfId, CrsCode, Semester) Department (DeptId, Name)

Division - Example
List the Ids of students who have passed all courses that were taught in spring 2000 Numerator:
StudId and CrsCode for every course passed by every student: StudId, CrsCode ( Grade F (Transcript) ) Transcript

Denominator:
CrsCode of all courses taught in spring 2000 CrsCode ( Semester=S2000 (Teaching) ) Teaching

Result is numerator/denominator

Division Example2
sno s1 s1 s1 s1 s2 s2 s3 s4 s4 pno p1 p2 p3 p4 p1 p2 p2 p2 p4

pno p2

B1
sno s1 s2 s3 s4

pno p2 p4 B2

pno p1 p2 p4 B3

sno s1 s4

A/B1

A/B2

sno s1 A/B3

Expressing A/B Using Basic Operators


Division is not essential op; just a useful shorthand. (Also true of joins, but joins are so common that systems implement joins specially.) Idea: For A/B, compute all x values that are not `disqualified by some y value in B. x value is disqualified if by attaching y value from B, we obtain an xy tuple that is not in A.

Disqualified x values:

x (( x ( A) B) A)
Disqualified x values

A/B:

x ( A)

Example s

Reserves

sid bid day 22 101 10/10/96 58 103 11/12/96

Sailors

sid 22 31 58

sname rating age dustin 7 45.0 lubber 8 55.5 rusty 10 35.0


color Blue Red Green Red

Boats

bid 101 102 103 104

bname Interlake Interlake Clipper Marine

Find the names of sailors whove reserved all boats

Uses division; schemas of the input relations to / must be carefully chosen:


(Tempsids, (
sid, bid Re serves) / ( bid Boats))

sname (Tempsids Sailors)

Das könnte Ihnen auch gefallen