32
COMP 630E Group Project Group 2 Ko Wai Sun, Eric Leung Cheuk Yung, Victo r Ng Ching Yu, Cedric Wong Yee Man, Shirley An Illustration of Data Dependencies

COMP 630E Group Project

  • Upload
    vanig

  • View
    45

  • Download
    0

Embed Size (px)

DESCRIPTION

COMP 630E Group Project. An Illustration of Data Dependencies. Group 2. Ko Wai Sun, Eric Leung Cheuk Yung, Victor Ng Ching Yu, Cedric Wong Yee Man, Shirley. Outline. The Example Functional Dependency (FD) Inclusion Dependency (IND) Multivalued Dependency (MVD) - PowerPoint PPT Presentation

Citation preview

Page 1: COMP 630E Group Project

COMP 630E Group Project

Group 2

Ko Wai Sun, Eric

Leung Cheuk Yung, Victor

Ng Ching Yu, Cedric

Wong Yee Man, Shirley

An Illustration of

Data Dependencies

Page 2: COMP 630E Group Project

Outline

The Example

Functional Dependency (FD)

Inclusion Dependency (IND)

Multivalued Dependency (MVD)

Join Dependency (JD)

Page 3: COMP 630E Group Project

Example Database

• Consider the following example– A database is designed to record the

information about students, professors and courses taken in a semester.

– Click to view the schema and relations of the database.

Page 4: COMP 630E Group Project

Data Dependency

• Data dependency (DD) is a part of integrity constrains that forms the basis of relation data model and is used to express the semantics of the database.

• In this project, we have three main categories of DD– Functional Dependency (FD)– Inclusion Dependency (IND)– Multivalued Dependency (MVD) & Join Dependency (JD)

Page 5: COMP 630E Group Project

Functional Dependency (FD)

• FD imposes restrictions within a single schema.

• It restricts the data in the database follows certain kind of rules.

• Armstrong’s Relations generalize six important rules in describing the FD in schema

Page 6: COMP 630E Group Project

Functional Dependency (FD)

• Consider the student relation

sid sname sfullname sprogram sdept

1001 stud_A stud_A Au BEng(COMP) 1

1002 stud_B stud_B Lo BEng(COMP) 1

1003 stud_C stud_C Ko BEng(ELEC) 2

1004 stud_D stud_D Ng BEng(ELEC) 2

Page 7: COMP 630E Group Project

Functional Dependency (FD)

• Reflexivity– If Y X schema(R) then we have F├X

Y.– Example

• sname sfullname => F ├ sfullname sname• each student’s name (sname) is a subset of his/h

er full name (sfullname). Hence we can determine the student’s name from his/her full name.

Page 8: COMP 630E Group Project

Functional Dependency (FD)

• Augmentation– If F├XY and W is a (set of) attribute(s) in t

he schema, then F├XWYW– Example

• F ├ sid sprogram => F ├ {sid, sdept} {sprogram, sdept}

• A student’s student ID (sid) can determine his/her program of study (sprogram).

• Then the student’s ID together with his/her belonging department can determine the program he/she is studying together with the department he/she belongs to.

Page 9: COMP 630E Group Project

Functional Dependency (FD)

• Transitivity– If F├XY and F├YZ, then F├XZ. – Example

• F├ sid sprogram and F├ sprogram sdeptthen F├ sid sdept

• Student identity number (sid) determines the program (sprogram) he/she has registered, and each program must refer to a department (sdept). We can find the department that the student belongs to by the student identity number.

Page 10: COMP 630E Group Project

Functional Dependency (FD)

• Union– If F├XY and F├XZ, then F├XYZ.– Example

• F├ sid sname and F├ sid sprogramthen F├ sid {sname, sprogram}

• Student ID (sid) determines the name of the student (sname), it also determines the program the student has registered (sprogram).

• Thus if we know the student ID, we can altogether know the student name and the program of that student.

Page 11: COMP 630E Group Project

Functional Dependency (FD)

• Decomposition– If F├XYZ, then F├XY and F├XZ.– Example

• F├ sid {sprogram, sdept}then F├ sid sprogram and F├ sid sdept.

• Student ID (sid) determines the program registered (sprogram) and the department he/she belongs to (sdept).

• With this student ID, we can find the program he/she has registered and the department he/she belongs to separately.

Page 12: COMP 630E Group Project

Functional Dependency (FD)

