Adjacency Requirements

We saw before that an edge adjacent to an annotated vertex must itself be annotated. To illustrate the reason for this rule, let’s examine what happens without such a requirement. Figure 4.39 shows a part of the database shown in Figure 4.17. This fragment includes multiple links from an actor to a single movie, representing Alec Guinness’s multiple roles in Kind Hearts and Coronets.

Database fragment [Annot_DB06.xml]

Figure 4.39. Database fragment [Annot_DB06.xml]


The (illegal) query shown in Figure 4.40 finds actor-movie pairs but omits the required edge annotation.

Illegal query omitting adjacent edge annotation

Figure 4.40. Illegal query omitting adjacent edge annotation


How are we to interpret this query? One interpretation would be to retain the ability of numeric annotations to collapse the subgraphs containing the same actor and different movies but let each role edge define a distinct match, much as we saw in Chapter 2, Query Basics. If we could execute such a query on the database fragment in Figure 4.39, we would see the results shown in Figure 4.41.

Hypothetical results for improperly annotated query

Figure 4.41. Hypothetical results for improperly annotated query


In this interpretation, the unannotated edge results in three different matching subgraphs instead of one subgraph that groups the three links. Each contains the same objects, but they differ in the link connecting the actor Alec Guinness with the movie Kind Hearts and Coronets. But annotating the edge as shown in Figure 4.42

Legal query including adjacent edge annotation [Annot_DB06_Q02.qg2.xml]

Figure 4.42. Legal query including adjacent edge annotation [Annot_DB06_Q02.qg2.xml]


collapses these three subgraphs into the single subgraph shown below:

Results for properly annotated query

Figure 4.43. Results for properly annotated query


This subgraph best corresponds to our intuitive understanding of the query as identifying actor-movie clusters, regardless of how many roles the actor played in each movie.

QGraph also requires that, at most, only one of two adjacent vertices may be annotated. Another way of stating this is that there can be no edge connecting two annotated vertices in a query. To see why this is the case, consider the database fragment and (illegal) query shown in Figure 4.44.

Database fragment and illegal query

Figure 4.44. Database fragment and illegal query


How are we to match the query against this database fragment? We have many instances where an actor is connected to two or more movies, and where a movie is connected to two or more actors, but matching these database elements to the query is far from straightforward.

Can we include the actor Mary Astor in the query results? She is connected to two movies, satisfying the annotation on the movie vertex, but those movies must also be part of a subgraph that satisfies the query’s other conditions and annotations, thus each movie she is connected to must be connected to two or more actors (one of which can be Mary Astor).

One of the movies linked to Mary Astor, Little Women, is only linked to a single actor, Mary Astor herself, and therefore does not satisfy the actor vertex annotation, so it does not match the query’s requirements. And if we cannot include Little Women, then Mary Astor cannot be included because she no longer links to two movies that satisfy the query.

A similar situation arises with respect to the movie The Maltese Falcon. At first glance, it appears to satisfy the query—it is linked to two actors, and each of those actors is linked to at least two movies. But as we’ve seen, at least one of those actors, Mary Astor, does not satisfy the query’s requirements, so it cannot be included, and therefore The Maltese Falcon also cannot be included in the query’s results.

This query is ambiguous because neither vertex annotation takes precedence over the other. In effect, we don’t know where to start when evaluating the query’s match to a specific part of the database, and the choice of a starting point effects how we determine whether an object in the database satisfies the requirements of the query. To avoid this ambiguity of interpretation, QGraph requires that at most one of two adjacent vertices be annotated.

QGraph also places additional restrictions in numeric annotations when used in queries that include constraints (Chapter 5, Constraints) or subqueries (Chapter 6, Subqueries). These rules are discussed in later chapters.