Download free books at BookBooN.com
An Introduction to Relational Database Theory
141
Building on The Foundation
Monadic: RENAME, projection, WHERE (restriction), EXTEND, SUMMARIZE … BY, GROUP,
UNGROUP, WRAP, UNWRAP
Dyadic: JOIN, UNION, INTERSECT, NOT MATCHING (semidifference), MINUS (difference),
MATCHING (semijoin), COMPOSE, SUMMARIZE … PER
n-adic: JOIN { … }, UNION { … }, INTERSECT { … }
There remain to be described various non-relational operators that involve tuples or relations and are
defined in Tutorial D, being deemed useful additional ingredients of a relational database language.
5.9 Relation Comparison
The operators described in this section are especially useful for defining database constraints, as described
in Chapter 6, but they can be useful in queries too.
You are familiar with comparisons: dyadic, truth-valued or Boolean operators whose operands are of the
same type. For example, comparisons of the form x = y, where x and y are expressions of the same type,
are available for all types in Tutorial D, as you would surely expect. However, some computer languages
do not support “=” for all the types they recognize, and some do not support it correctly!i.e., in the strict
sense that is needed for relational databases.
A Note on Equality
In Tutorial D, the literals TRUE and FALSE denote the only two values of the type named BOOLEAN,
commonly called truth values. The comparison x = y yields TRUE if the expressions x and y denote the
same value; otherwise (they denote different values) it yields FALSE. That is the strict sense I just
mentioned. As a consequence, if an expression w contains one or more appearances of x and we obtain
expression w' from w by replacing every appearance of x by y, then w = w' has the same truth value as x =
y. Some languages, such as COBOL and SQL, deviate somewhat from this strict definition of equality. In
particular, those two languages both allow two character strings to “compare equal” if they differ only in
their numbers of trailing blanksfor example, the strings 'this' and 'this '. Such treatment is
disastrous in a relational database language because the DBMS relies on the strict sense of “=” for the
definition and implementation of so many of the operators described in this book.
Suppose, for example, that in the current value of IS_CALLED one of the two Borises had his name
recorded with a trailing blank, and Tutorial D’s definition of “=” were the same as SQL’s and COBOL’s.
What then would be the result of the projection IS_CALLED{Name}? It can’t include both of
TUPLE{Name NAME('Boris')} and TUPLE{Name NAME('Boris ')}, for those two tuples
would be deemed equal and thus cannot both appear in the same relation. And if only one of them can
appear, which one? In fact, does it have to be either of them? Couldn’t TUPLE{Name NAME('Boris
'}), with two trailing blanks, appear instead? Similar questions arise in connection with Example 4.3 in
Chapter 4, where Name is the common attribute for an invocation of JOIN.