18
Jan. 2012 Yangjun Chen ACS- 3902 1 Lossless-join Outline: Lossless-join Chapter 15 – 3rd ed. (Chap. 15 – 4 th , 5 th ed.; Chap. 16, 6 th ed.) •Basic definition of Lossless-join •Examples •Testing algorithm

Outline: Lossless -join Chapter 15 – 3rd ed. (Chap. 15 – 4 th , 5 th ed.; Chap. 16, 6 th ed.)

  • Upload
    radha

  • View
    33

  • Download
    1

Embed Size (px)

DESCRIPTION

Outline: Lossless -join Chapter 15 – 3rd ed. (Chap. 15 – 4 th , 5 th ed.; Chap. 16, 6 th ed.) Basic definition of Lossless -join Examples Testing algorithm. Basic definition of Lossless -join A decomposition D = {R 1 , R 2 ,..., R m } of R has the lossless - PowerPoint PPT Presentation

Citation preview

Page 1: Outline:  Lossless -join Chapter 15 – 3rd ed. (Chap. 15 – 4 th , 5 th  ed.; Chap. 16, 6 th  ed.)

Jan. 2012 Yangjun Chen ACS-3902 1

Lossless-join

Outline: Lossless-joinChapter 15 – 3rd ed. (Chap. 15 – 4th, 5th ed.; Chap. 16, 6th ed.)

•Basic definition of Lossless-join

•Examples

•Testing algorithm

Page 2: Outline:  Lossless -join Chapter 15 – 3rd ed. (Chap. 15 – 4 th , 5 th  ed.; Chap. 16, 6 th  ed.)

Jan. 2012 Yangjun Chen ACS-3902 2

Lossless-join

•Basic definition of Lossless-join

A decomposition D = {R1, R2,..., Rm} of R has the lossless

join property with respect to the set of dependencies F on R if, for every relation r of R that satisfies F, the following holds,

(R1(r), ..., Rm(r)) = r,

where is the natural join of all the relations in D.

The word loss in lossless refers to loss of information, not to loss of tuples.

Page 3: Outline:  Lossless -join Chapter 15 – 3rd ed. (Chap. 15 – 4 th , 5 th  ed.; Chap. 16, 6 th  ed.)

Jan. 2012 Yangjun Chen ACS-3902 3

Lossless-join

•Example: decomposion-1

SSN PNUM hours ENAME

Emp_PROJ

PNAME PLOCATION

F = {SSN ENAME, PNUM {PNAME, PLOCATION},{SSN, PNUM} hours}

SSN ENAME

R1

PNUM PNAME PLOCATION

R2

SSN PNUM hours

R3

Lossless join

Page 4: Outline:  Lossless -join Chapter 15 – 3rd ed. (Chap. 15 – 4 th , 5 th  ed.; Chap. 16, 6 th  ed.)

Jan. 2012 Yangjun Chen ACS-3902 4

Lossless-join

•Example: decomposition-2

SSN PNUM hours ENAME

Emp_PROJ

PNAME PLOCATION

F = {SSN ENAME, PNUM {PNAME, PLOCATION},{SSN, PNUM} hours}

ENAME

R1

SSN PNAME

PLOCATION

R2

PNUM hours

Not lossless join

PLOCATION

Page 5: Outline:  Lossless -join Chapter 15 – 3rd ed. (Chap. 15 – 4 th , 5 th  ed.; Chap. 16, 6 th  ed.)

Jan. 2012 Yangjun Chen ACS-3902 5

Lossless-join

•decomposion-1

A1SSN

A2ENAME

A3PNUM

A4PNAME

A5PLOCATION

A6hours

b11

b21

b31

b12

b22

b32

b13

b23

b33

b14

b24

b34

b15

b25

b35

b16

b26

b36

R1

R2

R3

a1

b21

a1

a2

b22

b32

b13

a3

a3

b14

a4

b34

b15

a5

b35

b16

b26

a6

R1

R2

R3

Page 6: Outline:  Lossless -join Chapter 15 – 3rd ed. (Chap. 15 – 4 th , 5 th  ed.; Chap. 16, 6 th  ed.)

Jan. 2012 Yangjun Chen ACS-3902 6

