Plan of the lecture. G53RDB: Theory of Relational Databases Lecture 10. Logical consequence (implication) Implication problem for fds

Similar documents
Relational Database Design

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

Functional Dependencies & Normalization. Dr. Bassam Hammo

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

Relational-Database Design

Schema Refinement: Other Dependencies and Higher Normal Forms

Schema Refinement. Feb 4, 2010

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

Functional Dependencies. Getting a good DB design Lisa Ball November 2012

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

Plan of the lecture. G53RDB: Theory of Relational Databases Lecture 9. Informal exercise from last lecture. Example (from Stanczyk et al.

CSIT5300: Advanced Database Systems

LOGICAL DATABASE DESIGN Part #1/2

CMPS Advanced Database Systems. Dr. Chengwei Lei CEECS California State University, Bakersfield

Background: Functional Dependencies. æ We are always talking about a relation R, with a æxed schema èset of attributesè and a

Schema Refinement & Normalization Theory

Constraints: Functional Dependencies

Constraints: Functional Dependencies

Schema Refinement and Normal Forms

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

Schema Refinement and Normal Forms Chapter 19

On a problem of Fagin concerning multivalued dependencies in relational databases

Schema Refinement and Normalization

Schema Refinement and Normal Forms. Why schema refinement?

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

Functional. Dependencies. Functional Dependency. Definition. Motivation: Definition 11/12/2013

Schema Refinement and Normal Forms

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

Data Bases Data Mining Foundations of databases: from functional dependencies to normal forms

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 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

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

Chapter 3 Design Theory for Relational Databases

Plan of the lecture. G53RDB: Theory of Relational Databases Lecture 2. More operations: renaming. Previous lecture. Renaming.

Functional Dependencies

Functional Dependency and Algorithmic Decomposition

Functional Dependencies

CS54100: Database Systems

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

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

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

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

CS589 Principles of DB Systems Fall 2008 Lecture 4e: Logic (Model-theoretic view of a DB) Lois Delcambre

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

Plan of the lecture. G53RDB: Theory of Relational Databases Lecture 13. Join dependencies. Multivalued dependencies. Decomposition (non-loss!

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

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

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

Schema Refinement and Normal Forms

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

Section 7.1 Relations and Their Properties. Definition: A binary relation R from a set A to a set B is a subset R A B.

Schema Refinement and Normal Forms. Chapter 19

Chapter 7: Relational Database Design

Chapter 7: Relational Database Design. Chapter 7: Relational Database Design

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

Functional Dependencies

SCHEMA NORMALIZATION. CS 564- Fall 2015

Handout #6 INTRODUCTION TO ALGEBRAIC STRUCTURES: Prof. Moseley AN ALGEBRAIC FIELD

On the logical Implication of Multivalued Dependencies with Null Values

Topic Dependencies for Electronic Books

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

Schema Refinement and Normal Forms

Functional Dependencies

Axiomatizing Conditional Independence and Inclusion Dependencies

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

Review: Keys. What is a Functional Dependency? Why use Functional Dependencies? Functional Dependency Properties

Functional Dependencies

Databases Lecture 8. Timothy G. Griffin. Computer Laboratory University of Cambridge, UK. Databases, Lent 2009

HKBU: Tutorial 4

Functional Dependencies and Normalization

A CORRECTED 5NF DEFINITION FOR RELATIONAL DATABASE DESIGN. Millist W. Vincent ABSTRACT

Chapter 8: Relational Database Design

Math 242: Principles of Analysis Fall 2016 Homework 1 Part B solutions

Lecture 15 10/02/15. CMPSC431W: Database Management Systems. Instructor: Yu- San Lin

0.Axioms for the Integers 1

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

CSE 132B Database Systems Applications

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

The following techniques for methods of proofs are discussed in our text: - Vacuous proof - Trivial proof

Axioms of Kleene Algebra

Unit 3 - Functional Dependency and Decomposition

MANY BILLS OF CONCERN TO PUBLIC

Proving languages to be nonregular

Design Theory for Relational Databases

Design Theory for Relational Databases

Normaliza)on and Func)onal Dependencies

CSC 261/461 Database Systems Lecture 13. Spring 2018

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

CAS CS 460/660 Introduction to Database Systems. Functional Dependencies and Normal Forms 1.1

Computational Models: Class 3

From Constructibility and Absoluteness to Computability and Domain Independence

Relational Design: Characteristics of Well-designed DB

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Func8onal Dependencies

Relational Design Theory

Design theory for relational databases

Database System Concepts, 5th Ed.! Silberschatz, Korth and Sudarshan See for conditions on re-use "

KRIPKE S THEORY OF TRUTH 1. INTRODUCTION

3.3. Multivalued Dependencies 81 this last equality and from u[ω Y ] = t 2 [Ω Y ] it then follows that t 1 and t 2 agree on the intersection Z (Ω Y )=

