Download free books at BookBooN.com
An Introduction to Relational Database Theory
111
Relational Algebra – The Foundation
x Unlike JOIN, UNION does not have a single identity value. The normal set-theory union operator
does have an identity value, namely, the empty set. But relations have headings and there is no
single heading that can be the heading of a relation that, when unioned with any relation r, yields r.
However, we can note that if re is the empty relation of the same type as r, then r UNION re = r.
For that reason, Tutorial D, for what it’s worth, does allow you the take the union of no relations
at all, so long as you specify the heading of the desired result. For example:
UNION { x CHAR, y INTEGER, z SID } { }
If the key word UNION is replaced by RELATION, that would yield the same result of course.
Now you may well ask, what is the point of being able to take the union of no relations? Well, experience
shows that it is a mistake in a computer language to legislate against support for empty operands when the
operation in question has a mathematically respectable definition. Sometimes scripts in a desired language
are generated for us by special-purpose software; legislating against something that is definable but
apparently pointless sometimes turns out to be inconvenient for the developers of the generating software.
I know of several cases in SQL, for example, where that kind of concern has arisen. In particular, standard
SQL has no counterparts of TABLE_DEE and TABLE_DUM, nor does it allow one to express unions and
joins with no operands.
There remains one logical operator that I have not given you a relational counterpart of yet: negation. We
shall see that, as with OR, we have to restrict ourselves to certain special cases involving negation, and
these cases are addressed by a dyadic operator that goes by the strange name semidifference.
4.10 Semidifference and NOT
Consider the negation of the predicate for IS_CALLED: “Student StudentId is NOT called Name.” We run
into the same problem as that one we encountered with disjunction, for its extension includes
instantiations such as “Student S1 is not called Jane”, “Student S97431 is not called Anne”, “Student S1 is
not called Xdfrtghyuz”, and so on, ad infinitum (“almost”!). The term unsafe is sometimes used in
connection with predicates such as these, where the corresponding relation is likely to be of such
inordinately high cardinality as to be not computable in practice. It is no coincidence that both negation
and disjunction are unsafe in general: recall that pq is equivalent to ¬(¬p¬q).
So, when exactly can we “safely” use negation? Here is one example:
StudentId is called Devinder AND StudentId is NOT enrolled on C1.
Here we use AND to connect two predicates that have the same parameterthe same restriction as the one
we needed for disjunction. In this case, though, the second is negated. In Tutorial D we can obtain the
relation representing this predicate by using an operator named MINUS, as shown in Example 4.10.
MINUS is a relational counterpart of set difference and is subject to exactly the same restriction as UNION
concerning the types of its operands.