Lossless-join

a1

b21

a1

a2

b22

a2

b13

a3

a3

b14

a4

b34

b15

a5

b35

b16

b26

a6

R1

R2

R3

a1

b21

a1

a2

b22

a2

b13

a3

a3

b14

a4

a4

b15

a5

a5

b16

b26

a6

R1

R2

R3

SSN ENAME

PNUM {PNAME, PLOCATION}

SSN ENAME

PNUM PNAME PLOCATION

Page 7: Outline:  Lossless -join Chapter 15 – 3rd ed. (Chap. 15 – 4 th , 5 th  ed.; Chap. 16, 6 th  ed.)

Jan. 2012 Yangjun Chen ACS-3902 7

Lossless-join

•decomposition-2

A1SSN

A2ENAME

A3PNUM

A4PNAME

A5PLOCATION

A6hours

b11

b21

b12

b22

b13

b23

b14

b24

b15

b25

b16

b26

R1

R2

b11

a1

a2

b22

b13

a3

b14

a4

a5

a5

b16

a6

R1

R2

The matrix can not be changed!

SSN ENAMEPNUM {PNAME, PLOCATION}

{SSN, PNUM} hours

Page 8: Outline:  Lossless -join Chapter 15 – 3rd ed. (Chap. 15 – 4 th , 5 th  ed.; Chap. 16, 6 th  ed.)

Jan. 2012 Yangjun Chen ACS-3902 8

Lossless-join

a1 a2 b13 b14 b15 b16b21 b22 a3 a4 a5 a6a1 a2 a3 a4 a5 a6

EMP_PROJ

Why?

a1 a2b21 b22

R1b13 b14 b15a3 a4 a5

a1 b13 b16b21 a3 b26a1 a3 a6

R2

R3

Decomposition-1:

Page 9: Outline:  Lossless -join Chapter 15 – 3rd ed. (Chap. 15 – 4 th , 5 th  ed.; Chap. 16, 6 th  ed.)

Jan. 2012 Yangjun Chen ACS-3902 9

Lossless-join

R1 R3 = R13 =

Why?

Decomposition-1:

a1 a2 b13 b16a1 a2 a3 a6b21 b22 a3 b26

R13 R2 =

a1 a2 b13 b14 b15 b16b21 b22 a3 a4 a5 a6a1 a2 a3 a4 a5 a6

Page 10: Outline:  Lossless -join Chapter 15 – 3rd ed. (Chap. 15 – 4 th , 5 th  ed.; Chap. 16, 6 th  ed.)

Jan. 2012 Yangjun Chen ACS-3902 10

Lossless-join

b11 a2 b13 b14 a5 b16a1 b22 a3 a4 a5 a6

EMP_PROJ

Why?

a2 a5b22 a5

R1

b11 b13 b14 a5 b16

a1 a3 a4 a5 a6

R2

Decomposition-2:

Page 11: Outline:  Lossless -join Chapter 15 – 3rd ed. (Chap. 15 – 4 th , 5 th  ed.; Chap. 16, 6 th  ed.)

Jan. 2012 Yangjun Chen ACS-3902 11

Lossless-join

Why?

Decomposition-2:

R1 R2 =

b11 a2 b13 b14 a5 b16a1 a2 a3 a4 a5 a6b11 b22 b13 b14 a5 b16a1 b22 a3 a4 a5 a6

Spurious tuples

Page 12: Outline:  Lossless -join Chapter 15 – 3rd ed. (Chap. 15 – 4 th , 5 th  ed.; Chap. 16, 6 th  ed.)

Jan. 2012 Yangjun Chen ACS-3902 12

Lossless-join

student_no course_no instr_no

Instructor’s teach one course only

Student takes a course and has one instructor

{student_no, course} instr_noinstr_no course_no

Student-course-instructor:

Page 13: Outline:  Lossless -join Chapter 15 – 3rd ed. (Chap. 15 – 4 th , 5 th  ed.; Chap. 16, 6 th  ed.)

Jan. 2012 Yangjun Chen ACS-3902 13

Lossless-join

student_no course_no instr_no

student_no instr_no

Course_no instr_noR1

R2

A1stu-no