Transcription:

Plan of the lecture G53RDB: Theory of Relational Databases Lecture 10 Natasha Alechina School of Computer Science & IT nza@cs.nott.ac.uk Logical implication for functional dependencies Armstrong closure. Algorithm for computing the closure Inference rules for functional dependencies Soundness and completeness of the inference rules Inference rules for functional and multivalued dependencies Examples of derivations Lecture 10 2 Implication problem for fds Logical consequence (implication) In order to normalise a relation, we need to check lots of dependencies (for example, find all functional dependencies and check if in any of them determinant is not a key). If we had a way to generate all dependencies implied by certain other dependencies, we could save ourselves some work. For example, if we know that X Y implies Z W and we know that Z W does not hold, then we don t need to check whether X Y holds. Let Σ be a set of functional dependencies over a set of attributes U, and X Y a functional dependency involving attributes from the same set (X,Y U). X Y is a logical consequence of Σ, or Σ logically implies X Y, if any relation over attributes in U which satisfies functional dependencies in Σ, also satisfies X Y. In symbols: `Σ logically implies X Y is denoted as Σ = X Y. Lecture 10 3 Lecture 10 4 Logical consequence: example Logical consequence: example Let U = {Name, Age, CanVote}, Σ = {Name Age, Age CanVote} X Y = Name CanVote then Σ = X Y. Lecture 10 5 Proof: consider any relation R over U. Assume that it satisfies both dependencies in Σ. So, for any two tuples s and t in R, if s(name)=t(name), then s(age) = t(age) (because R satisfies Name Age) if s(age) = t(age), then s(canvote)=t(canvote) (because R satisfies Age CanVote) so for any two tuples s and t in R, if s(name)=t(name), then s(canvote)=t(canvote) (hence R satisfies Name CanVote) Lecture 10 6 1

Transitivity Armstrong closure In exactly the same way, we can prove that in general, {X Y, Y Z} = X Z That is, for any relation R whose schema includes X, Y and Z, it holds that if R satisfies X Y and Y Z, then R satisfies X Z. Given a set of functional dependencies Σ over a set of attributes U, fd closure X* of X U is defined as follows: X* = {A U: Σ = X A} Why is it a useful concept? By definition, Σ = X Y if, and only if, Y X* So we can test whether Σ = X Y by computing X*. There is a linear time algorithm to compute X*; here is a simpler, less efficient version it is O(n m), where n is the size of Σ and m is the size of X. Lecture 10 7 Lecture 10 8 Algorithm to compute fd closure Input: a set of functional dependencies Σ over some set of attributes U and a set X U of attributes. Output: the closure X* of X with respect to Σ. unused = Σ ; closure = X; repeat until no further change: if W Z unused and W closure then unused = unused {W Z }; closure = closure Z output closure Σ = X Y if, and only if, Y X* (as computed by the algorithm) Proof: there are two things to prove. one is that the closure algorithm does not claim too much, that is, if Y X* then Σ = X Y. another is that that it does not fail to discover dependencies: if Σ = X Y, then Y X*. Lecture 10 9 Lecture 10 10 To prove: if Y X*, then Σ = X Y. Proof by induction: Basis: at step 0, closure only contains attributes in X. for any subset Y of X, it trivially holds that Σ = X Y. Inductive step: suppose that for all W added at the previous step, Σ = X W. Now we add a new set of attributes Z because W is in Σ and Σ = W Z. But then Σ = X Z by transitivity. To prove: if Σ = X Y, then Y X*. If Z is not a subset of X*, we can construct a relation which satisfies Σ and does not satisfy X Z. This will show that Σ does not logically imply X Z. The relation R contains just two tuples, s and t. They agree on the values of all attributes in X* and disagree on all attributes which are not in X*, including at least some in Z. So R satisfies Σ and falsifies X Z. (A bit more details on the next slide.) Lecture 10 11 Lecture 10 12 2

Counterexample Inference rules for fds s t R X* X 1,,X n Y 1,,Y k Z 1,,Z m a 1,,a n b 1,,b k c 1,,c m a 1,,a n b 1,,b k d 1,,d m The idea is that X = {X 1,,X n }, X*={X 1,,X n, Y 1, Y k }, two tuples s and t agree on X* and disagree on Zs (c i is not equal to d i for every i in 1,,m). Clearly R does not satisfy X Z if some of Z s attributes are among Z i. Let us show that R satisfies Σ. Assume otherwise: there is W V in Σ such that R does not satisfy it. So s and t agree on W (so W X*) and disagree on V (so V is not a subset of X*). But if W X* and W V in Σ, then by construction of X*, also V should be in X*, a contradiction. Lecture 10 13 The following rules are due to Armstrong (1974): Let X,Y,Z be sets of attributes of some relation R. Then FD1 (reflexivity): if Y X then X Y FD2 (augmentation): if X Y then XZ YZ FD3 (transitivity): if X Y and Y Z then X Z Here, XZ is short for X Z. Lecture 10 14 Derivability Let Σ be a set of functional dependencies over a set of attributes U, and X Y a functional dependency involving attributes from the same set. X Y is derivable from Σ (by inference rules FD1-FD3) if we can obtain X Y by applying inference rules to dependencies in Σ (or, if there is a finite sequence of dependencies, each of which is either in Σ, or obtained from the previous dependencies by FD1-FD3). In symbols: ` X Y is derivable from Σ is denoted as Σ X Y. Example Let A,B,C,D,E be attributes and Σ = {A B, B C, CD E} Then Σ AD E: A C from A B and B C by FD3 AD CD from A C by FD2 AD E from AD CD and CD E by FD3 Lecture 10 15 Lecture 10 16 Soundness and completeness Armstrong s rules are sound: we can never derive dependencies which do not hold: if Σ X Y then Σ = X Y. Armstrong s rules are complete: if a dependency X Y is a logical consequence of Σ, then we can derive X Y from Σ. if Σ = X Y then Σ X Y. Proof of soundness The proof is by induction on the length of the derivation (the number of rule applications). We show that at each step in deriving X Y from Σ, by applying FD1-FD3 we only obtain logical consequences. FD1 (reflexivity): if Y X then X Y. Take any relation R. We want to show that for any two tuples s and t in R, if s(x)=t(x), then s(y)=t(y). Suppose s(x)=t(x). We know that Y X, so if s and t agree on all attributes in X, then they agree on all attributes in Y. So s(y)=t(y). Lecture 10 17 Lecture 10 18 3

