07.03 cartesian product

6

Click here to load reader

Upload: bishal-ghimire

Post on 06-Jul-2015

134 views

Category:

Education


0 download

TRANSCRIPT

Page 1: 07.03 cartesian product
Page 2: 07.03 cartesian product

The rename operation

It is denoted as ρ

E : relational algebra expression

ρ x (E): returns the result of

expression E under the name x.

ρ x (A1, A2, A3… An) (E): returns the

result of expression E under the name

x with attributes renamed to A1, A2,

A3… An.

Page 3: 07.03 cartesian product

Rename Operator

The rename operator returns an existing relation

under a new name.

ρA(B) is the relation B with its name changed to A.

Name EmployeeId

Harry 3415

Sally 2241

EmployeeName EmployeeId

Harry 3415

Sally 2241

Employee

Page 4: 07.03 cartesian product

Cartesian Product

If R and S are two relations, R S is the set of all concatenated tuples <x,y>, where x is a tuple in R and y is a tuple in S

◦ R and S need not be union compatible.

◦ But R and S must have distinct attribute names.

Each row of R is paired with each row of S.

Result schema has one field per field of S

and R, with field names `inherited’ if

possible.

Page 5: 07.03 cartesian product

Cartesian Product

A B

a1 b1

a2 b2

C D

c1 d1

c2 d2

A B C D

a1 b1 c1 d1

a1 b1 c2 d2

a2 b2 c1 d1

a2 b2 c2 d2

R S

R x S

Page 6: 07.03 cartesian product

sID sName GPA HS sID sName major dec

Student Apply

Q : Names and GPAs of students with HS >1000 who

applied to CS and were rejected

π sName , GPA

( σ Student.sID = Apply.sID ^ HS > 1000 ^ Major =‘cs’ ^ dec = ‘R’

( Student x Apply ) )