Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Design Dr. M.E. Fayad, Professor

Similar presentations


Presentation on theme: "Database Design Dr. M.E. Fayad, Professor"— Presentation transcript:

1 Database Design Dr. M.E. Fayad, Professor
5/1/2019 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 © M.E. Fayad SJSU -- CmpE

2 Lesson 11: Constraint Databases
5/1/2019 Lesson 11: Constraint Databases 2 © M.E. Fayad SJSU – CmpE M.E. Fayad

3 3 Lesson Objectives Understand Constraint Databases
5/1/2019 Lesson Objectives 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 3 © M.E. Fayad SJSU – CmpE M.E. Fayad

4 View and Logical Levels
5/1/2019 View and Logical Levels 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 © M.E. Fayad SJSU – CmpE M.E. Fayad

5 5 Constraint Databases Next level of data abstraction:
5/1/2019 Constraint Databases Next level of data abstraction: Constraint level – finitely represents by constraints the logical level 5 © M.E. Fayad SJSU – CmpE M.E. Fayad

6 Two Most Common Types of Constraints
5/1/2019 Two Most Common Types of Constraints 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 © M.E. Fayad SJSU – CmpE M.E. Fayad

7 7 Constraints (1) Assume u and v are variables or constants
5/1/2019 Constraints (1) Assume u and v are variables or constants B and ci are constants Let ± denote + or - Let p be a polynomial function over variables X1, …., Xn 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 © M.E. Fayad SJSU – CmpE M.E. Fayad

8 8 Constraints (2) Arithmetic Atomic Constraints Inequality: u ≠ v
5/1/2019 Constraints (2) 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 © M.E. Fayad SJSU – CmpE M.E. Fayad

9 9 Constraints (3) Half-Addition: ± u ± v ≥ b where b ≥ 0
5/1/2019 Constraints (3) Half-Addition: ± u ± v ≥ b where b ≥ 0 Addition: ± u ± v ≥ b Linear: c1x1 + ……+ cnxn ≥ b Polynomial: p( x1,……..,xn ) ≥ 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. ci is a coefficient in the linear constraint. 9 © M.E. Fayad SJSU – CmpE M.E. Fayad

10 5/1/2019 Constraints (4) 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 © M.E. Fayad SJSU – CmpE M.E. Fayad

11 Boolean Atomic Constraints (1)
5/1/2019 Boolean Atomic Constraints (1) Boolean Algebra < D, Λ, V, ‘, 0, 1 > D – domain, 0 – zero element, 1 – one element. such that the following axioms hold: 11 © M.E. Fayad SJSU – CmpE M.E. Fayad

12 Boolean Atomic Constraints (2)
5/1/2019 Boolean Atomic Constraints (2) 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 © M.E. Fayad SJSU – CmpE M.E. Fayad

13 Boolean Atomic Constraints (3)
5/1/2019 Boolean Atomic Constraints (3) 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 © M.E. Fayad SJSU – CmpE M.E. Fayad

14 Constraint Formulas (1)
5/1/2019 Constraint Formulas (1) 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 © M.E. Fayad SJSU – CmpE M.E. Fayad

15 Constraint Formulas (2)
5/1/2019 Constraint Formulas (2) Let F(x1,…,xn) be a formula with n rows, t = (c1,…,cn) a tuple with n constants. t satisfies F (t F) – substituting each xi by ci makes F true. 15 © M.E. Fayad SJSU – CmpE M.E. Fayad

16 Interpretation of free Boolean algebra
5/1/2019 Interpretation of free Boolean algebra 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 © M.E. Fayad SJSU – CmpE M.E. Fayad

17 Constants in constraints are also interpreted
5/1/2019 Constants in constraints are also interpreted 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 © M.E. Fayad SJSU – CmpE M.E. Fayad

18 The Constraint Data Model (1)
5/1/2019 The Constraint Data Model (1) 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 © M.E. Fayad SJSU – CmpE M.E. Fayad

