CSE 544 Principles of Database Management Systems

Similar documents
CSE 344 MAY 16 TH NORMALIZATION

CSE 344 AUGUST 3 RD NORMALIZATION

Introduction to Data Management CSE 344

11/1/12. Relational Schema Design. Relational Schema Design. Relational Schema Design. Relational Schema Design (or Logical Design)

10/12/10. Outline. Schema Refinements = Normal Forms. First Normal Form (1NF) Data Anomalies. Relational Schema Design

Database Design and Implementation

Introduction to Management CSE 344

11/6/11. Relational Schema Design. Relational Schema Design. Relational Schema Design. Relational Schema Design (or Logical Design)

Introduction to Database Systems CSE 414. Lecture 20: Design Theory

CSE 303: Database. Outline. Lecture 10. First Normal Form (1NF) First Normal Form (1NF) 10/1/2016. Chapter 3: Design Theory of Relational Database

CSE 344 AUGUST 6 TH LOSS AND VIEWS

Practice and Applications of Data Management CMPSCI 345. Lecture 16: Schema Design and Normalization

CMPT 354: Database System I. Lecture 9. Design Theory

Practice and Applications of Data Management CMPSCI 345. Lecture 15: Functional Dependencies

Schema Refinement. Feb 4, 2010

Lectures 6. Lecture 6: Design Theory

Design Theory. Design Theory I. 1. Normal forms & functional dependencies. Today s Lecture. 1. Normal forms & functional dependencies

CSC 261/461 Database Systems Lecture 11

Introduction to Data Management CSE 344

CSC 261/461 Database Systems Lecture 10 (part 2) Spring 2018

SCHEMA NORMALIZATION. CS 564- Fall 2015

CSC 261/461 Database Systems Lecture 8. Spring 2017 MW 3:25 pm 4:40 pm January 18 May 3 Dewey 1101

L14: Normalization. CS3200 Database design (sp18 s2) 3/1/2018

CSC 261/461 Database Systems Lecture 13. Spring 2018

CSC 261/461 Database Systems Lecture 12. Spring 2018

L13: Normalization. CS3200 Database design (sp18 s2) 2/26/2018

Schema Refinement and Normal Forms

Chapter 3 Design Theory for Relational Databases

DECOMPOSITION & SCHEMA NORMALIZATION

Design theory for relational databases

UVA UVA UVA UVA. Database Design. Relational Database Design. Functional Dependency. Loss of Information

DESIGN THEORY FOR RELATIONAL DATABASES. csc343, Introduction to Databases Renée J. Miller and Fatemeh Nargesian and Sina Meraji Winter 2018

Design Theory for Relational Databases. Spring 2011 Instructor: Hassan Khosravi

Design Theory for Relational Databases

Relational Database Design

Design Theory for Relational Databases

CS322: Database Systems Normalization

CS122A: Introduction to Data Management. Lecture #13: Relational DB Design Theory (II) Instructor: Chen Li

Introduction to Data Management. Lecture #7 (Relational DB Design Theory II)

Relational Design Theory

Normal Forms (ii) ICS 321 Fall Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa

Functional Dependency Theory II. Winter Lecture 21

Databases 2012 Normalization

Lossless Joins, Third Normal Form

Chapter 3 Design Theory for Relational Databases

Schema Refinement & Normalization Theory

Introduction to Data Management. Lecture #6 (Relational Design Theory)

Introduction to Data Management. Lecture #6 (Relational DB Design Theory)

INF1383 -Bancos de Dados

Schema Refinement and Normal Forms. Chapter 19

CS54100: Database Systems

Schema Refinement and Normal Forms

Relational Design Theory II. Detecting Anomalies. Normal Forms. Normalization

Information Systems for Engineers. Exercise 8. ETH Zurich, Fall Semester Hand-out Due

Introduction. Normalization. Example. Redundancy. What problems are caused by redundancy? What are functional dependencies?

Relational Database Design

Normal Forms. Dr Paolo Guagliardo. University of Edinburgh. Fall 2016

CS 464/564 Introduction to Database Management System Instructor: Abdullah Mueen

Schema Refinement and Normal Forms

Information Systems (Informationssysteme)

