Domain relational calculus (DRC) is a formal query language that is ‘non-procedural’ and ‘declarative’. Being a form of relational calculus the domain relation calculus also specifies what information has to be retrieved, not how that information has to be retrieved.
Domain relational calculus is much similar to the tuple relational calculus the only difference is that the variables it uses in the formula are the domain variables. The domain variable is the variable whose value ranges over the domain of an attribute.
DRC forms the basis for the language Query-By-Example (QBE) as the tuple relation calculus form the basis for structured query language (SQL). In the section ahead we will discuss the format of the expression in DRC.
Expressions in Domain Relation Calculus
To retrieve the information using domain relation calculus the expressions are of the form:
{< x1, x2, . . . , xn > | P(x1, x2, . . . , xn)}
You can observe the expression above is expressed in two parts. The first part presents the list of the domain variables whose values we are expecting the result relation and the second part represent the formula or condition that must be satisfied by the specified domain variables.
The formula in the above expression is made of several atoms where an atom is a formula that doesn’t have a deeper propositional structure or we can say a formula that doesn’t hold any subformula. In short, an atom is a simple formula made of simple logic. These atoms can be of the following form:
- < x1, x2, . . . , xn > ∈ r this means all the domain variables from x1 to xn are the attributes to the relation r.
- The formula may have xi op xj where op is the comparison operator which could be anything from <, ≤, =, =, >, ≥ and xi and xj are the attributes or domain variables that can be compared.
- The atom may be of the form xi op c where again op is the comparison operator and c is the constant that has to be compared with the domain variable xi.
Now we use the following rules to define the formula in domain relation calculus expression.
- If you are considering P1 as a formula then ¬P1 and (P1) are also the formula.
- If we have P1 and P2 as formulae then P1 ∨ P2, P1 ∧ P2, and P1 ⇒ P2 are also the formulae.
- If P1(x) is a formula where x is a free domain variable then ∃ x (P1(x)) and ∀ x (P1(x)).
Queries in Domain Relational Calculus
Let us overview some examples of domain relational calculus. Let us consider we have a relation instructor with domain variables ID, Name, Dept_Name, Salary.
Now if you have to determine details of all the instructors then domain relational calculus expression for the same would be
{<I,n, d, s>/<I,n,d, s> ∈ instructor}
To select the name of the instructor whose salary is greater than $50,000, the expression would be
{<n>/<I,n,d, s> ∈ instructor ∧ s > 50000}
Safety Expression
A Domain relation calculus expression is considered a safe expression if it produces a finite number of values that are present in the domain of the expression. The expression below is unsafe as it will result in values that are not in the domain of the expression.
{ c< i, n, d, s > | ¬(< i, n, d, s > ∈ instructor )}
To define a restriction to the relational calculus formula so, that it yields a finite number of values referenced by the domain of the formula we must include ‘there exist’ and ‘for all’ clauses with the following rules.
- All the values appearing in the result of domain relational calculus expression must be from dom(P).
- The subformula, ∃ x (P1(x)) including ‘there exist’ clause is true if there exists a value x in the domain of the formula P1 i.e. dom(P1), and such that P1(x) is true.
- The subformula, ∀x (P1(x)) including ‘for all’ clause is true if, for all values of x, P1 (x) is true from dom(P1).
The restrictions we defined above reduces the expression to the finite number of tuples that we have to consider to determine the result of the expression.
To find all the instructor ID in the database whose salary is greater than 50000 the expression would be:
{< i > | ∃ n, d, s (< i, n, d, s > ∈ instructor ∧ s > 80000)}
Expressive Power of Languages
The safe expressions in domain relational calculus are equivalent to the safe expressions in tuple relational calculus. On the other hand, when tuple relational calculus is restricted to the safe expression it becomes equivalent to relational algebra.
In short, all three i.e., basic relational algebra expression, restricted safe tuple relational calculus expression and restricted safe domain relational calculus expression has the equivalent expressive power. Although, like tuple relational calculus, the domain relational calculus is also unable to express aggregation, grouping and ordering but, it can be extended to support all this.
So, this is all about the domain relational calculus that is a non-procedural declarative language. The domain relational calculus uses the domain variables in the formula to retrieve the desired information and it is the basis for the language query-by-example QBE.
Leave a Reply