# DomainCalculus

Document Sample

```					               Domain Calculus
• Another form of relational calculus
• Uses domain variables that take values from
an attribute’s domain, rather than values
representing an entire tuple
• Closely related to tuple calculus
• Domain Calculus serves as the theoretical
basis for the query language QBE, just as the
relational algebra we examined earlier forms
the basis for SQL
• Expressions are of the form:
{< x1, x2, x3, ..., xn> | P( x1, x2, x3, ..., xn) }
Domain Calculus

• Atoms
– < x1, x2, x3, ..., xn>  R
– x y                  where x,y are domain variables and
  {, , , , , }
– x c                  where c is a constant

• Formulas
– an atom is a formula
– If P and Q are formulas, then so are (P), P, PQ, PQ, and
PQ
– If P(x) is a formula and x is a domain variable, then x P(x)
and x P(x) are also formulas
Domain Calculus

• Queries are of the form:
{< x1, x2, x3, ..., xn> | P( x1, x2, x3, ..., xn) }

• Examples

{<ss#, course#, semester> | Enroll(ss#, course#, semester)}

{<x, y, z> | Enroll(x, y, z)  y = CSE132A}
Domain Relational Calculus
• Style of QBE:variables represent values, not
tuples
• Difference with tuple calculus: instead of tuple
variable t use different variable for each value
t(A)

• Examples (movie database)
Query 1:
{t: TITLE | ∃s: THEATER (SCHEDULE(s, t))}
• Query 2.

{t: TITLE | ∃a: ACTOR(MOVIE(t, “BERTO”, a))}

• Query 3.

{t: TITLE d: DIRECTOR | ∃x: THEATER ∃a: ACTOR
(MOVIE(t d a) ∧ SCHEDULE(x t))}

• Rules: similar to tuple calculus

–Simplest formulas: R(x1…xn)
x comp y
x comp <const>

–Boolean combinations: ∧, ∨, ¬
–Quantifiers: ∃x:A ϕ(x), ∀x:A ϕ(x) where x is free in ϕ
Using Domain Calculus to
Formulate QBE Queries
•Similar to tuple calculus and SQL
•Example: Movie DB with an additional table
LIKES (NAME, TITLE)
Query: “Find people who like all movies”
•Domain calculus:
{n: NAME | ∀t: TITLE ∀d: DIR ∀a: ACTOR
(MOVIE(tda) →LIKES(nt))}
•Eliminate ∀:
{n: NAME | ¬∃t: TITLE ∃d: DIR ∃a:
ACTOR(MOVIE(tda) ∧¬LIKES(nt))}
• Find directors of currently playing movies:

–Domain calculus:
{d: DIR | ∃t: TITLE ∃a: ACTOR ∃s:
THEATER (MOVIE(tda)
∧SCHEDULE(st))}

–Algebra:
πDIR(MOVIE ><SCHEDULE)
• Examples

• Database schema:
–PERSON : NAME AGE

• Query: FIND OLDEST PERSON(S)

• Domain calculus
{n: NAME | ∃a: AGE(PERSON(na) ∧
¬∃a’: AGE ∃n’: NAME (PERSON(n’a’) ∧a<a’))}

• Algebra
πNAME(PERSON) −πNAME
(σAGE<AGE’(PERSON><δAGE→AGE’(πAGE(PERSON))))

```
DOCUMENT INFO
Shared By:
Categories:
Stats:
 views: 3 posted: 3/4/2010 language: English pages: 8