Lecture #7 (Relational Design Theory, cont d.)

Functional Dependency and Algorithmic Decomposition

Functional Dependencies and Normalization

Schema Refinement and Normal Forms. The Evils of Redundancy. Schema Refinement. Yanlei Diao UMass Amherst April 10, 2007

FUNCTIONAL DEPENDENCY THEORY II. CS121: Relational Databases Fall 2018 Lecture 20

The Evils of Redundancy. Schema Refinement and Normal Forms. Example: Constraints on Entity Set. Functional Dependencies (FDs) Example (Contd.

The Evils of Redundancy. Schema Refinement and Normal Forms. Example: Constraints on Entity Set. Functional Dependencies (FDs) Refining an ER Diagram

Relational Database Design Theory Part II. Announcements (October 12) Review. CPS 116 Introduction to Database Systems

Schema Refinement & Normalization Theory: Functional Dependencies INFS-614 INFS614, GMU 1

FUNCTIONAL DEPENDENCY THEORY. CS121: Relational Databases Fall 2017 Lecture 19

Schema Refinement and Normal Forms. The Evils of Redundancy. Functional Dependencies (FDs) CIS 330, Spring 2004 Lecture 11 March 2, 2004

The Evils of Redundancy. Schema Refinement and Normalization. Functional Dependencies (FDs) Example: Constraints on Entity Set. Refining an ER Diagram

Database Design: Normal Forms as Quality Criteria. Functional Dependencies Normal Forms Design and Normal forms

Schema Refinement and Normal Forms. The Evils of Redundancy. Functional Dependencies (FDs) [R&G] Chapter 19

The Evils of Redundancy. Schema Refinement and Normal Forms. Functional Dependencies (FDs) Example: Constraints on Entity Set. Example (Contd.

Database Design and Normalization

Functional Dependencies and Normalization. Instructor: Mohamed Eltabakh

Constraints: Functional Dependencies

Chapter 10. Normalization Ext (from E&N and my editing)

Schema Refinement. Yanlei Diao UMass Amherst. Slides Courtesy of R. Ramakrishnan and J. Gehrke

Schema Refinement and Normal Forms. Case Study: The Internet Shop. Redundant Storage! Yanlei Diao UMass Amherst November 1 & 6, 2007

Design Theory: Functional Dependencies and Normal Forms, Part I Instructor: Shel Finkelstein

Schema Refinement and Normal Forms

Schema Refinement: Other Dependencies and Higher Normal Forms

Functional Dependencies & Normalization. Dr. Bassam Hammo

Schema Refinement and Normal Forms Chapter 19

Schema Refinement and Normalization

Constraints: Functional Dependencies

Normal Forms 1. ICS 321 Fall Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa

A few details using Armstrong s axioms. Supplement to Normalization Lecture Lois Delcambre

Schema Refinement and Normal Forms. Why schema refinement?

Desirable properties of decompositions 1. Decomposition of relational schemes. Desirable properties of decompositions 3

Normalization. October 5, Chapter 19. CS445 Pacific University 1 10/05/17

But RECAP. Why is losslessness important? An Instance of Relation NEWS. Suppose we decompose NEWS into: R1(S#, Sname) R2(City, Status)

COSC 430 Advanced Database Topics. Lecture 2: Relational Theory Haibo Zhang Computer Science, University of Otago

Chapter 11, Relational Database Design Algorithms and Further Dependencies

CSE 132B Database Systems Applications

CS 4604: Introduc0on to Database Management Systems. B. Aditya Prakash Lecture #15: BCNF, 3NF and Normaliza:on

CS 186, Fall 2002, Lecture 6 R&G Chapter 15

Functional Dependencies. Applied Databases. Not all designs are equally good! An example of the bad design

Transcription:

CSE 544 Principles of Database Management Systems Lecture 3 Schema Normalization CSE 544 - Winter 2018 1

Announcements Project groups due on Friday First review due on Tuesday (makeup lecture) Run git pull to get the review subdirectory Place your review there Commit, push (see instructions in hw1.md); no need to tag Homework 1 due next Friday Run turninhw.sh hw1 Or manually: git commit..., git tag..., git push... CSE 544 - Winter 2018 2

Database Design The relational model is great, but how do I design my database schema? CSE 544 - Winter 2018 3

Outline Conceptual db design: entity-relationship model Problematic database designs Functional dependencies Normal forms and schema normalization CSE 544 - Winter 2018 4

Conceptual Schema Design Conceptual Model: name Patient patien_of Doctor zip name dno Relational Model: plus FD s (FD = functional dependency) Normalization: Eliminates anomalies CSE 544 - Winter 2018 5

Entity-Relationship Diagram Attributes Entity sets Relationship sets name Patient patient_of 6

Entity-Relationship Diagram Patient Doctor Attributes Entity sets Relationship sets name Patient patient_of 7

Entity-Relationship Diagram name pno dno Patient Doctor zip specialty name Attributes Entity sets Relationship sets name Patient patient_of 8

Entity-Relationship Diagram name pno dno Patient patient_of Doctor zip specialty name Attributes Entity sets Relationship sets name Patient patient_of 9

Entity-Relationship Diagram pno name since dno Patient patient_of Doctor zip specialty name Attributes Entity sets Relationship sets name Patient patient_of 10

Entity-Relationship Model Typically, each entity has a key ER relationships can include multiplicity One-to-one, one-to-many, etc. Indicated with arrows Many One Can model multi-way relationships Can model subclasses And more... CSE 544 - Winter 2018 11

Subclasses to Relations price name category Product isa isa Software Product Educational Product platforms Age Group 12

Subclasses to Relations price name category Product Name Price Category Gizmo 99 gadget Product Camera 49 photo Toy 39 gadget isa isa Software Product Educational Product platforms Age Group 13

Subclasses to Relations price name category Product Name Price Category Gizmo 99 gadget Product Camera 49 photo Toy 39 gadget isa isa Sw.Product Name platforms Software Product Educational Product Gizmo unix platforms Age Group 14

Subclasses to Relations price name category Product Name Price Category Gizmo 99 gadget Product Camera 49 photo Toy 39 gadget isa isa Sw.Product Name platforms Software Product platforms Educational Product Age Group Gizmo Name unix Age Group Gizmo toddler Ed.Product Toy senior

General approach to Translating Diagram into Relations Each entity set becomes a relation with a key Each relationship set becomes a relation with foreign keys except many-one relationships: just add a fk Each isa relationship becomes another relation, with both a key and foreign key CSE 544 - Winter 2018 16

Outline Conceptual db design: entity-relationship model Problematic database designs Functional dependencies Normal forms and schema normalization CSE 544 - Winter 2018 17

Relational Schema Design Name SSN PhoneNumber City Fred 123-45-6789 206-555-1234 Seattle Fred 123-45-6789 206-555-6543 Seattle Joe 987-65-4321 908-555-2121 Westfield One person may have multiple phones, but lives in only one city Primary key is thus (SSN, PhoneNumber) What is the problem with this schema? CSE 544 - Winter 2018 18

Relational Schema Design Name SSN PhoneNumber City Fred 123-45-6789 206-555-1234 Seattle Fred 123-45-6789 206-555-6543 Seattle Joe 987-65-4321 908-555-2121 Westfield Anomalies: Redundancy = repeat data for Fred Update anomalies = what if Fred moves to Bellevue? Deletion anomalies = what if Joe deletes his phone number? CSE 544 - Winter 2018 19

Relation Decomposition Break the relation into two: Name SSN PhoneNumber City Fred 123-45-6789 206-555-1234 Seattle Fred 123-45-6789 206-555-6543 Seattle Joe 987-65-4321 908-555-2121 Westfield Name SSN City Fred Joe 123-45-6789 Seattle 987-65-4321 Westfield SSN PhoneNumber 123-45-6789 206-555-1234 123-45-6789 206-555-6543 987-65-4321 908-555-2121 Anomalies have gone: No more repeated data Easy to move Fred to Bellevue (how?) Easy to delete all Joe s phone numbers (how?) 20

Relational Schema Design (or Logical Design) How do we do this systematically? Start with some relational schema Find out its functional dependencies (FDs) Use FDs to normalize the relational schema CSE 544 - Winter 2018 21

Functional Dependencies (FDs) Definition If two tuples agree on the attributes A 1, A 2,, A n then they must also agree on the attributes Formally: B 1, B 2,, B m A1 An determines B1..Bm A 1, A 2,, A n à B 1, B 2,, B m CSE 544 - Winter 2018 22

Functional Dependencies (FDs) Definition A 1,..., A m à B 1,..., B n holds in R if: t, t R, (t.a 1 = t.a 1... t.a m = t.a m à t.b 1 = t.b 1... t.b n = t.b n ) R A 1... A m B 1... B n t t if t, t agree here then t, t agree here 23

Example An FD holds, or does not hold on an instance: EmpID Name Phone Position E0045 Smith 1234 Clerk E3542 Mike 9876 Salesrep E1111 Smith 9876 Salesrep E9999 Mary 1234 Lawyer EmpID à Name, Phone, Position Position à Phone but not Phone à Position CSE 544 - Winter 2018 24

Example EmpID Name Phone Position E0045 Smith 1234 Clerk E3542 Mike 9876 ß Salesrep E1111 Smith 9876 ß Salesrep E9999 Mary 1234 Lawyer Position à Phone CSE 544 - Winter 2018 25

Example EmpID Name Phone Position E0045 Smith 1234 à Clerk E3542 Mike 9876 Salesrep E1111 Smith 9876 Salesrep E9999 Mary 1234 à Lawyer But not Phone à Position CSE 544 - Winter 2018 26

Example name à color category à department color, category à price name category color department price Gizmo Gadget Green Toys 49 Tweaker Gadget Green Toys 99 Which FD s hold? CSE 544 - Winter 2018 27

Buzzwords FD holds or does not hold on an instance If we can be sure that every instance of R will be one in which a given FD is true, then we say that R satisfies the FD If we say that R satisfies an FD, we are stating a constraint on R CSE 544 - Winter 2018 28

An Interesting Observation If all these FDs are true: Then this FD also holds: name à color category à department color, category à price name, category à price Find out from application domain some FDs, Compute all FD s implied by them CSE 544 - Winter 2018 29

Closure of a set of Attributes Given a set of attributes A 1,, A n The closure is the set of attributes B, denoted {A 1,, A n } +, s.t. A 1,, A n à B CSE 544 - Winter 2018 30

Closure of a set of Attributes Given a set of attributes A 1,, A n The closure is the set of attributes B, denoted {A 1,, A n } +, s.t. A 1,, A n à B Example: 1. name à color 2. category à department 3. color, category à price CSE 544 - Winter 2018 31

Closure of a set of Attributes Given a set of attributes A 1,, A n The closure is the set of attributes B, denoted {A 1,, A n } +, s.t. A 1,, A n à B Example: 1. name à color 2. category à department 3. color, category à price Closures: name + = {name, color} CSE 544 - Winter 2018 32

Closure of a set of Attributes Given a set of attributes A 1,, A n The closure is the set of attributes B, denoted {A 1,, A n } +, s.t. A 1,, A n à B Example: 1. name à color 2. category à department 3. color, category à price Closures: name + = {name, color} {name, category} + = {name, category, color, department, price} CSE 544 - Winter 2018 33

Closure of a set of Attributes Given a set of attributes A 1,, A n The closure is the set of attributes B, denoted {A 1,, A n } +, s.t. A 1,, A n à B Example: 1. name à color 2. category à department 3. color, category à price Closures: name + = {name, color} {name, category} + = {name, category, color, department, price} color + = {color} CSE 544 - Winter 2018 34

Keys A superkey is a set of attributes A 1,..., A n s.t. for any other attribute B, we have A 1,..., A n à B A key is a minimal superkey (no subset is a superkey) CSE 544 - Winter 2018 35

Computing (Super)Keys For all sets X, compute X + If X + = [all attributes], then X is a superkey Try reducing to the minimal X s to get the key CSE 544 - Winter 2018 36

Example Product(name, price, category, color) name, category à price category à color What is the key? CSE 544 - Winter 2018 37

Example Product(name, price, category, color) name, category à price category à color What is the key? (name, category) + = { name, category, price, color } CSE 544 - Winter 2018 38

Example Product(name, price, category, color) name, category à price category à color What is the key? (name, category) + = { name, category, price, color } Hence (name, category) is a key CSE 544 - Winter 2018 39

Key or Keys? Can we have more than one key? CSE 544 - Winter 2018 40

Key or Keys? Can we have more than one key? A à B B à C C à A what are the keys here? CSE 544 - Winter 2018 41

Key or Keys? Can we have more than one key? A à B B à C C à A ABàC BCàA what are the keys here? AàBC BàAC CSE 544 - Winter 2018 42

Eliminating Anomalies Main idea: X à A is OK if X is a (super)key X à A is not OK otherwise Need to decompose the table, but how? CSE 544 - Winter 2018 43

Boyce-Codd Normal Form There are no bad FDs: Definition. A relation R is in BCNF if: Whenever Xà B is a non-trivial dependency, then X is a superkey. Equivalently: Definition. A relation R is in BCNF if: X, either X + = X or X + = [all attributes] CSE 544 - Winter 2018 44

BCNF Decomposition Algorithm Normalize(R) find X s.t.: X X + and X + [all attributes] if (not found) then R is in BCNF let Y = X + - X; Z = [all attributes] - X + decompose R into R1(X Y) and R2(X Z) Normalize(R1); Normalize(R2); Y X Z X + CSE 544 - Winter 2018 45

Example Name SSN PhoneNumber City Fred 123-45-6789 206-555-1234 Seattle Fred 123-45-6789 206-555-6543 Seattle Joe 987-65-4321 908-555-2121 Westfield Joe 987-65-4321 908-555-1234 Westfield SSN à Name, City The only key is: {SSN, PhoneNumber} Hence SSN à Name, City is a bad dependency Name, City SSN + SSN Phone- Number In other words: SSN+ = SSN, Name, City and is neither SSN nor All Attributes

Find X s.t.: X X + and X + [all attributes] Example BCNF Decomposition Person(name, SSN, age, haircolor, phonenumber) SSN à name, age age à haircolor CSE 544 - Winter 2018 47

Find X s.t.: X X + and X + [all attributes] Example BCNF Decomposition Person(name, SSN, age, haircolor, phonenumber) SSN à name, age age à haircolor Iteration 1: Person: SSN+ = SSN, name, age, haircolor Decompose into: P(SSN, name, age, haircolor) Phone(SSN, phonenumber) name, age, haircolor SSN phonenumber CSE 544 - Winter 2018 48

Find X s.t.: X X + and X + [all attributes] Example BCNF Decomposition Person(name, SSN, age, haircolor, phonenumber) SSN à name, age What are age à haircolor the keys? Iteration 1: Person: SSN+ = SSN, name, age, haircolor Decompose into: P(SSN, name, age, haircolor) Phone(SSN, phonenumber) Iteration 2: P: age+ = age, haircolor Decompose: People(SSN, name, age) Hair(age, haircolor) Phone(SSN, phonenumber) CSE 544 - Winter 2018 49

Find X s.t.: X X + and X + [all attributes] Example BCNF Decomposition Person(name, SSN, age, haircolor, phonenumber) SSN à name, age Note the keys! age à haircolor Iteration 1: Person: SSN+ = SSN, name, age, haircolor Decompose into: P(SSN, name, age, haircolor) Phone(SSN, phonenumber) Iteration 2: P: age+ = age, haircolor Decompose: People(SSN, name, age) Hair(age, haircolor) Phone(SSN, phonenumber) CSE 544 - Winter 2018 50

R(A,B,C,D) Example: BCNF A à B B à C R(A,B,C,D) CSE 544 - Winter 2018 51

R(A,B,C,D) Example: BCNF A à B B à C Recall: find X s.t. X X + [all-attrs] R(A,B,C,D) CSE 544 - Winter 2018 52

R(A,B,C,D) Example: BCNF A à B B à C R(A,B,C,D) A + = ABC ABCD CSE 544 - Winter 2018 53

R(A,B,C,D) Example: BCNF A à B B à C R(A,B,C,D) A + = ABC ABCD R 1 (A,B,C) R 2 (A,D) CSE 544 - Winter 2018 54

R(A,B,C,D) Example: BCNF A à B B à C R(A,B,C,D) A + = ABC ABCD R 1 (A,B,C) B + = BC ABC R 2 (A,D) CSE 544 - Winter 2018 55

R(A,B,C,D) Example: BCNF A à B B à C R(A,B,C,D) A + = ABC ABCD R 11 (B,C) R 1 (A,B,C) B + = BC ABC R 12 (A,B) R 2 (A,D) What are the keys? What happens if in R we first pick B +? Or AB +? 56

Decompositions in General R(A 1,..., A n, B 1,..., B m, C 1,..., C p ) S 1 (A 1,..., A n, B 1,..., B m ) S 2 (A 1,..., A n, C 1,..., C p ) S 1 = projection of R on A 1,..., A n, B 1,..., B m S 2 = projection of R on A 1,..., A n, C 1,..., C p CSE 544 - Winter 2018 57

Lossless Decomposition Name Price Category Gizmo 19.99 Gadget OneClick 24.99 Camera Gizmo 19.99 Camera Name Price Name Category Gizmo 19.99 OneClick 24.99 Gizmo 19.99 Gizmo OneClick Gizmo Gadget Camera Camera CSE 544 - Winter 2018 58

Lossy Decomposition What is lossy here? Name Price Category Gizmo 19.99 Gadget OneClick 24.99 Camera Gizmo 19.99 Camera Name Gizmo OneClick Gizmo Category Gadget Camera Camera Price Category 19.99 Gadget 24.99 Camera 19.99 Camera CSE 544 - Winter 2018 59

Lossy Decomposition Name Price Category Gizmo 19.99 Gadget OneClick 24.99 Camera Gizmo 19.99 Camera Name Gizmo OneClick Gizmo Category Gadget Camera Camera Price Category 19.99 Gadget 24.99 Camera 19.99 Camera CSE 544 - Winter 2018 60

Decomposition in General R(A 1,..., A n, B 1,..., B m, C 1,..., C p ) S 1 (A 1,..., A n, B 1,..., B m ) S 2 (A 1,..., A n, C 1,..., C p ) Let: S 1 = projection of R on A 1,..., A n, B 1,..., B m S 2 = projection of R on A 1,..., A n, C 1,..., C p The decomposition is called lossless if R = S 1 S 2 Fact: If A 1,..., A n à B 1,..., B m then the decomposition is lossless It follows that every BCNF decomposition is lossless

Testing for Lossless Join If we decompose R into Π S1 (R), Π S2 (R), Π S3 (R), Is it true that S1 S2 S3 = R? That is true if we can show that: R S1 S2 S3 always holds (why?) R S1 S2 S3 neet to check

Example from textbook Ch. 3.4.2 The Chase Test for Lossless Join R(A,B,C,D) = S1(A,D) S2(A,C) S3(B,C,D) R satisfies: AàB, BàC, CDàA S1 = Π AD (R), S2 = Π AC (R), S3 = Π BCD (R), hence R S1 S2 S3 Need to check: R S1 S2 S3

Example from textbook Ch. 3.4.2 The Chase Test for Lossless Join R(A,B,C,D) = S1(A,D) S2(A,C) S3(B,C,D) R satisfies: AàB, BàC, CDàA S1 = Π AD (R), S2 = Π AC (R), S3 = Π BCD (R), hence R S1 S2 S3 Need to check: R S1 S2 S3 Suppose (a,b,c,d) S1 S2 S3 Is it also in R?

Example from textbook Ch. 3.4.2 The Chase Test for Lossless Join R(A,B,C,D) = S1(A,D) S2(A,C) S3(B,C,D) R satisfies: AàB, BàC, CDàA S1 = Π AD (R), S2 = Π AC (R), S3 = Π BCD (R), hence R S1 S2 S3 Need to check: R S1 S2 S3 Suppose (a,b,c,d) S1 S2 S3 Is it also in R? R must contain the following tuples: A B C D Why? a b1 c1 d (a,d) S1 = Π AD (R)

Example from textbook Ch. 3.4.2 The Chase Test for Lossless Join R(A,B,C,D) = S1(A,D) S2(A,C) S3(B,C,D) R satisfies: AàB, BàC, CDàA S1 = Π AD (R), S2 = Π AC (R), S3 = Π BCD (R), hence R S1 S2 S3 Need to check: R S1 S2 S3 Suppose (a,b,c,d) S1 S2 S3 Is it also in R? R must contain the following tuples: A B C D Why? a b1 c1 d (a,d) S1 = Π AD (R) a b2 c d2 (a,c) S2 = Π BD (R)

Example from textbook Ch. 3.4.2 The Chase Test for Lossless Join R(A,B,C,D) = S1(A,D) S2(A,C) S3(B,C,D) R satisfies: AàB, BàC, CDàA S1 = Π AD (R), S2 = Π AC (R), S3 = Π BCD (R), hence R S1 S2 S3 Need to check: R S1 S2 S3 Suppose (a,b,c,d) S1 S2 S3 Is it also in R? R must contain the following tuples: A B C D Why? a b1 c1 d (a,d) S1 = Π AD (R) a b2 c d2 (a,c) S2 = Π BD (R) a3 b c d (b,c,d) S3 = Π BCD (R)

Example from textbook Ch. 3.4.2 The Chase Test for Lossless Join R(A,B,C,D) = S1(A,D) S2(A,C) S3(B,C,D) R satisfies: AàB, BàC, CDàA S1 = Π AD (R), S2 = Π AC (R), S3 = Π BCD (R), hence R S1 S2 S3 Need to check: R S1 S2 S3 Suppose (a,b,c,d) S1 S2 S3 Is it also in R? R must contain the following tuples: Chase them (apply FDs): AàB A B C D a b1 c1 d a b1 c d2 a3 b c d A B C D Why? a b1 c1 d (a,d) S1 = Π AD (R) a b2 c d2 (a,c) S2 = Π BD (R) a3 b c d (b,c,d) S3 = Π BCD (R)

Example from textbook Ch. 3.4.2 The Chase Test for Lossless Join R(A,B,C,D) = S1(A,D) S2(A,C) S3(B,C,D) R satisfies: AàB, BàC, CDàA S1 = Π AD (R), S2 = Π AC (R), S3 = Π BCD (R), hence R S1 S2 S3 Need to check: R S1 S2 S3 Suppose (a,b,c,d) S1 S2 S3 Is it also in R? R must contain the following tuples: Chase them (apply FDs): AàB BàC A B C D Why? a b1 c1 d (a,d) S1 = Π AD (R) a b2 c d2 (a,c) S2 = Π BD (R) a3 b c d (b,c,d) S3 = Π BCD (R) A B C D a b1 c1 d a b1 c d2 a3 b c d A B C D a b1 c d a b1 c d2 a3 b c d

Example from textbook Ch. 3.4.2 The Chase Test for Lossless Join R(A,B,C,D) = S1(A,D) S2(A,C) S3(B,C,D) R satisfies: AàB, BàC, CDàA S1 = Π AD (R), S2 = Π AC (R), S3 = Π BCD (R), hence R S1 S2 S3 Need to check: R S1 S2 S3 Suppose (a,b,c,d) S1 S2 S3 Is it also in R? R must contain the following tuples: Chase them (apply FDs): A B C D Why? a b1 c1 d (a,d) S1 = Π AD (R) a b2 c d2 (a,c) S2 = Π BD (R) a3 b c d (b,c,d) S3 = Π BCD (R) AàB BàC CDàA A B C D a b1 c1 d a b1 c d2 A B C D a b1 c d a b1 c d2 A B C D a b1 c d a b1 c d2 Hence R contains (a,b,c,d) a3 b c d a3 b c d a b c d

Schema Refinements = Normal Forms 1st Normal Form = all tables are flat 2nd Normal Form = obsolete Boyce Codd Normal Form = no bad FDs 3rd Normal Form = see book BCNF is lossless but can cause loss of ability to check some FDs 3NF fixes that (is lossless and dependency-preserving), but some tables might not be in BCNF i.e., they may have redundancy anomalies CSE 544 - Winter 2018 71