Download - CSE 880 : Database Systems
![Page 1: CSE 880 : Database Systems](https://reader030.vdocuments.mx/reader030/viewer/2022032708/56812c8b550346895d913cc1/html5/thumbnails/1.jpg)
1
CSE 880: Database Systems
Lecture : EER to Relational Mapping
Reference:
Read Chapter 9 of the textbook
![Page 2: CSE 880 : Database Systems](https://reader030.vdocuments.mx/reader030/viewer/2022032708/56812c8b550346895d913cc1/html5/thumbnails/2.jpg)
2
EER to Relation Mapping
Mapping of superclass/subclass relationships Mapping of shared subclasses Mapping of union types (categories)
![Page 3: CSE 880 : Database Systems](https://reader030.vdocuments.mx/reader030/viewer/2022032708/56812c8b550346895d913cc1/html5/thumbnails/3.jpg)
3
Mapping of Superclass/Subclasses
Let R be the superclass {S1, S2,….,Sm} are the subclasses
– Each subclass can have its own local attributes
R
S1 S2 Sm
…
ka1
a2
b1
b2
c
![Page 4: CSE 880 : Database Systems](https://reader030.vdocuments.mx/reader030/viewer/2022032708/56812c8b550346895d913cc1/html5/thumbnails/4.jpg)
4
EER to Relation Mapping
Step 8: 4 possible approaches– Option 8A: Multiple relations – Superclass and subclasses
– Option 8B: Multiple relations – Subclass relations only
– Option 8C: Single relation with one type attribute
– Option 8D: Single relation with multiple type attributes
![Page 5: CSE 880 : Database Systems](https://reader030.vdocuments.mx/reader030/viewer/2022032708/56812c8b550346895d913cc1/html5/thumbnails/5.jpg)
5
Mapping EER Constructs to Relations
Option 8A: Multiple relations - superclass and subclass– Create superclass relation with attributes {k,a1,a2} and primary key
(PK) = k
– Create a relation Si for each subclass Si, with attributes {k} U {attributes of Si} with PK = k.
R
S1 S2 Sm
…
ka1
a2
b1
b2
c1
k a1 a2
R
k c1 c2
Smc2
k b1 b2
S1
…
![Page 6: CSE 880 : Database Systems](https://reader030.vdocuments.mx/reader030/viewer/2022032708/56812c8b550346895d913cc1/html5/thumbnails/6.jpg)
6
Example
![Page 7: CSE 880 : Database Systems](https://reader030.vdocuments.mx/reader030/viewer/2022032708/56812c8b550346895d913cc1/html5/thumbnails/7.jpg)
7
MySQL Workbench Example
Click on 1-1 identifying relationship type
Click on subclass first before superclass. Repeat this for all 3 subclasses.
![Page 8: CSE 880 : Database Systems](https://reader030.vdocuments.mx/reader030/viewer/2022032708/56812c8b550346895d913cc1/html5/thumbnails/8.jpg)
8
MySQL Workbench Example
![Page 9: CSE 880 : Database Systems](https://reader030.vdocuments.mx/reader030/viewer/2022032708/56812c8b550346895d913cc1/html5/thumbnails/9.jpg)
9
Mapping EER Constructs to Relations
Option 8B: Multiple relations –subclass relations only– Create a relation for each subclass Si, with the attributes of Si
and the superclass
– Works for total specialization (i.e., every entity in the superclass must belong to (at least) one of the subclasses)
R
S1 S2 Sm
…
ka1
a2
b1
b2
c1
c2
a1 a2k c1 c2
Sm
a1 a2k b1 b2
S1
…
![Page 10: CSE 880 : Database Systems](https://reader030.vdocuments.mx/reader030/viewer/2022032708/56812c8b550346895d913cc1/html5/thumbnails/10.jpg)
10
Example
Tonnage
Total specialization
![Page 11: CSE 880 : Database Systems](https://reader030.vdocuments.mx/reader030/viewer/2022032708/56812c8b550346895d913cc1/html5/thumbnails/11.jpg)
11
Limitation of previous two approaches
Query: What does John Doe do as an employee?
To answer this query, we need to scan all three subclass relations, which is inefficient!
![Page 12: CSE 880 : Database Systems](https://reader030.vdocuments.mx/reader030/viewer/2022032708/56812c8b550346895d913cc1/html5/thumbnails/12.jpg)
12
Option 8C: Single relation – with one type attribute (t)– Create a single relation with attributes {k,a1,…an} U {attributes of
S1} U…U {attributes of Sm} U {t} with primary key, PK = k
– The attribute t is called a type (or discriminating) attribute
– This option works for disjoint specialization
EER to Relations Mapping
d
C
S1 S2 Sm
…
ka1
a2
b1
b2
c1
c2
t a1 a2k b1 b2
R
c1 c2… t
![Page 13: CSE 880 : Database Systems](https://reader030.vdocuments.mx/reader030/viewer/2022032708/56812c8b550346895d913cc1/html5/thumbnails/13.jpg)
13
Example
EngType
d
![Page 14: CSE 880 : Database Systems](https://reader030.vdocuments.mx/reader030/viewer/2022032708/56812c8b550346895d913cc1/html5/thumbnails/14.jpg)
14
EER to Relations Mapping
Option 8D: Single relation – with multiple type attributes– Create a single relation with attributes {k,a1,…an} U {attributes of
S1} U…U {attributes of Sm} U {t1, t2,…,tm} and PK = k
– ti is a Boolean attribute indicating whether a tuple belongs to Si.
– This option works for overlapping specialization
o
C
S1 S2 Sm
…
ka1
a2
b1
b2
c1
c2
a1 a2k b1 b2
R
c1 c2… …t1 tm
![Page 15: CSE 880 : Database Systems](https://reader030.vdocuments.mx/reader030/viewer/2022032708/56812c8b550346895d913cc1/html5/thumbnails/15.jpg)
15
Example
![Page 16: CSE 880 : Database Systems](https://reader030.vdocuments.mx/reader030/viewer/2022032708/56812c8b550346895d913cc1/html5/thumbnails/16.jpg)
16
So which option is better?
Depends on applications; must consider tradeoff:– Too many relations (options 8A and 8B)
Inefficient query processing
– Single relation (options 8C and 8D) Lots of nulls; may “lose” some meaningful relationships
If everything is mapped to the Employee relation, we lose
the relationship between hourly employee and trade
union
![Page 17: CSE 880 : Database Systems](https://reader030.vdocuments.mx/reader030/viewer/2022032708/56812c8b550346895d913cc1/html5/thumbnails/17.jpg)
17
EER to Relations Mapping
Mapping of Shared Subclasses (Multiple Inheritance)– A shared subclass is a subclass of several superclasses,
indicating multiple inheritance. These superclasses must have the same key attribute
– Can apply any of the four options (subject to their restrictions – total/partial, overlapping/disjoint)
![Page 18: CSE 880 : Database Systems](https://reader030.vdocuments.mx/reader030/viewer/2022032708/56812c8b550346895d913cc1/html5/thumbnails/18.jpg)
18
o
Example
STUDENT_ASSISTANT is a shared subclass of the EMPLOYEE and STUDENT entity types
![Page 19: CSE 880 : Database Systems](https://reader030.vdocuments.mx/reader030/viewer/2022032708/56812c8b550346895d913cc1/html5/thumbnails/19.jpg)
19
Example
Since there are usually separate queries for employees, alumni, and students, we can use options 8A or 8B
– Relations for option 8A: Person, Employee, Alumnus, Student
– Relations for option 8B: Employee, Alumnus, Student
![Page 20: CSE 880 : Database Systems](https://reader030.vdocuments.mx/reader030/viewer/2022032708/56812c8b550346895d913cc1/html5/thumbnails/20.jpg)
20
Example
o
Suppose we want to use option 8C and 8D to group all employees into a single relation called EMPLOYEE
![Page 21: CSE 880 : Database Systems](https://reader030.vdocuments.mx/reader030/viewer/2022032708/56812c8b550346895d913cc1/html5/thumbnails/21.jpg)
21
Example
o
Suppose we want to use option 8C to group all students into a single relation called STUDENT
![Page 22: CSE 880 : Database Systems](https://reader030.vdocuments.mx/reader030/viewer/2022032708/56812c8b550346895d913cc1/html5/thumbnails/22.jpg)
22
Putting it all together…