Presentation is loading. Please wait.

Presentation is loading. Please wait.

© 2003-2006 M.E. Fayad SJSU -- CmpE Database Design Dr. M.E. Fayad, Professor Computer Engineering Department, Room #283I College of Engineering San José.

Similar presentations


Presentation on theme: "© 2003-2006 M.E. Fayad SJSU -- CmpE Database Design Dr. M.E. Fayad, Professor Computer Engineering Department, Room #283I College of Engineering San José."— Presentation transcript:

1 © 2003-2006 M.E. Fayad SJSU -- CmpE Database Design Dr. M.E. Fayad, Professor Computer Engineering Department, Room #283I College of Engineering San José State University One Washington Square San José, CA 95192-0180 http://www.engr.sjsu.edu/~fayad

2 L7-S2 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad 2 Lesson 07: Constraint Databases

3 L7-S3 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad Lesson Objectives 3 Understand Constraint Databases Learn How to Deal with Constraints î Arithmetic Atomic Constraints î Boolean Atomic Constraints î Constraint Formulas î Interpretations of Free Boolean Constraints Understand the Constraint Data Model Explore Data Abstraction

4 L7-S4 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad  Are The highest level of data abstraction  Are not suitable for computer to represent data. Why?  Because the allow an infinite number of tuples or points.  In this lecture we discuss constraint data model that is used to represent the logical level of data in a concise way. 4 View and Logical Levels

5 L7-S5 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad Next level of data abstraction: Constraint level – finitely represents by constraints the logical level 5 Constraint Databases

6 L7-S6 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad  Constraints apply to two or more variables.  Each variable takes its value from a domain  Common domains are: + The set of nonnegative numbers (or natural numbers) N + The set of integer numbers Z + The set of rational number Q + The set of real numbers R  Other domains – Set of English words in the dictionary W 6 Two Most Common Types of Constraints

7 L7-S7 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad Assume u and v are variables or constants B and c i are constants Let ± denote + or - Let p be a polynomial function over variables X 1, …., X n Any valid expression with constants, variables, addition, and multiplication symbols We define the most basic type of constraints, called the atomic constraints over any of the domains N, Z, Q, R as following: 7 Constraints (1)

8 L7-S8 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad Arithmetic Atomic Constraints Equality: u = v Inequality: u ≠ v Lower bound: u ≥ b Upper bound: – u ≥ b Order: u ≥ v Gap-order: u – v ≥ b where b ≥ 0 Difference: u – v ≥ b 8 Constraints (2)

9 L7-S9 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad Half-Addition: ± u ± v ≥ b where b ≥ 0 Addition: ± u ± v ≥ b Linear: c 1 x 1 + ……+ c n x n ≥ b Polynomial: p( x 1,……..,x n ) ≥ b Note: Instead of ≥ we can also use > b is a bound which is restricted to be nonnegative in the case of gap-order and half addition constraints. c i is a coefficient in the linear constraint. 9 Constraints (3)

10 L7-S10 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad If a constraint C is any of these types of constraints and the domain of the variables is Z and Q we talk of integer C constraints or rational C constraints, respectively. We consider each = constraint as the conjunction of two ≥ constraints. For example: linear equation 5x+7y = 8 can be expressed as the conjunction of the linear inequality constraints: 5x +7y ≥ 8 and 5x +7y ≤ 8 This is why we do not consider linear equality as atomic constraints. Nevertheless, we will write constraints with = signs. 10 Constraints (4)

11 L7-S11 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad Boolean Algebra D – domain, 0 – zero element, 1 – one element. such that the following axioms hold: 11 Boolean Atomic Constraints (1)

12 L7-S12 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad Commutative: x V y = y V x x Λ y = y Λ x Distributive: x V ( y Λ z ) = ( x V y ) Λ ( x V z ) x Λ ( y V z ) = ( x Λ y ) V ( x Λ z ) Inverse: x V x’ = 1 x Λ x’ = 0 Zero and one element properties: x V 0 = x x Λ 1 = x 0 ≠ 1 12 Boolean Atomic Constraints (2)

