Sometimes you cannot capture the necessary query restrictions using a single condition. For example, suppose we have a database that contains information not just on authors and books, but that also includes other published materials such as magazine articles and screenplays. If we want to not just restrict matches to items published before 1990, but to also ensure that we only match book objects, we have to place two conditions on the book vertex to correctly restrict the matching objects:
Both of the conditions
ObjType = book and
PubDate < 1990
must be satisfied
in order for the corresponding database object to match this vertex.
Because both conditions must be satisfied, we can more correctly write
this as the logical conjunction of two conditions, as shown in
Figure 3.17.
In this example, the two conditions are combined using the logical
AND
operator. For clarity, query diagrams use the
English words AND and OR
instead of the symbols
and
.
In principle,
complex conditions
in QGraph can be any logical combination of simple conditions.
For example, we could to modify the above query to find both books and
screenplays published before 1990 by creating the following query.
(However, see “Complex conditions in Proximity”
for important Proximity limitations
on the form of complex conditions.)
QGraph also permits the use of the logical
NOT
operator in complex conditions. The
NOT operator has the expected effect of requiring
that the condition’s test must fail for the
corresponding database entity to match the query.
For example, to find items not published in 1990, we can create
the query
This query matches objects whose PubDate
attribute does not include the value
1990.
Remember that QGraph must consider all of an attribute’s values for an object or link when evaluating a condition. Therefore, when database items have multiple attribute values, we cannot assume that Attribute <> value is equivalent to NOT(Attribute = value). For example, in the query above, if an object’s PubDate attribute has the the value {1984, 1990}, then the condition PubDate <> 1990 will be satisfied because 1984 <> 1990. But the condition NOT(PubDate = 1990) will not be satisfied because 1990 is included in the value for PubDate.
Similarly, the two conditions PubDate <> 1990 and NOT(PubDate = 1990) do not yield the same results when applied to objects or links having no values for the specified attribute. In the case of an inequality condition, if an item has no PubDate attribute, no value exists to satisfy the inequality, therefore the condition cannot be satisfied. In the case of a negated condition, no value exists to satisfy the PubDate = 1990 equality, therefore the condition is satisfied.