Upload
grace-nichols
View
224
Download
0
Embed Size (px)
Citation preview
2003 SJSU -- CmpE L6-S1 Constraint DB
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
2003 SJSU – CmpE --- M.E. Fayad L6-S2 Constraint DB
2
Lesson 06:Constraint Databases
2003 SJSU – CmpE --- M.E. Fayad L6-S3 Constraint DB
Lesson Objectives
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
2003 SJSU – CmpE --- M.E. Fayad L6-S4 Constraint DB
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
2003 SJSU – CmpE --- M.E. Fayad L6-S5 Constraint DB
Next level of data abstraction:
Constraint level – finitely represents
by constraints
the logical level
5
Constraint Databases
2003 SJSU – CmpE --- M.E. Fayad L6-S6 Constraint DB
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 W6
Two Most Common Types of Constraints
2003 SJSU – CmpE --- M.E. Fayad L6-S7 Constraint DB
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
Constraints (1)
2003 SJSU – CmpE --- M.E. Fayad L6-S8 Constraint DB
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)
2003 SJSU – CmpE --- M.E. Fayad L6-S9 Constraint DB
Half-Addition: ± u ± v ≥ b where b ≥ 0Addition: ± 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
Constraints (3)
2003 SJSU – CmpE --- M.E. Fayad L6-S10 Constraint DB
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)
2003 SJSU – CmpE --- M.E. Fayad L6-S11 Constraint DB
Boolean Algebra < D, Λ, V, ‘, 0, 1 >
D – domain,
0 – zero element,
1 – one element.
such that the following axioms hold:
11
Boolean Atomic Constraints (1)
2003 SJSU – CmpE --- M.E. Fayad L6-S12 Constraint DB
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)
2003 SJSU – CmpE --- M.E. Fayad L6-S13 Constraint DB
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)
2003 SJSU – CmpE --- M.E. Fayad L6-S14 Constraint DB
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)
2003 SJSU – CmpE --- M.E. Fayad L6-S15 Constraint DB
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
Constraint Formulas (2)
2003 SJSU – CmpE --- M.E. Fayad L6-S16 Constraint DB
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
2003 SJSU – CmpE --- M.E. Fayad L6-S17 Constraint DB
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
2003 SJSU – CmpE --- M.E. Fayad L6-S18 Constraint DB
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)
2003 SJSU – CmpE --- M.E. Fayad L6-S19 Constraint DB
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)
2003 SJSU – CmpE --- M.E. Fayad L6-S20 Constraint DB
20
The Constraint Data Model (3)
Income Tax
i t 0 ≤ i , i ≤ 24000, t = 0.15 i
i t 24000 < i , i ≤ 58150, t = 3600 + 0.28 (i – 24000)
i t 58150 < i , i ≤ 121300 t = 13162 + 0.31(i – 58150)
i t 121300 < i , i ≤ 263750, t = 32738.5 + 0.36 (i – 121300)
i t 263750 < i , t = 84020.5 + 0.396 (i – 263750)
Taxtable
2003 SJSU – CmpE --- M.E. Fayad L6-S21 Constraint DB
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)
2003 SJSU – CmpE --- M.E. Fayad L6-S22 Constraint DB
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
2003 SJSU – CmpE --- M.E. Fayad L6-S23 Constraint DB
23
The Constraint Data Model (6)
Go
City 1 time1 City 2 Time2
Omaha t1 Lincoln t2 t2 – t1 ≥ 60
Omaha t1 Mpls t2 t2 – t1 ≥ 650
Omaha t1 De_Moines t2 t2 – t1 ≥ 400
Mpls t1 Chicago t2 t2 – t1 ≥ 370
De_Moines t1 Chicago t2 t2 – t1 ≥ 600
De_Moines t1 Kansas_City t2 t2 – t1 ≥ 180
2003 SJSU – CmpE --- M.E. Fayad L6-S24 Constraint DB
In Go, we represent each connection between two cities by two constraint tuples.
24
The Constraint Data Model (7)
2003 SJSU – CmpE --- M.E. Fayad L6-S25 Constraint DB
25
The Constraint Data Model (8)
Radio X Y
1 x y (x – 8)2 + (y – 9)2 ≤ 25
2 x y (x – 8)2 / 52 + (y – 3)2/32 ≤ 1
3 x y (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 areaThe 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.
2003 SJSU – CmpE --- M.E. Fayad L6-S26 Constraint DB
The data can be represented in the Crops relation using linear inequality constraints over rational numbers. 26
The Constraint Data Model (9)
Corn Rye Sunflower Wheat
x1 x2 x3 x4
15x1 + 8x2 + 10x3 + 15x4 ≤ 3000
30x1 + 25x2 + 5x3 + 10x4 ≤ 8000
2003 SJSU – CmpE --- M.E. Fayad L6-S27 Constraint DB
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)
2003 SJSU – CmpE --- M.E. Fayad L6-S28 Constraint DB
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
2003 SJSU – CmpE --- M.E. Fayad L6-S29 Constraint DB
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
2003 SJSU – CmpE --- M.E. Fayad L6-S30 Constraint DB
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
2003 SJSU – CmpE --- M.E. Fayad L6-S31 Constraint DB
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
2003 SJSU – CmpE --- M.E. Fayad L6-S32 Constraint DB
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
2003 SJSU – CmpE --- M.E. Fayad L6-S33 Constraint DB
Exercise 2.1 Represent the Constraint relation Free in a relational form assuming that d is an integer.
33
Discussion Questions
Person Day
Andrew d 3 ≤ d, d ≤ 6
Andrew d 16 ≤ d, d ≤ 26
Barbara d 6 ≤ d, d ≤ 18
Barbara d 25 ≤ d, d ≤ 30
2003 SJSU – CmpE --- M.E. Fayad L6-S34 Constraint DB
34
Solution
Person FreeAndrew 3, 4, 5, 6Andrew 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26Barbara 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18Barbara 25, 26, 27, 28, 29, 30
2003 SJSU – CmpE --- M.E. Fayad L6-S35 Constraint DB
Exercise 2.3 Using a constraint relation represent the street map shown in Figure 1.3 As following
35
Discussion Questions
2003 SJSU – CmpE --- M.E. Fayad L6-S36 Constraint DB
36
Solution
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 + 10 1/3, 2<=x, x<=17
Vine x y x=5, y>=2, y<=14
Oak x y x=11, y>=2, y<=12
Maple x y y=5, x<=20, x>=7
2003 SJSU – CmpE --- M.E. Fayad L6-S37 Constraint DB
Relational Algebra
SQL
37
Questions for the Next Lecture