Sunday, 8 November 2020

DBMS : Domain Relational Calculus (DRC)

 

Domain Relational Calculus (DRC):

  • The domain relational calculus is a calculus that was introduced as a declarative database query language for the relational data model.
  • It uses domain variables that take on value from an attribute domain rather than value for an entire tuple.
  • To form a relation of degree for a query result, we must have ‘n’ of these domain variable one for each attribute.
  • An expression is in the form:

{< x1,x2,...,xn> | P(x1,x2,...,xn)}

 

where xi, 1<=i<=n, represent domain variables and P is a formula.

  • An atom in the domain relational calculus is of the following form:

  1. {< x1,x2,...,xn > r, where ‘r’ is a relation on ‘r’ attributes and xi, 1<=i<=n are domain variables or constants.
  2. x Ө y, where x and y are domain variables, and  Ө  is a comparison operator.
  3. x Ө c, where c is a constant.

  • Formulae are built up from atoms using the following rules:

  1.  An atom is a formula.
  2.  If P is a formula, then so are P and (P).
  3. If P1 and P2 are formulae, then so are P1 P2, P1 P2 and P1=>P2.
  4. If P(x) is a formula, where x is a domain variable, then so are x (P(x)) and x (P(x)).

 

Examples:

 

a)    Find branch name, loan number, customer name and amount for loans of over $1200.

 

{<b,l,c,a>|<b,l,c,a> borrow  a>1200 }

 

b)    Find all customers who have a loan for an amount greater than $1200.

 

{<c>| b,l,a <b,l,c,a> borrow  a>1200 }

 

c)    Find all customers having a loan from the Miami branch and the city in which they live.

 

{<c,x>| b,l,a <b,l,c,a> borrow  b= “Miami” Y(<c,y,x> customer))) }

 

 

Safety of Expressions in Domain Relational Calculus:

  • In tuple relational calculus, it is possible to write expressions that may generate infinite relations. The same situation arises for a domain relational calculus.
  • In the domain relational calculus, we must concern about the formula within “there exists” and “for all”.
  • Consider the expression:

 

{x| (<x,y> r) Λ z ((<x,z>r) Λ P (x,z))}

  • In the second part of this expression; z ((<x,z>r)ΛP(x,z))} we need to consider values for z that do not appear in r .
  • This set of values actually is an infinite set.
  • This case does not appear in the tuple relational calculus because, in tuple relational calculus, the universal and existential quantifiers are applied on variables that already range over a specific relation (in the form t r (P (t)) and t r (P (t))).
  • Therefore, in DRC, an expression {<x1, x2, …,xn> | P(x1, x2, …,xn)} is safe if all the following condition holds:

 

  1. All values in the result are values from DOM (P).
  2. For every “there exists” sub formula of the form x (P1(x)), the sub formula is true if there is a value x in DOM (P1) such that P1(x) is true.
  3. For every “for all” sub formula of the form x (P2(x)), the sub formula is true if for all values x from DOM (P2), P2(x) is true.

No comments:

Post a Comment