• Pseudo-transitivity– If F├XY and F├YWZ, then F├XWZ.– Example

• If F├ sid sname and F├ {sname, sprogram} sdept , then F├ {sid, sprogram} sdept

• Student ID (sid) determines the student name (sname). Knowing the student name and the program that he/she has registered (sprogram), we can know the department he/she belongs to (sdept).

• Then, if we know the student ID of the student and the the registered program, we can know the department this student belongs to.

Page 13: COMP 630E Group Project

Inclusion Dependency (IND)

• IND is the rule among different schemas• Consider the student and department relations

sid sname sfullname sprogram sdept

1001 stud_A stud_A Au BEng(COMP)

1

1002 stud_B stud_B Lo BEng(COMP)

1

1003 stud_C stud_C Ko BEng(ELEC) 2

1004 stud_D stud_D Ng BEng(ELEC) 2

did dname

1 Computer Sci.

2 Electronic Eng.

student department

Page 14: COMP 630E Group Project

Inclusion Dependency (IND)

• In the student relation, we only have the student ID of the student and his/her corresponding department ID number.

• Normally every student must belong to a department.

• There should not exist that the relation contains a department with an unknown department identity number, or that the department has no identity number.

Page 15: COMP 630E Group Project

Inclusion Dependency (IND)

• Just the same as FD, there is a tool to formulate the IND between schemas

• This tool is called “Casanova et al.’s axiom system”

• We consider the following three rules:– Reflexivity– Projection and Permutation– Transitivity

Page 16: COMP 630E Group Project

Inclusion Dependency (IND)

• Reflexivity– If X is (are) attribute(s) in a schema R, we h

ave IND├ R[X] R[X]. – Example

• In student relation, IND ├ student[sid] student[sid]

– It gives the basis of inclusion dependency.

Page 17: COMP 630E Group Project

Inclusion Dependency (IND)

• Projection and permutation– If IND├R1[X]R2[Y], then IND├R1[Xk]R2[Yk]

where Xk and Yk are projection and permutation on X and Y

– Example• In the teach relation, course ID and the course des

cription are subset of records in the course relation. If we use course ID as referential key to the course relation, there must exist some records in course relation for the same description as the course description.

Page 18: COMP 630E Group Project

Inclusion Dependency (IND)

course cdescription lecturer

COMP104 C++ 1

COMP104 C++ 2

COMP171 Algorithms 3

ELEC102 Electronics 4

ELEC151 Digital Circuit 5

ELEC151 Digital Circuit 6

course cdescription credit

COMP104 C++ 5

COMP171 Algorithms 3

ELEC102 Electronics 5

ELEC151 Digital Circuit 5

course teach

teach[{course, cdescription}] course[{course, cdescription, credit}]=> teach[cdescription] course[cdescription]

Page 19: COMP 630E Group Project

Inclusion Dependency (IND)

• Transitivity– If IND├R1[X]R2[Y] and IND├R2[Y]R3[Z], then

IND├R1[X]R3[Z]

– Example• In the pattern relation, it records what courses a student

needs to take and only the course ID is known. It is trivial that the course ID is a subset of the course ID in the teach relation. As course ID in the teach relation is also a subset of that in the course relation, from the pattern relation, we can use the course ID as referential key to the course relation.

Page 20: COMP 630E Group Project

Inclusion Dependency (IND)

student dept course

1001 1 COMP104

1001 1 COMP171

1002 1 COMP104

1002 1 COMP171

1003 2 ELEC102

1003 2 ELEC151

1004 2 ELEC102

1004 2 ELEC151

course cdescription lecturer

COMP104 C++ 1

COMP104 C++ 2

COMP171 Algorithms 3

ELEC102 Electronics 4

ELEC151 Digital Circuit 5

ELEC151 Digital Circuit 6

pattern teach

If IND├ pattern[course] teach[course]

Page 21: COMP 630E Group Project

Inclusion Dependency (IND)

course cdescription dept

COMP104 C++ 1

COMP171 Algorithms 1

ELEC102 Electonics 1

ELEC151 Digital Circuit 1

course cdescription lecturer

COMP104 C++ 1

COMP104 C++ 2

COMP171 Algorithms 3

ELEC102 Electronics 4

ELEC151 Digital Circuit 5

ELEC151 Digital Circuit 6

course

teach

and IND├ teach[course] course[course]

Page 22: COMP 630E Group Project

Inclusion Dependency (IND)

course cdescription dept