13 L7-S13 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad Boolean equality constraints: T = B 0 Boolean inequality constraints: T ≠ B 0 where T is a Boolean term built from domain elements and operations of the boolean algebra. Example: ( x’ Λ z ) V ( y Λ z ) V ( x Λ y’ Λ z’ ) = B 0 13 Boolean Atomic Constraints (3)

14 L7-S14 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad each atomic constraint if F and G are formulas, then (F and G) is a formula and (F or G) is a formula. if F is a formula, then (not F) is a formula. 14 Constraint Formulas (1)

15 L7-S15 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad Let F(x 1,…,x n ) be a formula with n rows, t = (c 1,…,c n ) a tuple with n constants. t satisfies F (t F) – substituting each x i by c i makes F true. 15 Constraint Formulas (2)

16 L7-S16 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad Symbols are interpreted to be concrete operators or values. Example: D – all subsets of 1 Λ – intersection V – union ‘ – complement 0 – emptyset 1 – set of names of all animals {cat, dog, parrot,…} Question: What would be the meaning of the example Boolean constraint under this interpretation ? 16 Interpretation of free Boolean algebra

17 L7-S17 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad Example: Suppose we have the constraint b Λ m = 0 and we interpret b as {canary, parrot, falcon} m as {cat, dog} Question: Is the Boolean constraint true under this interpretation ? 17 Constants in constraints are also interpreted

18 L7-S18 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad Constraint data model provides a finite representation of the infinite relational data model. In constraint data model each attribute is associated with an attribute variable, and the value of the attributes in a relation is specified implicitly using constraints. A constraint database is a finite set of constraint relations. A constraint relation is a finite set of constraint tuples, –Where each constraint tuple is a conjunction of atomic constraints using the same set of attribute variables. 18 The Constraint Data Model (1)

19 L7-S19 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad Constraint relation – a finite set of constraint tuples. Constraint tuples – tuples with variables and constraints that restrict the variables. Example: ( i, t : 0 ≤ i, i ≤ 24000, t = 0.15 i ) is a constraint tuple of Taxtable(Income, Tax). It means that the tax is 15% on any income below $24,000. 19 The Constraint Data Model (2)

20 L7-S20 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad 20 The Constraint Data Model (3) IncomeTax it 0 ≤ i, i ≤ 24000, t = 0.15 i it 24000 < i, i ≤ 58150, t = 3600 + 0.28 (i – 24000) it 58150 < i, i ≤ 121300 t = 13162 + 0.31(i – 58150) it 121300 < i, i ≤ 263750, t = 32738.5 + 0.36 (i – 121300) it 263750 < i, t = 84020.5 + 0.396 (i – 263750) Taxtable

21 L7-S21 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad The taxtable constraint relation consists of only five contraint tuples. It represents the infinite relation that we described early. The constraints in the table are order constraints and linear equations over the rational numbers. 21 The Constraint Data Model (4)

22 L7-S22 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad The Go relation can be presented by the following constraint relation. Assumption: If the shortest path from city1 to city2 is some m minutes, then if we leave city1 at time t1 we may arrive at city2 at some time t2, such that 22 The Constraint Data Model (5) t2 – t1 ≥ m

23 L7-S23 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad 23 The Constraint Data Model (6) Go City 1time1City 2Time2 Omahat1Lincolnt2t2 – t1 ≥ 60 Omahat1Mplst2t2 – t1 ≥ 650 Omahat1De_Moinest2t2 – t1 ≥ 400 Mplst1Chicagot2t2 – t1 ≥ 370 De_Moinest1Chicagot2t2 – t1 ≥ 600 De_Moinest1Kansas_Cityt2t2 – t1 ≥ 180

24 L7-S24 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad In Go, we represent each connection between two cities by two constraint tuples. 24 The Constraint Data Model (7)