19 The Constraint Data Model (2)
5/1/2019 The Constraint Data Model (2) Constraint relation – a finite set of constraint tuples. Constraint tuples – tuples with variables and constraints that restrict the variables. Example: ( i, t : ≤ 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 © M.E. Fayad SJSU – CmpE M.E. Fayad

20 The Constraint Data Model (3)
5/1/2019 The Constraint Data Model (3) Income Tax i t 0 ≤ i , i ≤ 24000, t = 0.15 i 24000 < i , i ≤ 58150, t = (i – 24000) 58150 < i , i ≤ t = (i – 58150) < i , i ≤ , t = (i – ) < i , t = (i – ) 20 Taxtable © M.E. Fayad SJSU – CmpE M.E. Fayad

21 The Constraint Data Model (4)
5/1/2019 The Constraint Data Model (4) 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 © M.E. Fayad SJSU – CmpE M.E. Fayad

22 The Constraint Data Model (5)
5/1/2019 The Constraint Data Model (5) 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 t2 – t1 ≥ m 22 © M.E. Fayad SJSU – CmpE M.E. Fayad

23 The Constraint Data Model (6)
5/1/2019 The Constraint Data Model (6) City 1 time1 City 2 Time2 Omaha t1 Lincoln t2 t2 – t1 ≥ 60 Mpls t2 – t1 ≥ 650 De_Moines t2 – t1 ≥ 400 Chicago t2 – t1 ≥ 370 t2 – t1 ≥ 600 Kansas_City t2 – t1 ≥ 180 23 Go © M.E. Fayad SJSU – CmpE M.E. Fayad

24 The Constraint Data Model (7)
5/1/2019 The Constraint Data Model (7) In Go, we represent each connection between two cities by two constraint tuples. 24 © M.E. Fayad SJSU – CmpE M.E. Fayad

25 The Constraint Data Model (8)
5/1/2019 The Constraint Data Model (8) Radio X Y 1 x y (x – 8)2 + (y – 9)2 ≤ 25 2 (x – 8)2 / 52 + (y – 3)2/32 ≤ 1 3 (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. 25 © M.E. Fayad SJSU – CmpE M.E. Fayad

26 The Constraint Data Model (9)
5/1/2019 The Constraint Data Model (9) Corn Rye Sunflower Wheat x1 x2 x3 x4 15x1 + 8x2 + 10x3 + 15x4 ≤ 3000 30x1 + 25x2 + 5x3 + 10x4 ≤ 8000 The data can be represented in the Crops relation using linear inequality constraints over rational numbers. 26 © M.E. Fayad SJSU – CmpE M.E. Fayad

27 5/1/2019 Data Abstraction (1) 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 © M.E. Fayad SJSU – CmpE M.E. Fayad

28 Data Abstraction: View Level
5/1/2019 Data Abstraction: View Level 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 © M.E. Fayad SJSU – CmpE M.E. Fayad

29 Data Abstraction: Logical Level
5/1/2019 Data Abstraction: Logical Level Logical level – infinite relation r, tuple t Describes what data are stored in terms of sets of infinite relations. Discussed in Chapter 1 29 © M.E. Fayad SJSU – CmpE M.E. Fayad

30 Data Abstraction: Constraint Level
5/1/2019 Data Abstraction: Constraint Level 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 © M.E. Fayad SJSU – CmpE M.E. Fayad

31 Data Abstraction: Physical Level
5/1/2019 Data Abstraction: Physical Level Physical level – the way the data is actually stored in the computer system We will see example of this in Chapter 17 31 © M.E. Fayad SJSU – CmpE M.E. Fayad

32 32 Discussion Questions T/F
5/1/2019 Discussion Questions 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 level 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 © M.E. Fayad SJSU – CmpE M.E. Fayad

33 5/1/2019 Discussion Questions Exercise 2.1 Represent the Constraint relation Free in a relational form assuming that d is an integer. Person Day Andrew d 3 ≤ d, d ≤ 6 16 ≤ d, d ≤ 26 Barbara 6 ≤ d, d ≤ 18 25 ≤ d, d ≤ 30 33 © M.E. Fayad SJSU – CmpE M.E. Fayad

34 34 Solution Person Free Andrew 3, 4, 5, 6
5/1/2019 Solution Person Free Andrew 3, 4, 5, 6 Andrew 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 Barbara 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 Barbara 25, 26, 27, 28, 29, 30 34 © M.E. Fayad SJSU – CmpE M.E. Fayad

35 5/1/2019 Discussion Questions Exercise 2.3 Using a constraint relation represent the street map shown in Figure 1.3 As following 35 © M.E. Fayad SJSU – CmpE M.E. Fayad

36 36 Solution Name X Y Willow x y y=19, x<=20, x>=4 Hare x y
5/1/2019 Name X Y Willow x y y=19, x<=20, x>=4 Hare x y y=-2x+29, y>=11, y<=20 Bear x y y=1/3 *x /3, 2<=x, x<=17 Vine x y x=5, y>=2, y<=14 Oak x y x=11, y>=2, y<=12 36 Maple x y y=5, x<=20, x>=7 © M.E. Fayad SJSU – CmpE M.E. Fayad

37 Questions for the Next Lecture
5/1/2019 Questions for the Next Lecture Relational Algebra SQL 37 © M.E. Fayad SJSU – CmpE M.E. Fayad


Download ppt "Database Design Dr. M.E. Fayad, Professor"

Similar presentations


Ads by Google