CS345 PROBLEM SET #4
SOLUTIONS
4 Questions, 100 pts.

Problem 1 (20 pts.)

Consider the conjunctive queries with negation P and Q.
P:
p(X) :- q(X,Y) & q(Y,X) & r(Y,Y) & NOT q(X,X) & NOT r(Y,X).
Q:
p(B) :- q(A,B) & r(A,A) & NOT r(A,B).
Use the Levy-Sagiv test to show that P is contained in Q and Q is not contained in P.

Solution

First, we show that P is contained in Q. Then we show that Q is not contained in P.

Problem 2 (25 pts.)

Consider the conjunctive queries (with arithmetic subgoals) P and Q.
P:
panic :- q(X,Y,Z) & q(X,Z,Y) & q(Y,Z,X).
Q:
panic :- q(X,Y,Z) & X<=Z & Y<=Z.
Use the Klug-Levy-Sagiv test to show that P is contained in Q.

Solution

Consider the canonical database D, constructed from P for any partition of the variables in P and any order for that partition. Let the constants assigned to X, Y, and Z be a, b, and c respectively. Thus, D = {q(a,b,c), q(a,c,b), q(b,c,a)}. Note that a, b, and c are not necessarily different. We will consider all 3 possible cases. Therefore P is contained in Q.

Problem 3 (30 pts.)

This problem involves a "mystery" predicate m. There are two things known about m. ("panic" is a generic 0-ary predicate or, equivalently, a propositional variable, that we may use as the head of a CQ that represents a constraint.) Prove that the conjunctive query

panic :- q(X,Y,Z) & m(Y,X) & m(Y,Z)

contains the conjunctive query

panic :- q(X,Y,X) & q(Y,Z,Y) & q(X,Z,X).

Solution

Therefore, by the Gupta test, panic :- q(X,Y,Z) & m(Y,X) & m(Y,Z) contains
panic :- q(X,Y,X) & q(Y,Z,Y) & q(X,Z,X).

Problem 4 (25 pts.)

Determine whether each of the conjunctive queries
P:
p(X,Y) :- arc(X,A) & arc(A,Y) & arc(X,B) & arc(B,Y) & X<A & B<Y.
Q:
p(X,Y) :- arc(X,Z) & arc(Z,Y) & X<Z & Z<Y.
is contained in the other. If not, give a counterexample database.

Hint: The Gupta test is messy here, since there are a lot of containment mappings after we replace duplicate occurrences of variables. However, in general, and here in particular, when there is implication of the OR over all containment mappings, we can usually identify one or a few of the containment mappings that are really involved in the implication. Try first to understand what the CQ's are saying, and the focus on the containment mappings you really need.

Solution

First we show that P is not contained in Q. Then we show that Q is contained in P.