Pertemuan >

32
1 Pertemuan <<#07>> <<Relational Algebra(02) >> Matakuliah : <<M0094>>/<<Pengantar Sistem Basis Data>> Tahun : <<2005>> Versi : <<1/1>>

description

Matakuliah: / Tahun: Versi: . Pertemuan >. Learning Outcomes. Pada akhir pertemuan ini, diharapkan mahasiswa akan mampu : - PowerPoint PPT Presentation

Transcript of Pertemuan >

Page 1: Pertemuan  >

1

Pertemuan <<#07>><<Relational Algebra(02) >>

Matakuliah : <<M0094>>/<<Pengantar Sistem Basis Data>>Tahun : <<2005>>Versi : <<1/1>>

Page 2: Pertemuan  >

2

Learning Outcomes

Pada akhir pertemuan ini, diharapkan mahasiswa

akan mampu :

• Mahasiswa dapat Menunjukkan cara pemakaian operasi Join, Intersection, Division

Page 3: Pertemuan  >

3

Outline Materi

• Theta Join, equijoin

• Natural Join

• Outer Join, left Outer Join

• Semijoin

• Division

Page 4: Pertemuan  >

4

Chapter 4 (lanjutan pert. 06)

Relational Algebra and

Relational Calculus

Transparencies

Page 5: Pertemuan  >

5

Join Operations Join is a derivative of Cartesian product.

Equivalent to performing a Selection, using join predicate as selection formula, over Cartesian product of the two operand relations.

One of the most difficult operations to implement efficiently in an RDBMS and one reason why RDBMSs have intrinsic performance problems.

Page 6: Pertemuan  >

6

Join Operations

Various forms of join operation– Theta join– Equijoin (a particular type of Theta join)– Natural join– Outer join– Semijoin

Page 7: Pertemuan  >

7

Theta join (-join)

R FS

– Defines a relation that contains tuples satisfying the predicate F from the Cartesian product of R and S.

– The predicate F is of the form R.ai S.bi where may be one of the comparison operators (<, , >, , =, ).

Page 8: Pertemuan  >

8

Theta join (-join)

Can rewrite Theta join using basic Selection and Cartesian product operations.

R FS = F(R S)

Degree of a Theta join is sum of degrees of the operand relations R and S. If predicate F contains only equality (=), the term Equijoin is used.

Page 9: Pertemuan  >

9

Example - Equijoin

List the names and comments of all clients who have viewed a property for rent.

(clientNo, fName, lName(Client)) Client.clientNo = Viewing.clientNo

(clientNo, propertyNo, comment(Viewing))

Page 10: Pertemuan  >

10

Natural join

R S– An Equijoin of the two relations R and S over all

common attributes x. One occurrence of each common attribute is eliminated from the result.

Page 11: Pertemuan  >

11

Example - Natural join

List the names and comments of all clients who have viewed a property for rent.

(clientNo, fName, lName(Client))

(clientNo, propertyNo, comment(Viewing))

Page 12: Pertemuan  >

12

Outer join

To display rows in the result that do not have matching values in the join column, use Outer join.

R S– (Left) outer join is join in which tuples from

R that do not have matching values in common columns of S are also included in result relation.

Page 13: Pertemuan  >

13

Example - Left Outer join

Produce a status report on property viewings.

propertyNo, street, city(PropertyForRent)

Viewing

Page 14: Pertemuan  >

14

Semijoin

R F S

– Defines a relation that contains the tuples of R that participate in the join of R with S.

Can rewrite Semijoin using Projection and Join:

R F S = A(R F S)

Page 15: Pertemuan  >

15

Example - Semijoin

List complete details of all staff who work at the branch in Glasgow.

Staff Staff.branchNo = Branch.branchNo and Branch.city = ‘Glasgow’ Branch

Page 16: Pertemuan  >

16

Division

R S

– Defines a relation over the attributes C that consists of set of tuples from R that match combination of every tuple in S.

Expressed using basic operations:

T1 C(R)

T2 C((S X T1) – R)

T T1 – T2

Page 17: Pertemuan  >

17

Example - Division

Identify all clients who have viewed all properties with three rooms.

(clientNo, propertyNo(Viewing)) (propertyNo(rooms = 3 (PropertyForRent)))

Page 18: Pertemuan  >

18

Chapter 4 (lanjutan pert. 06)

Relational Algebra and

Relational Calculus

Transparencies

Page 19: Pertemuan  >

19

Join Operations Join is a derivative of Cartesian product.

Equivalent to performing a Selection, using join predicate as selection formula, over Cartesian product of the two operand relations.

One of the most difficult operations to implement efficiently in an RDBMS and one reason why RDBMSs have intrinsic performance problems.

Page 20: Pertemuan  >

20

Join Operations

Various forms of join operation– Theta join– Equijoin (a particular type of Theta join)– Natural join– Outer join– Semijoin

Page 21: Pertemuan  >

21

Theta join (-join)

R FS

– Defines a relation that contains tuples satisfying the predicate F from the Cartesian product of R and S.

– The predicate F is of the form R.ai S.bi where may be one of the comparison operators (<, , >, , =, ).

Page 22: Pertemuan  >

22

Theta join (-join)

Can rewrite Theta join using basic Selection and Cartesian product operations.

R FS = F(R S)

Degree of a Theta join is sum of degrees of the operand relations R and S. If predicate F contains only equality (=), the term Equijoin is used.

Page 23: Pertemuan  >

23

Example - Equijoin

List the names and comments of all clients who have viewed a property for rent.

(clientNo, fName, lName(Client)) Client.clientNo = Viewing.clientNo

(clientNo, propertyNo, comment(Viewing))

Page 24: Pertemuan  >

24

Natural join

R S– An Equijoin of the two relations R and S over all

common attributes x. One occurrence of each common attribute is eliminated from the result.

Page 25: Pertemuan  >

25

Example - Natural join

List the names and comments of all clients who have viewed a property for rent.

(clientNo, fName, lName(Client))

(clientNo, propertyNo, comment(Viewing))

Page 26: Pertemuan  >

26

Outer join

To display rows in the result that do not have matching values in the join column, use Outer join.

R S– (Left) outer join is join in which tuples from

R that do not have matching values in common columns of S are also included in result relation.

Page 27: Pertemuan  >

27

Example - Left Outer join

Produce a status report on property viewings.

propertyNo, street, city(PropertyForRent)

Viewing

Page 28: Pertemuan  >

28

Semijoin

R F S

– Defines a relation that contains the tuples of R that participate in the join of R with S.

Can rewrite Semijoin using Projection and Join:

R F S = A(R F S)

Page 29: Pertemuan  >

29

Example - Semijoin

List complete details of all staff who work at the branch in Glasgow.

Staff Staff.branchNo = Branch.branchNo and Branch.city = ‘Glasgow’ Branch

Page 30: Pertemuan  >

30

Division

R S

– Defines a relation over the attributes C that consists of set of tuples from R that match combination of every tuple in S.

Expressed using basic operations:

T1 C(R)

T2 C((S X T1) – R)

T T1 – T2

Page 31: Pertemuan  >

31

Example - Division

Identify all clients who have viewed all properties with three rooms.

(clientNo, propertyNo(Viewing)) (propertyNo(rooms = 3 (PropertyForRent)))

Page 32: Pertemuan  >

32

<< PENUTUP>>

Dilanjutkan ke Pert 08

RELATIONAL CALCULUS