COMP104 C++ 1

COMP171 Algorithms 1

ELEC102 Electonics 1

ELEC151 Digital Circuit 1

student dept course

1001 1 COMP104

1001 1 COMP171

1002 1 COMP104

1002 1 COMP171

1003 2 ELEC102

1003 2 ELEC151

1004 2 ELEC102

1004 2 ELEC151

course

pattern

then IND├ pattern[course] course[course]

Page 23: COMP 630E Group Project

Multivalued Dependency (MVD) & Join Dependency (JD)

• The third type of DD is related to the decomposition restriction on a single schema.

• This includes multivalued dependency (MVD) and join dependency (JD)

Page 24: COMP 630E Group Project

Multivalued Dependency (MVD)

• Notation: MVD ├ A B

• Example– In the relation pattern. An MVD

deptcourse is satisfied. • t1 [dept] = t2 [dept] = t3 [dept] = t4 [dept] = 1• t3 [course] = t1 [course] = COMP104• t4 [course] = t2[course] = COMP171• Also, t5 [dept] = t6 [dept] = t7 [dept] = t8 [dept] = 2• t7 [course] = t5 [course] = ELEC102• t8 [course] = t6 [course] = ELEC151

Page 25: COMP 630E Group Project

Multivalued Dependency (MVD)

sid sname sprogram sdept

1001 stud_A BEng(COMP) 1

1002 stud_B BEng(COMP) 1

1003 stud_C BEng(ELEC) 2

1004 stud_D BEng(ELEC) 2 dept course

1 COMP104

1 COMP171

2 ELEC102

2 ELEC151

student

requirement

Page 26: COMP 630E Group Project

Multivalued Dependency (MVD)

student dept course

1001 1 COMP104

1001 1 COMP171

1002 1 COMP104

1002 1 COMP171

1003 2 ELEC102

1003 2 ELEC151

1004 2 ELEC102

1004 2 ELEC151

Two students in the same department take the same courses

pattern

Page 27: COMP 630E Group Project

Multivalued Dependency (MVD)

• Example (cont’d)– In other words, students in the same departme

nt follow the same study pattern to take courses.

– Students (1001, 1002) in the Computer Sci. department take COMP104 and COMP171

– and those (1003, 1004) in the Electronic Eng. department take ELEC102 and ELEC151.

• Example

Page 28: COMP 630E Group Project

Join Dependency (JD)

• JD is the general version of MVD

• If the schema can be broken up into n (n≥1) or more schema losslessly, the schema obeys JD.

• particularly, when n=1, it is the trivial case.

• when n=2, it is actually MVD.

Page 29: COMP 630E Group Project

Join Dependency (JD)

• Example– In the relation enrollment– JD ((student, course),

(course, lecturer), (student, lecturer)) holds,

– but JD ((student,course), (course,lecturer)) does not.

student course lecturer

1001 COMP104 1

1001 COMP171 3

1002 COMP104 2

1002 COMP171 3

1003 ELEC102 4

1003 ELEC151 5

1004 ELEC102 4

1004 ELEC151 6

enrollment

Page 30: COMP 630E Group Project

Join Dependency (JD)

– Decompose the relation enrollment into 3 relations as follows

Course Lecturer

COMP104 1

COMP104 2

COMP171 3

ELEC102 4

ELEC151 5

ELEC151 6

Student Lecturer

1001 1

1001 3

1002 2

1002 3

1003 4

1003 5

1004 4

1004 6

Student Course

1001 COMP104

1001 COMP171

1002 COMP104

1002 COMP171

1003 ELEC102

1003 ELEC151

1004 ELEC102

1004 ELEC151

Page 31: COMP 630E Group Project

Join Dependency (JD)

– When the three relations are joined back together, it will be the same as before decomposing.

– But joining the first two relations ((student, course), (course, lecturer)) would generate some spurious results.

– The natural join is as shown in the next slide

Page 32: COMP 630E Group Project

Join Dependency (JD)

Student Course Lecturer

1001 COMP104 1

1001 COMP104 2

1001 COMP171 3

1002 COMP104 1

1002 COMP104 2

1002 COMP171 3

1003 ELEC102 4

1003 ELEC151 5

1003 ELEC151 6

1004 ELEC102 4

1004 ELEC151 5

1004 ELEC151 6

The tuples with red values are spurious. They do not exist in the original enrollment relation.

Therefore the JD of joining these two relations does not hold.