Proof of soundness Proof of soundness FD2 (augmentation): if X Y then XZ YZ. Take any relation R which satisfies X Y. We want to show that for any two tuples s and t in R, if s(xz)=t(xz), then s(yz)=t(yz). Assume s(xz)=t(xz). This is the same as s(x)=t(x) and s(z)=t(z). Since R satisfies X Y, from s(x)=t(x) we get s(y)=t(y). We know that s(y)=t(y) and s(z)=t(z), so s(yz)=t(yz). FD3 (transitivity): if X Y and Y Z then X Z. Really the same as our example of logical consequence. Take any relation R which satisfies X Y and Y Z. We want to show that for any two tuples s and t in R, if s(x)=t(x), then s(z)=t(z). Assume s(x)=t(x). Then by X Y, s(y)=t(y). Then by Y Z, s(z)=t(z). Lecture 10 19 Lecture 10 20 Proof of completeness To show that if a dependency X Y follows from Σ, then it is also derivable from Σ using the axioms; in other words, Σ = X Y implies Σ X Y: The proof consists of two parts: Σ X X* (Σ implies a functional dependency between X and the set of all attributes in the closure of X with respect to Σ). If Σ = X Y, then Y X*. From X X* and Y X* we can derive X Y by FD1 and FD3 (the proof of this property, called decomposition, is given later in the lecture). Lecture 10 21 Σ X X* By induction, we show that at every step i in construction of X*, Σ X closure i, where closure i is the set of attributes in the closure at step i. Basis of induction: at step 0, closure 0 = {X}, and Σ X X by FD1. Inductive step: suppose Σ X closure i, prove Σ X closure i+1. Lecture 10 22 Σ X X* Derivable rules Inductive step: (1) assume Σ X closure i inductive hypothesis (2) Σ closure i W by fd1 (3) Σ W Z because W Z is in Σ (4) Σ closure i Z by fd3 from (2), (3) (5) Σ closure i closure i Z by fd2 from (4) (note that closure i closure i = closure i ) (6) Σ closure i closure i+1 from (5) (7) Σ X closure i+1 by fd3 from the inductive hypothesis (1) and (6). Some other rules are also sound, but we do not need them for completeness because they follow from FD1-FD3. For example, Decomposition: if X YZ, then X Y. From Y YZ we get YZ Y by FD1. From X YZ and YZ Y we get X Y by FD3. Lecture 10 23 Lecture 10 24 4

Derivable rules Reading Union: if X Y and X Z, then X YZ. From X Y we get XX XY by FD2, and since XX=X we get X XY. From X Z we get XY YZ by FD2. From X XY and XY YZ we get X YZ by FD3. Ullman, Widom, chapter 3.5 Stanczyk et al, Chapter 7.3 (Armstrong axiomatization of functional dependencies, 3NF). Abiteboul, Hull, Vianu, Foundations of Databases, chapter 8 for axiomatization of multivalued dependencies and functional dependencies. Lecture 10 25 Lecture 10 26 Informal coursework Show that FD1 - FD3 imply (9) Pseudo-transitivity: if X Y and TY Z, then TX Z. Lecture 10 27 5