Download presentation
Presentation is loading. Please wait.
Published byAmice Fletcher Modified over 6 years ago
1
University of Milano Bicocca Carlo Batini Course on Data Base Design
Part 5 – Logical Design
2
© Carlo Batini, 2015 This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. To view a copy of this license, visit
4
Low level conceptual map
5
Logical design as a black box
Conceptual schema Queries Transactions Application load Logical design Logical model Logical schema
6
Logical design in the relational model
Conceptual schema Logical design Relational schema Query load Relational model
7
Notation simplification
8
Diagrammatic notation for ER diagrams adopted so far
Student Id B Course Student Name Exam (1,n) Foreing Chinese Surname Grade Date Course Id Country
9
Simplified notation adopted in this chapter
Student Id Surname Identifier of Entity B Course Student Course Id Name Exam (1,n) Foreing Chinese Grade Date Country Attribute of Entity Attributes of Relationship
10
Translation of entities and relationships into relational tables
11
How to translate generalizations?
Student Id Surname B Student Foreing Chinese Country ?
12
Optimization design issues - Computer structure: CPU and memories
Student Id Surname B Student Course Course Id Name Exam (1,n) Grade Student (Student Id, Surname) Exam (Student Id, Course Id, Grade) Course (Course Id, Name) Central Processing Unit Main memory Secondary Memory Channels 10-8/10-9 seconds 10-2
13
An example of partitioning
Employee Id Place of Birth Date of Birth Level Salary Taxes B Employee Employee Id Level Salary Taxes B Empl1 Empl2 Place of Birth Date of Birth splitted (1,n)
14
Transformation for achieving efficiency
Student Id Surname B Student Course Course Id Name Exam (1,n) Grade Student Id Course Id Surname Grade B Student Course
15
An entity with two groups of attributes accessed separately by queries
16
The three steps of logical design
Conceptual schema in the ER model Simplification and optimization Simplified and optimized conceptual schema in the ER model Translation Relational schema
17
An ER schema with redundancies
Student Id Surname # of Exams passed (1,n) (1,n) Course Id Name Student B Course Exam Grade Date
18
An entity with two identifiers and the two possible choices as primary keys
Student Id Social Security Number Given Name Last Name B Student Student (Student Id, Social Security Number, Given Name, Last Name)
19
Simplification and optimization in Atzeni’s book and in this Part 5
Four steps Course Student Id Surname # of Exams passed B Student Course Id Name Exam (1,n) Grade Date 1. Redundancy analysis 2. Removing generalizations Simplification step Optimization step Merging Partitioning 3. Partitoning and/or merging of entities/relationships 4. In case of multiple identifiers, choice of identifier to be translated into the primary key
20
Restructuring of Generalizations example
IdA A1 A2 B A C C1 B1 D A-D (1,n) E C-E B1
21
Relevant cases of generalization restructurings
B A C ABC Case 1 Case 2 Case 3
22
First case of restructuring
IdA A1 A2 B A C C1 B1 D A-D (1,n) E C-E
23
First case of restructuring
24
Corresponding assignment of properties to new constructs in case 1
IdA A1 A2 B A C C1 B1 D A-D (1,n) E C-E Type (0,n) ABC B1
25
Case 2
26
Corresponding assignment of properties to new constructs in case 2
IdA A1 A2 B A C C1 B1 D A-D (1,n) E C-E (0,1) (1,1) A-B A-C B1
27
Restructuring of Generalizations third case
IdA A1 A2 IdA A1 A2 B1 D A-D (1,n) (1,n) (1,n) B A B A-D D D A-D (1,n) (1,n) (1,n) IdA A1 A2 C1 C B C C-E E B1 C1 C-E (1,n) E B1
28
Third case of restructuring
29
The schema of the motivating example after the simplification step
Course Course Id Name Exam (1,n) Grade Date Student Id Surname B Student Foreing Chinese Country Type
30
Entity partitioning B Course B Student Student- Exam-Course Student Id
Surname Type Country (1,n) (1,n) Course Id Name Student B Course Exam Grade Date Student Id Surname Course Id Name Type Country Grade Date Student- Exam-Course B
31
The three cases of entity (and related relationship) merging
KE1 KE2 E3 E4 B E12 E1 many E2 one or
32
Result of merging in the motivating example
33
Transaltion of Entity B Student
Student ID Given Name Surname Place of Birth B Student Student (Student Id, Given Name, Surname, Place of Birth)
34
Applying the translation in the motivating example
Student Id Surname Course Id Name Type Country Grade Date Student- Exam-Course B Student-Exam-Course (Student Id, Course Id, Surname, Name, Type, Country, Grade, Date)
35
Example considered in the translation of many to many binary relationship
36
Translation of many to many relationships
Student Id Given Name Surname Place of Birth B Student Course Exam (1,n) Grade Date Course Id Name # of Hours Student (Student Id, Given Name, Surname, Place of Birth) Exam (Student Id, Course Id, Grade, Date) Course (Course Id, Name, # of hours)
37
Translation of many to many relationships
Student Id Given Name Surname Place of Birth B Student Course Exam (1,n) Grade Date Course Id Name # of Hours Student (Student Id, Given Name, Surname, Place of Birth) Exam (Student Id, Course Id, Grade, Date) Course (Course Id, Name, # of hours)
38
Do not forget referential integrity constraints…
Student Id Given Name Surname Place of Birth B Student Course Exam (1,n) Grade Date Course Id Name # of Hours Student (Student Id, Given Name, Surname, Place of Birth) Exam (Student Id, Course Id, Grade, Date) Course (Course Id, Name, # of hours)
39
Translation of ternary relationships
IdA A1 A2 B A A-B-C (1,n) C IdB B1 IdC C1 C2 C3 ABC1 ABC2 A (IdA, A1, A2) B (IdB, B1, B2) A-B-C (IdA, IdB, IdC, ABC1, ABC2) C (IdC, ABC1, ABC2)
40
Example of many to many recursive relationship
Person Id Given Name Surname Person B (1,n) (1,n) Person A Person B Relative Type of parental Relationship Person (Person Id, Given Name, Surname) Relative (Person IdA, Person IdB, Type of parental relationship)
41
Translation of one to many relationships
Student Id Given Name Surname Place of Birth B Student Country Born (1,1) (1,n) Country Id Name Continent Student (Student Id, Given Name, Surname, Place of Birth, Country) Country (Country Id, Name, Continent)
42
Translation of entity with external identifier
Student Id B Student University St-Un (1,1) (1,n) Surname Name City Student (Student Id, University, Surname) University (Name, City)
43
(1,1) to (1,1) Relationships A B Solution 1 A (KA, A1, KB)
B (KB, B1, B2) Solution 2 A (KA, A1) B (KB, B1, B2, KA) A KA A1 A-B B (1,1) KB B1 B2
44
Translation of (0,1) to (1,1) Relationships
Solution 1 A (KA, A1) B (KB, B1, B2, KA) A KA A1 A-B B (0,1) (1,1) KB B1 B2 Solution 2 A (KA, A1, KB) B (KB, B1, B2)
45
The two cases of translation in the case (0,1) to (1,1) and corresponding instances
B KA A1 KB ka1 a11 null ka2 a12 kb1 ka3 a13 ka4 a14 kb2 ka5 a15 kb3 ka6 a16 kb4 KB B1 B2 kb1 b11 b21 kb2 b12 b22 kb3 b13 b23 kb4 b14 b24 Solution 1 A (KA, A1, KB) B (KB, B1, B2) A KA A1 A-B B (0,1) (1,1) KB B1 B2 A B KA A1 ka1 a11 ka2 a12 ka3 a13 ka4 a14 ka5 a15 ka6 a16 KB B1 B2 KA kb1 b11 b21 ka2 kb2 b12 b22 ka4 kb3 b13 b23 ka5 kb4 b14 b24 ka6 Solution 2 A (KA, A1) B (KB, B1, B2, KA)
46
The three solutions for the (0,1) and (0,1) case
KA A1 A-B B (0,1) KB B1 B2 Solution1 A (KA, A1) B (KB, B1, B2, KA) Solution 2 A (KA, A1, KB) Solution 3 B (KB, B1, B2) A-B (KA, KB)
47
Exercise 5.1
48
Exercise 5.1: Output of simplification and optimization
RBG (0,1) KB B1 (1,n) (1,1) KA A1 B B RAB A (0,1) (1,n) G KG G1 RAGL (1,n) H (1,n) C1 C2 D1 D2 E E1 E2 L KL L1 C D RCD (0,n) (0,n)
49
Exercise 5.1: Output of simplification and optimization
B A C D KB B1 D1 D2 E1 E2 KA A1 RBG RAB RAGL L G E RCD KG G1 KL L1 (0,n) H (1,1) (0,1) (1,n)
50
Exercise 5.1: Output of simplification and optimization
B A BCDE KB B1 C1 C2 D1 D2 E1 E2 TYPE KA A1 RBG RAB RAGL L G KL L1 (0,n) H (1,1) (0,1) (1,n) RCD
51
Exercise 5.1: Steps of translation
B A BCDE KB B1 C1 C2 D1 D2 E1 E2 TYPE KA A1 RBG RAB RAGL L G KG G1 KL L1 (0,n) H (1,1) (0,1) (1,n) RCD Legenda many to many relationships one to many relationships one to one relationships entities
52
Exercise 5.1: Output of transation
RBCDE (KB, B1, C1, C2, D1, D2, E1, E2, TYPE) RA (KA, A1) RG (KG, G1) RL (KL, L1) RCD (KBC, KBD) RBG (KB, KG) RAGL (KA, KG, KL, H)
53
Exercise 5.1: Adding referential integrity constraints
RBCDE (KB, B1, C1, C2, D1, D2, E1, E2, TYPE) RA (KA, A1) RG (KG, G1) RL (KL, L1) RCD (KBC, KBD) RBG (KB, KG) RAGL (KA, KG, KL, H)
54
Exercise 5.1: Adding referential integrity constraints
RBCDE (KB, B1, C1, C2, D1, D2, E1, E2, TYPE) RA (KA, A1, KB) RG (KG, G1) RL (KL, L1) RCD (KBC, KBD) RBG (KB, KG) RAGL (KA, KG, KL, H)
55
Exercise 5.2
56
Exercise 5.2 A B D C E F G B1 KA A1 E1 EF1 KD D1 RAB (0,1) REF (1,n)
KG G1 G2 G3 G4 G5 RFG F1
57
Exercise 5.2: Output of simplification
B DEF KA A1 B1 KD D1 E1 F1 RBD (0,1) (0,n) REF EF1 C1 C RCD E F G KG G1 G2 G3 G4 G5 (1,n) RFG
58
Exercise 5.2: Output of optimization
B DEF KA A1 B1 KD D1 E1 F1 RBD (0,1) (0,n) REF EF1 C1 C G1 KG1 G11 G21 RFG1 (1,n) RCD E G2 RFG2 KG2 G3 G4 G5 F G12 (1,1)
59
Exercise 5.1: Output of transation
B (KA, A1, B1, KD) C (KA, A1, B1, KD) DEF (KD, D1, E1, F1, KG1, KG2) G1 ( KG1, G11, G21, KG2) G2 (KG2, G3, G4, G5) REF (KD1, KD2, EF1)
60
Exercise 5.2: Adding referential integrity constraints
B (KA, A1, B1, KD) C (KA, A1, B1, KD) DEF (KD, D1, E1, F1, KG1,KG2) G1 ( KG1, G1, G2, KG2) G2 (KG2, G3, G4, G5) REF (KD1, KD2, EF1)
61
University Database Example
62
Exercise 5.3 Course Student Foreign St. Chinese St. Department Country
ID Last Name First Name Name Year of Enrollment Passed Enrolled in Course (1,n) (0,n) Student Grade Date (1,1) Teach Foreign St. Chinese St. Professor First Name Last (1,n) Born Country Name Continent (1,n) (1,1) Born (1,n) (1,1) Department (1,1) (1,n) Belongs to Associate Professor Full Professor Name Address Name Region City Born in (1,1) (1,n)
63
Exercise 5.3 - Output of Simplification and Optimization
First Name Last City Born in (1,1) ID Teach Region Full Professor Department many Address Year of Enrollment Passed Enrolled in Course (1,n) (0,n) Grade Date Born Country Continent Student (0,1) Works in Associate Professor Type
64
Exercise 5.3 - Output of Simplification and Optimization
Student Student Foreign St. Chinese St. Professor Full Professor Associate Professor Full Professor Associate Professor
65
Exercise 5.3 - Output of Translation
Student (Student Id, Last Name, First Name, Type, City, Country) Course (Course Id, Year of Enrollment) Enrolled in (Student Id, Course Id) Passed (Student Id, Course Id, Grade, Date) Full Professor (Last Name, First Name, Department Name, City) Associate Professor (Last Name, First Name, Department Name) Department (Name, Address) City (Name, Region) Foreign Student (Student Id, Country) Chinese Student (Student Id, City of Birth) Country (Name, Continent)
66
Exercise 5.3 - Adding referential integrity constraints
Student (Student Id, Last Name, First Name, Type, City, Country) Course (Course Id, Year of Enrollment) Enrolled in (Student Id, Course Id) Passed (Student Id, Course Id, Grade, Date) Full Professor (Last Name, First Name, Department Name, City) Department (Name, Address) Associate Professor (Last Name, First Name, Department Name) City (Name, Region) Foreign Student (Student Id, Country) Chinese Student (Student Id, City of Birth) Country (Name, Continent)
67
Concepts introduced in Part 5
Part 5 - Logical Design Phase of Logical Design Simplification and Optimization Translation Simplification Phase Removing Generalizations Optimization Phase Partitoning of Entities/Relationships Merging of Entities/Relationships Translation Step (Translation of an) Entity Many to Many Relationship One to Many Relationship Ternary Relationship Recursive Relationship (1,1) to (1,1) Relationship (0,1) to (1,1) Relationship (0,1) to (0,1) Relationship
68
Resti
69
Normalization B City B City Country Student Student Student Id
born (1,1) (1,n) Last Name City Name Country Continent Student Id B Student born (1,1) Last Name City (1,n) Name in Country Continent
70
Motivating Example B Course B Student Student Foreing Chinese Foreing
Course Id Name Exam (1,n) Grade Date Student Id Surname B Student Foreing Chinese Country Student Id Surname B Student Foreing Chinese Country
71
Corresponding assignment of properties to new constructs in case 3
72
Restructuring generalizations in the motivating example
73
Translation of ER modeling constructs
Student Id Surname B Student Course Course Id Name Exam (1,n) Grade Student Id Surname Student Id Course Id Grade Course Id Name Student Id Surname B Student Foreing Chinese Country ?
74
Choice among multiple identifiers
Employee Id Place of Birth Date of Birth Level Salary Taxes B Employee
75
Simplification and optimization step
Four steps Course Student Id Surname # of Exams passed B Student Course Id Name Exam (1,n) Grade Date 1. Redundancy analysis 2. Removing generalizations Simplification step Optimization step Merging Partitioning 3. Partitioning and/or merging of entities/relationships 4. In case of multiple identifiers, choice of identifier to be translated into the primary key
76
Simplification and optimization step
Course Student Id Surname # of Exams passed B Student Course Id Name Exam (1,n) Grade Date 1. Redundancy analysis 2. Removing generalizations Simplification step 3. Partitioning or merging of entities 4. In case of multiple identifiers, choice of identifier to be translated into the primary key Optimization step Merging Partitioning
77
Removing generalizations
Student Id Surname Student B ? Chinese Student Foreing Student Country
78
Simplification
79
Optimization – entity partitioning
Employee Id Level Salary Taxes B Empl1 Empl2 Place of Birth Date of Birth Same as (1,n) Employee
80
(0,1) to (1,1) Relationships A B A B A B Solution 1 A (KA, A1)
KB B1 B2 A B Solution 1 A (KA, A1) B (KB, B1, B2, KA) KA A1 ka1 a11 ka2 a12 ka3 a13 ka4 a14 KB B1 B2 KA kb1 b11 b21 ka1 kb2 b12 b22 ka2 kb3 b13 b23 ka3 kb4 b14 b24 ka4 A B A KA A1 A-B B (0,1) (1,1) KB B1 B2 Solution 2 A (KA, A1, KB) B (KB, B1, B2) KA A1 KB ka1 a11 null ka2 a12 kb1 ka3 a13 ka4 a14 kb2 KB B1 B2 kb1 b11 b21 kb2 b12 b22 kb3 b13 b23 kb4 b14 b24
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.