A2course-no

A3instr-no

b11

b21

b12

b22

b13

b23

R1

R2

A1stu-no

A2course-no

A3instr-no

b11

a1

a2

b22

a3

a3

R1

R2

b11

a1

a2

a2

a3

a3

R1

R2

{student_no, course} instr_noinstr_no course_no

Page 14: Outline:  Lossless -join Chapter 15 – 3rd ed. (Chap. 15 – 4 th , 5 th  ed.; Chap. 16, 6 th  ed.)

Jan. 2012 Yangjun Chen ACS-3902 14

Lossless-join

student_no course_no instr_no

student_no course_no

Course_no instr_noR1

R2

A1stu-no

A2course-no

A3instr-no

b11

b21

b12

b22

b13

b23

R1

R2

A1stu-no

A2course-no

A3instr-no

b11

a1

a2

a2

a3

b23

R1

R2

b11

a1

a2

a2

a3

b23

R1

R2

instr_no course_no

{student_no, course} instr_noinstr_no course_no

Page 15: Outline:  Lossless -join Chapter 15 – 3rd ed. (Chap. 15 – 4 th , 5 th  ed.; Chap. 16, 6 th  ed.)

Jan. 2012 Yangjun Chen ACS-3902 15

Lossless-join

student_no course_no instr_no

student_no course_no

student_no instr_noR1

R2

A1stu-no

A2course-no

A3instr-no

b11

b21

b12

b22

b13

b23

R1

R2

A1stu-no

A2course-no

A3instr-no

a1

a1

b12

a2

a3

b23

R1

R2

a1

a1

b12

a2

a3

b23

R1

R2

{student_no, course} instr_noinstr_no course_no

Page 16: Outline:  Lossless -join Chapter 15 – 3rd ed. (Chap. 15 – 4 th , 5 th  ed.; Chap. 16, 6 th  ed.)

Jan. 2012 Yangjun Chen ACS-3902 16

Lossless-join

Testing algorithminput: A relation R, a decomposition D = {R1, R2,..., Rm} of R, anda set F of function dependencies.

1. Create an initial matrix S with one row i for each relation Ri inD, and one column j for each attribute Aj in R.

2. Set S(i, j) := bij for all matrix entries.3. For each row i representing relation schema Ri Do

{for each column j representing Aj do{if relation Ri includes attribute Aj then

set S(i, j) := aj;} 4. Repeat the following loop until a complete loop execution results

in no changes to S.

Page 17: Outline:  Lossless -join Chapter 15 – 3rd ed. (Chap. 15 – 4 th , 5 th  ed.; Chap. 16, 6 th  ed.)

Jan. 2012 Yangjun Chen ACS-3902 17

Lossless-join

4. Repeat the following loop until a complete loop execution resultsin no changes to S.

{for each function dependency X Y in F dofor all rows in S which have the same symbols in the

columns corresponding to attributes in X do{make the symbols in each column that correspond to

an attribute in Y be the same in all these rows as follows:if any of the rows has an “a” symbol for the column,set the other rows to the same “a” symbol in the column.If no “a” symbol exists for the attribute in any of therows, choose one of the “b” symbols that appear in oneof the rows for the attribute and set the other rows tothat same “b” symbol in the column;}}

5. If a row is made up entirely of “a” symbols, then the decompo-sition has the lossless join property; otherwise it does not.

Page 18: Outline:  Lossless -join Chapter 15 – 3rd ed. (Chap. 15 – 4 th , 5 th  ed.; Chap. 16, 6 th  ed.)

Jan. 2012 Yangjun Chen ACS-3902 18

Lossless-join

a1

b21

a1

a2

b22

b32

b13

a3

a3

b14

a4

b34

b15

a5

b35

b16

b26

a6

a2b21a1

b22b32

R1<SSN, ENAME> R2<PNUM, PNAME, Plocation>

b13 b14 b15a3 a4 a5a3 b34 b35

a1 b13 b16b21 a3 b26a1 a3 a6

R3<SSN, PNUM, hours>

<a3, a4, a5, a1, a3, a6><a3, b34, b35, a1, a3, a6>

PNUM {PNAME, PLOCATION}

a1