Domain Relational Calculus

Domain Relational Calculus
In the tuple relational calculus, we use variables that range over tuples in a relation. In the
domain relational calculus, we also use variables but in this case the variables take their
values from domains of attributes rather than tuples of relations. An expression in the
domain relational calculus has the following general form:
{d1, d2, . . . , dn | F(d1, d2, . . . , dm)} m . n
where d1, d2, . . . , dn, . . . , dm represent domain variables and F(d1, d2, . . . , dm) represents a
formula composed of atoms, where each atom has one of the following forms:
n R(d1, d2, . . . , dn), where R is a relation of degree n and each di is a domain variable.
n di Į dj, where di and dj are domain variables and Į is one of the comparison operators
(<, ., >, ., =, ‚); the domains di and dj must have members that can be compared
by Į.
n di Į c, where di is a domain variable, c is a constant from the domain of di, and Į is one
of the comparison operators.
We recursively build up formulae from atoms using the following rules:
n An atom is a formula.
n If F1 and F2 are formulae, so are their conjunction F1 È F2, their disjunction F1 É F2, and
the negation ~F1.
n If F is a formula with domain variable X, then (ÎX)(F) and (ÍX)(F) are also formulae.
Example 4.15 Domain relational calculus
In the following examples, we use the following shorthand notation:
(Îd1, d2, . . . , dn) in place of (Îd1), (Îd2), . . . , (Îdn)
(a) Find the names of all managers who earn more than ’25,000.
{fN, lN | (ÎsN, posn, sex, DOB, sal, bN) (Staff(sN, fN, lN, posn, sex, DOB, sal, bN) È
posn = eManagerf È sal > 25000)}
If we compare this query with the equivalent tuple relational calculus query in Example 4.12(a),
we see that each attribute is given a (variable) name. The condition Staff(sN, fN, . . . , bN)
ensures that the domain variables are restricted to be attributes of the same tuple. Thus,
we can use the formula posn = eManagerf, rather than Staff.position = eManagerf. Also note
the difference in the use of the existential quantifier. In the tuple relational calculus, when
we write Îposn for some tuple variable posn, we bind the variable to the relation Staff by
writing Staff(posn). On the other hand, in the domain relational calculus posn refers to a
domain value and remains unconstrained until it appears in the subformula Staff(sN, fN, lN,
posn, sex, DOB, sal, bN) when it becomes constrained to the position values that appear in
the Staff relation.
For conciseness, in the remaining examples in this section we quantify only those
domain variables that actually appear in a condition (in this example, posn and sal).
(b) List the staff who manage properties for rent in Glasgow.
{sN, fN, lN, posn, sex, DOB, sal, bN | (ÎsN1, cty) (Staff(sN, fN, lN, posn, sex, DOB, sal, bN) È
PropertyForRent(pN, st, cty, pc, typ, rms, rnt, oN, sN1, bN1) È (sN = sN1) È
cty = eGlasgowf)}
This query can also be written as:
{sN, fN, lN, posn, sex, DOB, sal, bN | (Staff(sN, fN, lN, posn, sex, DOB, sal, bN) È
PropertyForRent(pN, st, eGlasgowf, pc, typ, rms, rnt, oN, sN, bN1))}
In this version, the domain variable cty in PropertyForRent has been replaced with the constant
eGlasgowf and the same domain variable sN, which represents the staff number, has
been repeated for Staff and PropertyForRent.
(c) List the names of staff who currently do not manage any properties for rent.
{fN, lN | (ÎsN) (Staff(sN, fN, lN, posn, sex, DOB, sal, bN) È
(~(ÎsN1) (PropertyForRent(pN, st, cty, pc, typ, rms, rnt, oN, sN1, bN1) È (sN = sN1))))}
(d) List the names of clients who have viewed a property for rent in Glasgow.
{fN, lN | (ÎcN, cN1, pN, pN1, cty) (Client(cN, fN, lN, tel, pT, mR) È
Viewing(cN1, pN1, dt, cmt) È PropertyForRent(pN, st, cty, pc, typ, rms, rnt, oN, sN, bN) È
(cN = cN1) È (pN = pN1) È cty = eGlasgowf)}
(e) List all cities where there is either a branch office or a property for rent.
{cty | (Branch(bN, st, cty, pc) ∨
PropertyForRent(pN, st1, cty, pc1, typ, rms, rnt, oN, sN, bN1))}
(f) List all the cities where there is a branch office but no properties for rent.
{cty | (Branch(bN, st, cty, pc) ∧
(~(∃cty1) (PropertyForRent(pN, st1, cty1, pc1, typ, rms, rnt, oN, sN, bN1) ∧ (cty = cty1))))}
(g) List all the cities where there is both a branch office and at least one property
for rent.
{cty | (Branch(bN, st, cty, pc) ∧
(∃cty1) (PropertyForRent(pN, st1, cty1, pc1, typ, rms, rnt, oN, sN, bN1) ∧ (cty = cty1)))}
These queries are safe. When the domain relational calculus is restricted to safe expressions,
it is equivalent to the tuple relational calculus restricted to safe expressions, which
in turn is equivalent to the relational algebra. This means that for every relational algebra
expression there is an equivalent expression in the relational calculus, and for every
tuple or domain relational calculus expression there is an equivalent relational algebra
expression.
Domain Relational Calculus Domain Relational Calculus Reviewed by Shopping Sale on 22:19 Rating: 5

No comments:

Powered by Blogger.