Download free books at BookBooN.com
An Introduction to Relational Database Theory
109
Relational Algebra – The Foundation
Let’s think about the extension of “Student StudentId is called Name or is enrolled on course CourseId”.
Here is a true instantiation that we can determine by examination of the current values of IS_CALLED
and IS_ENROLLED on:
Student S1 is called Anne or is enrolled on course C1.
So TUPLE {StudentId SID('S1'), Name NAME('Anne'), CourseId CID('C1')}
clearly appears in the body of the corresponding relation. But the following instantiations are also true:
(a) Student S1 is called Anne or is enrolled on course C3.
(b) Student S1 is called Jane or is enrolled on course C1.
(c) Student S1 is called Anne or is enrolled on course C4751.
(d) Student S1 is called Xdfrtghyuz or is enrolled on course C1.
In case (a) the first disjunct, “Student S1 is called Anne”, is true and the second is false. A similar remark
applies to case (c), even though, as it happens, course C4751 doesn’t even existthe corresponding tuple
appears in the relation because CID('C4751') does denote a value of type CID (and S1’s name is
Anne). Cases (b) and (d) connect true statements about enrolments with false ones about names. In (d),
though we can perhaps be 100% certain that nobody has ever been called Xdfrtghyuz, I am assuming that
NAME('Xdfrtghyuz') is a value of type NAME (it would be difficult to define the type in such a way
as to exclude such possibilities).
You can see, then, that the extension of the disjunctive predicate contains an inordinately large number of
instantiations compared with the extension of the much more restrictive conjunctive predicate. In practical
terms, the corresponding relation is too big, would take too much time to be computed, and in any case
isn’t very useful. For those reasons, Codd deliberately excluded a general relational counterpart of OR
from his relational algebra. However, noting that some disjunctive predicates do not suffer from this
problem, he did include a dyadic operator, UNION, to give relations representing just those special cases.
Codd noted that the relation for a predicate of the form p OR q is computablethe problem just described
does not ariseif p and q have exactly the same set of parameters and the relations for p and q are
computable. His UNION operator, therefore, requires its relation operands to be of the same type (i.e., to
have the same heading).
Consider, then, the predicate
Student StudentId is called Devinder OR student StudentId is enrolled on course C1.
The two disjuncts both have just the one parameter, StudentId. The first disjunct is derived from the
predicate for IS_CALLED by substituting a value for the Name parameter (thus binding it); the second is
derived from the predicate for IS_ENROLLED_ON by similarly binding the CourseId parameter.
Although the expression IS_CALLED UNION IS_ENROLLED_ON is illegal in Tutorial D, for the
reason I have given, the expression given in Example 4.9 is legal.