25 L7-S25 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad 25 The Constraint Data Model (8) RadioXY 1xy(x – 8) 2 + (y – 9) 2 ≤ 25 2xy(x – 8) 2 / 5 2 + (y – 3) 2 /3 2 ≤ 1 3xy(y – 1) ≥ (x – 3) 2, y ≤ 10 The first radio station broadcasts within a circle with center at location (8, 9) The second in an elliptic area The third in a parabolic area is cut off by a line. The broadcast relation can be expressed as a constraint relation with Quadratic constraints over the real number.

26 L7-S26 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad The data can be represented in the Crops relation using linear inequality constraints over rational numbers. 26 The Constraint Data Model (9) CornRyeSunflowerWheat x1x2x3x4 15x 1 + 8x 2 + 10x 3 + 15x 4 ≤ 3000 30x 1 + 25x 2 + 5x 3 + 10x 4 ≤ 8000

27 L7-S27 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad Each data model provides some abstraction about stored data. There are four levels of data abstraction, namely –View level –Logical level –Constraint Level –Physical level The various levels of data abstraction are linked by translation methods. 27 Data Abstraction (1)

28 L7-S28 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad  How users can view their data  For different sets of users different views can be provided by a database  We will see more examples of visualization used in the MLPQ and PReSTO constarint databases systems in chapter 18 and 20. 28 Data Abstraction: View Level

29 L7-S29 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad  Logical level – infinite relation r, tuple t  Describes what data are stored in terms of sets of infinite relations.  Discussed in Chapter 1 29 Data Abstraction: Logical Level

30 L7-S30 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad  Describes the data stored using one or more constraint relations.  There is a natural link between the logical and constraint levels. Let r be the infinite relational model and R be the constraint model of a relation. Then a tuple t is in r iff there is a constraint tuple C in R such that after substitution of the constants in t into the variables of C, we get a true formula, that is t satisfies C.  Constraint level – finite relation R, constraint tuple C, t є r iff t ╞ C for some C є R 30 Data Abstraction: Constraint Level

31 L7-S31 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad  Physical level – the way the data is actually stored in the computer system  We will see example of this in Chapter 17 31 Data Abstraction: Physical Level

32 L7-S32 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad T/F Constraint data model is used to represent the logical level of data in a concise way. Logical level is not suitable for computer to represent data. View view is suitable for computer to represent data. Constraint level describes the data stored using one or more constraint relations. Physical level corresponds to the way the data is actually stored in computer system 32 Discussion Questions

33 L7-S33 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad Exercise 2.1 Represent the Constraint relation Free in a relational form assuming that d is an integer. 33 Discussion Questions PersonDay Andrewd3 ≤ d, d ≤ 6 Andrewd16 ≤ d, d ≤ 26 Barbarad6 ≤ d, d ≤ 18 Barbarad25 ≤ d, d ≤ 30

34 L7-S34 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad 34 Solution PersonFree Andrew 3, 4, 5, 6 Andrew16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 Barbara6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 Barbara25, 26, 27, 28, 29, 30

35 L7-S35 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad Exercise 2.3 Using a constraint relation represent the street map shown in Figure 1.3 As following 35 Discussion Questions

36 L7-S36 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad 36 Solution NameXY Willowx yy=19, x =4 Harexy y=-2x+29, y>=11, y<=20 Bearxyy=1/3 *x + 10 1/3, 2<=x, x<=17 Vinexyx=5, y>=2, y<=14 Oakxyx=11, y>=2, y<=12 Maplexyy=5, x =7

37 L7-S37 Constraint DB © 2003-2006 M.E. Fayad SJSU – CmpE M.E. Fayad Relational Algebra SQL 37 Questions for the Next Lecture


Download ppt "© 2003-2006 M.E. Fayad SJSU -- CmpE Database Design Dr. M.E. Fayad, Professor Computer Engineering Department, Room #283I College of Engineering San José."

Similar presentations


Ads by Google