Sunday, 8 November 2020

DBMS : Tuple Relational Calculus (TRC)

 

Tuple Relational Calculus (TRC):

  • Tuple relational calculus is a non-procedural query language.
  • Tuple relational calculus is based on specifying a number of tuple variables.
  • Each variable usually ranges over a particular database relation.
  • The general form of tuple relational calculus is as follows:

{t | COND (t)}

  • Where ‘t’ is a tuple variable and COND(t)  is a conditional expression involving t. The result of such a query is the set of all tuples ‘t’ that satisfy COND (t).
  • For ex: to find all employees whose salary is above 50000 we write:

 

{t | Employee (t) and t.salary>50000}

  • Tuple relational calculus general form is read as, “it is a set of all tuple t such that the condition COND is true for the value of tuple t”. Informally, we need to specify the following information in a tuple calculus expression:

 

  1. For each tuple variable ‘t’, the range relation ‘R’ is of ‘t’. This value is specified by a condition of the form R (t).
  2. A condition to select particular combination of tuples. As variables range over their respective range relations, the condition is evaluated for every possible combination of tuples to identify the selected combinations for which the condition evaluates true.
  3. A set of attributes to be retrieved i.e. the requested attributes. The values of these attributes are retrieved for each selected combination of tuples.

 

 Examples:

 

  1. Retrieve the name and address of all employees who work for the ‘Research’ department.

 

{ t.FNAME ,t.LNAME,t.ADDRESS/EMPLOYEE(t)

and (d)(DEPARTMENT(d).and d.DNAME= ‘Research’ and

d.DNUMBER=t.DNO)}

 

  1. Make a list of project numbers for projects that involve an employee whose last name is Ram, either as a worker or as manager of the controlling department for the project.

{ p.PNUMBER/PROJECT(P) AND (( (e) (w)

(EMPLOYEE(e) and WORKS_ON(W) and

W.PNO=P.PNUMBER and e.LNAME= ‘RAM’ and e.SSN=W.ESSN))

 

 

Safety of Expressions in Tuple Relational Calculus:

  • A tuple relational calculus expression may generate an infinite expression.
  • Suppose the expression:

{t |(t borrow)}

  • There are infinite number of tuples that are not in borrow. Most of these tuples contain values that do not appear in the database.

 

 For Safe Tuple Expressions:

  • We need to restrict the relational calculus a bit. The domain of a formula P, denoted by dom(P) or DOM(P), is the set of all values referenced in P.
  • These include values mentioned in P as well as values that appear in a tuple of a relation mentioned in P.
  • So, the domain of P is the set of all values explicitly appearing in P or that appear in the relations mentioned in P.

dom ( t borrow ^ t[amount]<1200)

is the set of all values appearing in borrow.

dom (t |(t borrow))

is the set of all values appearing in borrow.


  • We may say an expression {t |P (t)} is safe, if all values that appear in the result array are values from dom(P).
  • A safe expression yields a finite number of tuples as its result. Otherwise, it is called unsafe.
  • A safe expression is one that is guaranteed to yield finite number of tuples as its results. Otherwise, it is called unsafe.

No comments:

Post a Comment