CS345 PROBLEM SET #3
Due in class, Wednesday, October 23, 1996.
5 Questions, 100 pts.

Problem 1 (15 pts.)

Consider the conjunctive queries A and B.
A:
p(X,Y) :- q(X,Z) & q(Z,T) & r(T,Y).
B:
p(X,Z) :- q(X,X) & r(X,Z).
Is A contained in B? Is B contained in A? Justify your answers by offering containment mappings or showing that none exists.

Problem 2 (20 pts.)

Consider the infinite sequence of conjunctive queries Q1, Q2, ..., where Qi is:
q(X) :- arc(X,Z1) & arc(Z1,Z2) & ... & arc(Z{i-1},Zi) & arc(Zi,X).
Note that Qi represents (not necessarily simple) cycles of length i+1 in a directed graph. Find all containments among the Q's.

Problem 3 (15 pts.)

Consider the conjunctive queries A and B.
A:
p(X) :- q(X,Y,X) & q(X,Z,Y) & r(Y,X).
B:
p(X) :- q(X,Y,Z) & r(Y,Z).
Show that A is contained in B by using the method of canonical databases.

Problem 4 (30 pts.)

Consider the conjunctive queries A and B.
A:
p(X) :- q(X,Y) & r(Y,Z) & s(Z,W) & s(X,Z).
B:
p(X) :- q(X,Y) & q(X,Z) & r(Y,Z) & r(Z,Y) & s(Y,Z) & s(X,Y).
Test whether B is contained in A by using Saraiya's containment test. However, you must start by mapping q(X,Y) to q(X,Y) (this requirement is to make sure that you go through the major steps of the algorithm). Indicate at each step what inferences are made.

Problem 5 (20 pts.)

Find all equivalences and containments among the four conjunctive queries below. Note that c is a constant in Q4.
Q1:
p(X,Y) :- q(X,A) & q(A,B) & q(B,Y).
Q2:
p(X,Y) :- q(X,A) & q(A,B) & q(B,C) & q(C,Y).
Q3:
p(X,Y) :- q(X,A) & q(B,C) & q(D,Y) & q(X,B) & q(A,C) & q(C,Y).
Q4:
p(X,Y) :- q(X,A) & q(A,c) & q(c,B) & q(B,Y).