Homomorphic Tree Embeddings and Their Applications to Recursive ...

21 downloads 0 Views 227KB Size Report
and Jiawei Han z y. Dept. of Computer Science, Concordia University, Montreal, Quebec z. Dept. of Computer Science, Simon Fraser University, Burnaby, BC.
Appears in: LICS '93.

Homomorphic Tree Embeddings and Their Applications to Recursive Program Optimization 

Laks V.S. Lakshmanany , y

Karima Ashrafy , and Jiawei Hanz

Dept. of Computer Science, Concordia University, Montreal, Quebec Dept. of Computer Science, Simon Fraser University, Burnaby, BC

z

Abstrct: We study the problems of stage preserving linearization and 1-boundedness for a class of nonlinear single rule recursive programs and develop syntactic characterizations for both. Our characterizations lead to a polynomial time algorithm for the former and a linear time algorithm for the latter. Stage preserving linearization results in a signi cant improvement in evaluation eciency, compared to a linearization which does not preserve stages. The class of non-linear sirups which are stage preserving linearizable includes several classes of programs which can be linearized only using a mix of left and right linear rules, as well as programs which cannot be linearized using previously known techniques. Our study makes use of a novel technique based on the notion of homomorphic tree embeddings.

1 Introduction The Problems: Two powerful forms of recursive

query optimization in deductive databases are transforming a non-linear program into an equivalent linear program and transforming a recursive program into an equivalent non-recursive program. Indeed, linear recursion is much easier and faster to evaluate than non-linear recursion, and non-recursive queries can be evaluated more eciently than recursive queries in general. This paper is concerned with the problems of stage preserving linearization and 1-boundedness for

The research of the rst two authors was supported in part by grants from the NSERC (Canada), FCAR (Quebec), and the Concordia University Faculty Research development Program, and that of the second author was supported in part by grants from the NSERC (Canada) and the Centre for Systems Science of Simon Fraser University. 

the class of non-linear single recursive rule programs (sirups). We shall motivate these problems via examples. First, for stage preserving linearization, consider the following program , computing common prerequisites (not necessarily immediate) for courses C; D. P

Example 1.1.

r0: common req(P; C; D) :- common(P; C; D). r1: common req(P; C; D) :- common req(P; E; F), prereq(E; C), common req(P; G; H), prereq(H; D). The (exit) predicate common(P; C; D) says that P is an immediate prerequisite to both C and D. This program is a non-linear (bilinear) sirup. It can be shown that this program is equivalent to the following linear program (using abbreviations for predicates.) r0: c r(P; C; D) :- c(P; C; D). r1right : c r(P; C; D) :- c(P; E; F), p(E; C), c r(P; G; H), p(H; D). r1left : c r(P; C; D) :- c r(P; E; F), p(E; C), c(P; G; H), p(H; D). r1squash: c r(P; C; D) :- c r(P; E; H), p(E; C), p(H; D). 2 The last rule can be viewed as obtained from r1 by \squashing" the two occurrences of the recursive predicate c r in the body into one so that it retains all the essential information in the two original subgoals. As a second example, consider the following non-linear sirup . Q

R

Example 1.2.

r0: p(X1 ; X2 ) :- e(X1 ; X2 ). r1: p(X1 ; X2 ) :- a(X1 ); p(U; V ); p(X2; U). It can be shown using the results of this paper that this program is equivalent to the following linear program . r0: p(X1 ; X2 ) :- e(X1 ; X2 ). S

r1left : p(X1 ; X2) :- a(X1 ); p(U; V ); e(X2 ; U). r1right : p(X1 ; X2) :- a(X1 ); e(U; V ); p(X2; U). 2 Some signi cant features of the linear programs (such as above) obtained using the linearization technique proposed in this paper are as follows. (1) Such equivalent linear programs cannot be obtained using previously proposed techniques. (2) While ZYT-type of linearization [21] considers replacing a non-linear sirup with either a left-linear rule or a right-linear rule, our technique is (also) applicable to programs which can only be linearized using a mix of left and right linear rules (and in some cases, as with above, using one more rule). (3) For every non-linear sirup  for which an equivalent linear program  is obtained using the technique proposed in this paper, it can be shown that for an arbitrary input database (edb) , the stage1 of each derived tuple w.r.t. a bottom-up evaluation of program  on is identical to its stage w.r.t.  evaluated on . We refer to this aspect by saying that the stage is preserved by this linearization technique. The last point implies that the number of iterations needed to reach a xpoint using  is equal to the number of iterations needed using . It is possible to show that each iteration based on  involves less work than a similar iteration based on  [9]. Thus, stage preserving linearization achieves signi cant savings in the cost of query evaluation. In contrast, a technique such as ZYT-linearization does not preserve the stage in general. E.g., when transitive closure based on bilinear recursion is ZYT-linearized it can lead to an exponential increase in the stage of certain tuples. While for transitive closure itself this problem is easily solved using the logarithmic speedup techniques proposed in the literature (e.g., see [18, 5]), these techniques may not be applicable when the recursion is not one-sided2 , without increasing the arity of the recursive predicate. Thus, stage preserving linearization achieves a substantial improvement in query processing eciency without the aid of additional strategies during evaluation, compared to a linearization technique which does not preserve the stage. For general (linear) recursive programs, this is very important. Finally, several techniques developed for mixed linear recursions [13, 8] can be taken advantage of when evaluating speci c queries

against the transformed linear program. For 1-boundedness, consider the following program rec .

The stage of a tuple in a bottom-up xpoint evaluation is the minimum number of iterations needed to produce that tuple. In this paper, we will consider (naive or) semi-naive evaluation as our basic model of evaluation for de ning the stage. 2 E.g., The well-known same-generation program is a simple example of a two-sided recursion.

De nition 1.2. Consider a bilinear sirup  of the

P

D

D

D

1

P

Example 1.3.

r0: p(X1 ; X2 ; X3) :- e(X1 ; X2; X3 ). r1 : p(X1 ; X2 ; X3) :- p(K; X2; U), p(U; X2 ; X3), a(X1 ; X2). It can be shown using the technique developed in this paper that this program is 1-bounded. This means it is equivalent to the following non-recursive program nonrec. r0: p(X1 ; X2 ; X3) :- e(X1 ; X2; X3 ). r1left?right : p(X1 ; X2; X3 ) :- e(K; X2 ; U), e(U; X2 ; X3), a(X1 ; X2 ). 2 Since optimization of non-recursive queries is a classical problem for which powerful techniques have been developed in relational database theory, detection of (1-)bounded query programs opens up the possibility of using such techniques for any query against such programs. Finally, let us de ne the important notions formally. For a datalog program  and a database (edb) , let ( ) denote the set of facts obtained by one application of the rules in  to the facts in . We de ne 0 ( ) = . m+1 ( ) = m ( ) (m (S )). Finally, the least xpoint is given by 1 ( ) = i De nition 3.1. Let T be a proof-tree generated by a program  and let S be any tree whose nodes are labeled by predicates (with variable arguments) occurring in the program . Then a homomorphic embedding of the tree T into the tree S is any partial function h from the nodes of T to the nodes of S, satisfying the following conditions. (i) for every node u of T, either h is de ned on u, or h maps an ancestor of u to a leaf of S. (ii) h preserves levels in the sense that whenever h(u) = v, the level of u in T equals the level of v in S. (iii) For every pair of nodes u; v in T such that h(u); h(v) are both de ned, if u is a child of v in T, then h(u) is a child of h(v) in S. (iv) Consider the symbol mapping m induced by h from the variables in T to those in S, as follows: whenever h(u) = v and the labels of u and v are p(A1 ; : : :; An) and q(B1 ; : : :; Bm ) then m : p q, Ai Bi , i4 . Then m is a homomorphism in the sense that it maps each predicate symbol to itself, each dv to itself, and it is a function, i.e. it does not map any variable to two di erent variables. Note that it follows from Conditions (i) and (ii) that h maps the root of T to the root of S. The signi cance of homomorphic tree embeddings will be clear from the following result. 7!

7!

8

Theorem 3.1. Suppose that  is any program and

that Tn : n < ! is the in nite family of proof-trees generated by . Consider any in nite family of trees Sn : n < ! , such that (i) the set of predicates labeling the nodes of any Sn is a subset of the predicates involved in the program  and (ii) the set of leaves of Sn is a subset of the leaves of Tn, n. Suppose now that there is a family of homomorphic embeddings hn : Tn Sn . Then the program  is equivalent S to the in nite union of conjunctive queries n
f

g

g

8

!

Intuitively, a proof-tree can be viewed as a conjunctive query as well as a scheme for computing (the set of tuples corresponding to its root). When we provide a homomorphic embedding of a proof-tree T into another tree S (which has a subset of T's leaves for its own leaves), we essentially establish that the facts 4

Clearly this mapping is well de ned only if n = m.

corresponding to the root of T can be computed alternatively as suggested by the proof-tree S. Further, since the embedding is homomorphic, we ensure that the computation suggested by S in not arbitrary, but rather it also obeys the laws of the program . In the remainder of this section, we focus on nonlinear sirups of the kind discussed in Section 1. For our purpose, \recursively constructed" homomorphic embeddings will be useful. To understand this concept, it will be useful to view each embedding h : T S as a transformation rule that transforms a tree of the form T into a tree of the form S. Indeed, such tree transformation rules can be repeatedly applied to given proof-trees. We say that an embedding (or rule) h : T S is derived from a set of rules h1 : T1 S1 ; : : :; hm : Tm Sm provided there is a nite sequence of rule applications hi1 : T Ti1 ; hi2 : Ti1 Ti2 ; hi : Ti ?1 S, such that hi h1; : : :; hm . A family of embeddings hn : n < ! is recursively constructed if there is a nite set of embeddings h1 : T1 S1 ; : : :; hm : Tm Sm such that every embedding in the family is derived from this set of rules. More specially, such a family is single rule generated if there is a rule h0 : T0 S0 such that every embedding/rule in the above family is derived (by recursive applications) from this one rule. We will exclusively deal with single rule generated families of embeddings in the sequel. Examples of single rule generated embeddings are given in Fig. 2 and 3(b) corresponding to programs in Examples 1.1 and 1.2. The corresponding families can be generated by applying the appropriate (single) rule recursively (to saturation) to each proof-tree in the family Tn : n < ! . Our next result characterizes the set of embeddings that will lead to sp-linearization of a non-linear sirup . The idea is to consider the smallest nonlinear proof-tree, viz., T2 , and then study the question of what transformation will linearize the tree while preserving the stage. Let us rst explain our convention. We shall consider the problem of (homomorphically) embedding T2 into one of the linear trees T1; Tleft ; Tright ; Tsquash. The motivation for this comes from the fact that each embedding T2 T (where T is one of the linear trees above) suggests a transformation of a proof-tree of the form T2 into a proof-tree of the form T. In order to linearize an arbitrary non-linear tree Tnon, a transformation rule 0 must satisfy two conditions, as shown in [14]: 0 ; (ii) it should be possible to transform (i) an arbitrary tree Tnon into a linear tree by nitely 0 . Theorem 3.2 many applications of the rule !

!

f

!

!

g

!



!

f

n

n

!

j

g

f

f

!

!

g

g

!

f

g

!

T !T T

 T

T !T

2

guarantees that the (transformations associated with the) embeddings T2 T1 , T2 Tright , T2 Tleft , and T2 Tsquash completely capture what it takes for a bilinear sirup to be sp-linearizable. Fig. 1 shows these tree transformations in schematic form. Theorem 3.2. Let  be a bilinear sirup. Then  is sp-linearizable i the proof-tree T2 can be homomorphically embedded into one of the proof-trees T1 ; Tleft ; Tright ; and Tsquash , for suitable choices of pi ; pj ; pk, shown in Fig. 1. 2 We next consider the embeddings associated with 1-boundedness. There are exactly two transformation rules associated with 1-boundedness, as suggested by the embeddings hleft : Tleft T1 , and hright : Tright T1 . We have the following result. Theorem 3.3. Let  be a bilinear sirup. Then  is 1-bounded i Tleft and Tright can both be homomorphically embedded into trees of the form T1 for suitable choices of the leaves of T1. 2 A direct application of Theorems 3.2 and 3.3 will not yield polynomial time tests because of the exponentially many possible ways of mapping the edb nodes in one tree to those in the other. Thus eciently testable characterization are needed. Such characterizations are developed in the next two sections, with Theorems 3.2 and 3.3 as the basis. In addition, we stress that embedding T2 into a tree of the form T where T is one of the linear trees above, entails considering all possible choices for the leaves of T corresponding to the idb predicate p. This diculty is also overcome in the next section. !

!

!

!

!

!

4 Stage Preserving Linearizability The objective of this section is to develop an ef ciently testable characterization of sp-linearizability, based on Theorem 3.2. This process is challenged by the fact that the number of actual embedding rules that Theorem 3.2 covers is 136! In principle, we could consider each of these cases, analyze it, and come up with necessary and sucient (syntactic or otherwise) conditions for the particular embedding rule to go through. However, this approach would be inelegant and error-prone (because of the combinatorial explosion). Our main theorem of this section shows that it is necessary and sucient to consider exactly 17 of the 136 possible embeddings, in order to detect splinearizability.

Theorem 4.1 (Characterization of sp-linearizability). Let  be a bilinear sirup of the form shown in Section 1. Then  is sp-linearizable i the proof-tree T2 can be homomorphically embedded into one of the trees T1 , Tleft , Tright , Tsquash with one of the following mapping patterns. I. Right-Embeddings:

1. Right1 : p` 2. Right2 : p` 3. Right3 : p` 4. Right4 : p`

p`` ; pr pr . p`r ; pr pr . pr` ; pr` prr ; prr prr . p`r ; pr` p`` ; prr p`r . II. Left-Embeddings: 5-8: Left1 {Left4 : Symmetric to Right1 {Right4 . 7!

7!

7!

7!

7!

7!

7!

7!

7!

7!

III. One-Embeddings:

9. One1 : p` p`` ; pr p`r . 10. One2 : p` p`r ; pr p`` . 11,12: One3 ; One4: Symmetric to One1; One2 . 13. One5 : p` prr ; pr p`` . 7!

7!

7!

7!

7!

7!

IV. Squash-Embeddings:

14. Squash1 : p`` ; pr` p`` ; p`r ; prr p`r . 15. Squash2 : p`` ; pr` p`` ; p`r ; prr prr . 16. Squash3 : p`` ; pr` pr` ; p`r ; prr p`r . 17. Squash4 : p`` ; pr` pr` ; p`r ; prr prr . 2 Some discussion is in order. The theorem considers 4 groups of embeddings. Each group of embedding has a name, depending on the form of the tree into which it embeds T2 . For instance, right-embeddings are concerned with embedding T2 into a tree of the form Tright , while squash-embeddings try to embed T2 into a tree of the form Tsquash . To appreciate the signi cance of the theorem, notice that it greatly reduces the number of possible embeddings to consider. Further, as mentioned in Section 1, the de nition of sp-linearizability does not impose any restricions on the number of rules of the equivalent linear program or their form. Theorem 4.1 shows that in spite of this general form of linearization, it is exactly captured by the set of embeddings and their associated transformation rules, given above. To further reveal the signi cance of the theorem, let us consider four types of linear programs (involving the only idb predicate p) which can be derived from the original program : (i) right = r0: p:- e; r1right : p :- e` ; pr ; a1; : : :; ak ; (ii) left = r0: p :- e; r1left : p :- p` ; er ; a1; : : :; ak ; (iii) mixed = r0: p :- e; r1right : p :- e` ; pr ; a1; : : :; ak; r1left : p :- p` ; er ; a1; : : :; ak ; (iv) squash = r0: p :- e; r1right : p :- e` ; pr ; a1; : : :; ak; r1left : p :p` ; er ; a1; : : :; ak; rsquash: p :- p ; a1; : : :; ak , where p is any atom involving p such that there is a function f from the variables of r1 to those of r1squash which is identity on dv's and such that f(p` ) = f(pr ) = p 7!

7!

7!

7!

7!

7!

7!

7!

f

g

f

g

f

g

f



g





and f(ai) = ai, i. From the proof of Theorem 4.1, it can be shown that  is sp-linearizable exactly when it is equivalent to one of the four linear programs above. This leads to the following Theorem 4.2. Let  be a bilinear sirup as above. Then the following results hold. (1)  is equivalent to right i it admits one of the embeddings Right1 , Right2 , One1 , One2 . (2)  is equivalent to left i it admits one of the embeddings Left1 ; Left2 , One3 ; One4. (3)  is equivalent to mixed but not to right and left exactly when it admits one of the embeddings Right3 , Right4 , Left3 , Left4 and none of the embeddings in (1) and (2) above. (4)  is equivalent to squash i it admits one of the embeddings Squashi , i = 1; : : :; 4. 2 Our proof of the theorem shows that the equivalence between  and the programs  above is actually stage-equivalence. The point is, unlike the previously proposed notions of linearization, the de nition of splinearization by itself does not suggest the form of the equivalent linear program. The above theorem shows that there are exactly 4 types of linear programs to one of which the original program needs to be stageequivalent in order to be sp-linearizable. We remark that Theorems 4.1 and 4.2 still do not directly suggest a polynomial time algorithm for testing sp-linearizability. The reason is that testing whether the sirup will admit any given type of embedding will involve considering an exponential number of mapping possibilities for the edb subgoals in the tree. In the full paper [9], we develop a complete syntactic characterization for any of the embeddings to hold for a sirup, and hence for the sirup to be sp-linearizable. For want of space, we illustrate our characterization only for the case of squash-embeddings. We rst need some notions. We say that a subgoal s of a sirup  projects a variable Z occurring at p` : i or pr : i provided s contains an occurrence of the dv Xi . We say that a subgoal s in the recursive rule of a sirup  is upward incompatible (UI) provided one of the following conditions holds: (i) s is an idb subgoal; (ii) s is an edb subgoal and it satis es one of the following conditions: (a) s shares an ndv with p` or pr ; (b) s projects a dv Xj occurring at p` : i or pr : i, j = i; (c) s projects an ndv shared between p` (or pr ) and an edb subgoal; (d) s projects an ndv occurring at p` : i, pr : i = Xi , and Xi also occurs in p` or pr ; (e) (d), with p` and pr interchanged; (f) s projects an ndv occurring at p : i and p : j, i = j, and either p  : i = Xi , or p  : j = Xi . The 8

6

6

6

6

6

intuition behind the notion of upward incompatibility is that we can prove that if  is sp-linearizable via a squash-embedding, then there is an embedding which for all upward compatible subgoals s, maps both sl and sr to s. We next de ne a precedence relation between variables occurring in corresponding arguments of p` and pr . Let Z and W be any variables occurring in p : i and p  : i, respectively, such that Z = W. We say that Z is of a higher priority than W, denoted Z > W, if one of the following conditions is satis ed: (i) Z is a dv. (ii) Z is an ndv shared with an edb subgoal. (iii) Z is an ndv occurring in at least two di erent idb arguments, say p : i and p : j, and p  : i = p  : j. This notion is used in the next de nition. De nition 4.1. Let  be a bilinear sirup and T2 be the complete proof-tree of height 2 generated by . Suppose N denotes the set of UI subgoals of T2 at level 2. Then the choice graph of  is a digraph G() whose nodes are N; the arcs of G() are de ned as follows. there is an arc from node s to node t provided one of the following conditions holds: (i) s and t share an ndv, and = ; (ii) s : k = Xi , t : m = Xj , p : i = p : j, but 2 p  : j = p : i. We say that a node s of G() is forced whenever s projects the variables Z and W occurring at p : i and p  : i, and Z > W. In this case, we also say that the connected component of G() containing s is forced. We now present the syntactic characterization of splinearization via squash-embeddings. Theorem 4.3. Let  be a bilinear sirup and let G() be its choice graph. Then  admits a squashembedding i the following conditions hold: (i) no pair of subgoals s` ; sr are both forced. (ii) no pair of subgoals s` ; sr are connected in G(). 2 Theorem 4.3 reduces the semantic condition of admitting one of the squash-embeddings to purely syntactic conditions. In [9] we develop the syntactic characterization for the existence of all types of embeddings and also develop a polynomial time algorithm which tests whether the given sirup is sp-linearizable and constructs an embedding if one exists. We also establish its correctness and complexity. As an example, the program of Example 1.15 satis es the conditions corresponding to the mapping 6

6

6

P

5 Technically, this falls outside the class of sirups considered since it has repeating subgoals. Our characteri-

patterns p`` p`` , p`r prr , pr` p`` , and prr prr . p` and pr themselves map to the node p , which is the parent of p`` and prr in Tsquash . As another example, program of Example 1.2 satis es the conditions corresponding to p` p`r , pr` p``, and prr p`r . We close this section with Theorem 4.4. Testing whether a given bilinear sirup is sp-linearizable can be done in polynomial time. Further, the appropriate equivalent linear program can be constructed in the same time. 2 7!

7!

7!

7!



R

7!

7!

7!

5 1-Boundedness In this section, our main objective is to characterize the structural rules corresponding to 1-boundedness identi ed in Section 3, in terms of syntactic conditions involving the original program alone. Indeed, a direct attempt at testing whether the mappings associated with each of the embedding rules Tleft T1 , Tright T1 would take time exponential in the size of the sirup. Thus an eciently testable characterization is necessary for 1-boundedness. We shall actually develop a simple and elegant characterization of 1-boundedness. As we shall show, our characterization leads to a linear time algorithm for the recognition of such programs. Kanellakis [6] has shown that when the subgoals are allowed to repeat in the recursive rule, detection of (uniform) 1-boundedness is NP-hard even for linear programs. Thus our characterization in some sense identi es the largest known class of (non-linear) programs whose 1-boundedness can be detected in polynomial time (in fact, in linear time). Our main results of this section follow. Theorem 5.1. Let  be a bilinear sirup. Then the proof-tree Tleft can be homomorphically embedded into a tree of the form T1 i one of the following conditions holds. !

!

1. p` is dv-saving and p` preserves every subgoal which is related to p`. 2. whenever p` has a dndv U occurring in arguments p` : i1; : : :; p` : ik , either pr saves all these arguments or pr has some dndv V at the positions pr : i1 ; : : :; pr : ik . In addition, whenever p` : i carries either a dv or an sndv, pr saves that argument. zation still provides a sucient condition for it to be splinearizable.

3. p` and pr satisfy the following conditions: (a) p` saves every dv occurring in pr and vice versa, and (b) p` preserves every edb subgoal related to p`, and (c) p` and pr have matching ndv-patterns.

2 Theorem 5.2. It can be determined in time linear in the size of a non-linear sirup whether the sirup is 1-bounded. 2 In [9] we give a linear time algorithm and prove its correctness and complexity. As an example, consider the program in Example 1.3. This program is 1-bounded since it satis es the condition 2 above. Indeed it is equivalent to the nonrecursive program obtained by replacing both occurrences of the recursive predicate p in the recursive rule by the exit predicate e. In general testing 1-boundedness is NP-hard even for linear sirups. To our knowledge ours is the rst positive (i.e. polynomial time complexity) result on (1-)boundedness of non-linear sirups. Our result is in some sense optimal because when the edb subgoals repeat the complexity becomes NP-hard even for linear sirups.

6 Summary and Future Research Using a new technique based on homomorphic tree embeddings, we studied the problems of stage preserving linearizability and 1-boundedness for a class of bilinear recursions. Our study has led to a complete syntactic characterization as well as ecient decision procedures for these problems (polynomial for the former and linear for the latter). The signi cance of sp-linearization was brought out. In comparing with previous approaches to linearization (e.g., [15, 14]) we note that they only consider the problem of testing equivalence to a speci c linear sirup while in our approach, the linear program can consist of a number of recursive rules and the exact program to which equivalence is being tested in not known a priori. A second distinction is that the transformations studied in this paper were motivated by homomorphic tree embeddings, while their transformations are induced by containment mappings. We remark that while 1boundedness could have been studied completely using containment mappings, homomorphic embeddings

were needed in analyzing sp-linearizability and characterizing it, in particular w.r.t. the squash-embeddings. Homomorphic embeddings provide a uniform framework in which many of the optimization problems can be studied. Several interesting problems remain open. (1) Can we characterize bilinear recursions which can be linearized using mixed linear rules (without necessarily preserving stages)? (2) What can we say about 2-boundedness (more generally k-boundedness) of bilinear sirups? (3) Can we account for the e ect of semantic knowledge in the form of integrity constraints (e.g. functional dependencies) in recognizing sp-linearizability and 1-boundedness? It is our hope that the framework of homomorphic embeddings will o er a useful tool with which such optimization problems can be attacked. Our future work will address some of these problems.

References [1] Chaudhuri, S. and Vardi, M.Y. On the equivalence of recursive and nonrecursive datalog programs. In Proc. 11th ACM SIGACT-SIGMODSIGART Symp. on Principles of Database Systems, 1992.

[2] Gaifman, H., Mairson, H., Sagiv, Y., and Vardi, M.Y. Undecidable optimization problems for database logic programs. Technical report, IBM Research Report RJ 5583 (56702), Yorktown Heights, New York,, April 3 1987. [3] Hillebrand, G.G., Mairson, H.G., and Vardi, M.Y. Tools for datalog boundedness. In Proc. ACM Symp. PODS, pages 1{12, 1991. [4] Ioannidis, Y.E. A time bound on the materialization of some recursively de ned views. In Proc. 11th Int. Conf. of Very Large Data Bases, pages 219{226, 1985. [5] Ioannidis, Y.E. and Ramakrishnan, R. Ecient transitive closure algorithms. In Proc. 14th VLDB Conference, pages 382{394, 1987. [6] Kanellakis, P. Logic programming and parallel complexity. In Foundations of Deductive Databases and Logic Programming, pages 547{ 586. 1988. J. Minker ed., Morgan Kaufmann. [7] Kanellakis, P. and Abiteboul, S. Database theory column: Deciding bounded recursion in database logic programs. SIGACT News, 20(4):17{23, 1989.

[8] Kemp, D.B., Ramamohanarao, K., and Somogyi, Z. Right-, left- and multi-linear rule transformations that maintain context information. In Proc. 16th VLDB Conf., pages 235{242, 1989. [9] Lakshmanan, Laks V.S., Ashraf, K., and Han, J. Homomorphic trees embeddings and their applications to recursive program optimization. Technical report, Concordia University, Montreal, Canada, April 1993. Submitted to a technical journal (A preliminary version appears in IEEE Symp. on Logic in Computer Science, Montreal, Quebec.). [10] Lakshmanan, Laks V.S. and Hernandez, H. Structural query optimization: A uniform framework for semantic query optimization in deductive databases. In Proc. ACM Symp. PODS, pages 102{114, Denver, CO, 1991. [11] Naughton, J.F. Data independent recursion in deductive databases. In Proc. 5th ACM Symp. PODS, pages 267{279, 1986. [12] Naughton, J.F. Redundancy in function free recursive inference rules. In Proc. of the IEEE Symposium on Logic Programming, 1986. [13] Naughton, J.F., Ramakrishnan, R., Sagiv, Y., and Ullman, J.D. Ecient evaluation of right-, left-, and multi-linear rules. In Proc. ACM SIGMOD '89 International Conference on Management of Data, pages 380{391, 1990.

[14] Ramakrishnan, R., Sagiv, Y., Ullman, J.D., and Vardi, M. Proof-tree transformation theorems and their applications. In Proc. 8th ACM Symp. PODS, pages 172{181, 1989. [15] Saraiya, Y. Linearizing nonlinear recursions in polynomial-time. In Proc. 8th ACM

SIGACT-SIGMOD-SIGACT Symp. of Principles of Database Systems, pages 182{189, 1989.

[16] Saraiya, Y. Polynomial-time program transformations in deductive databases. In Proc.

9th ACM SIGACT-SIGMOD-SIGACT Symp. on Principles of Database Systems, pages 132{144,

1990. [17] Ullman, J.D.

Principles of Database and Knowledge-Base Systems, volume II. Computer

Science Press, Maryland, 1989. [18] Valduriez, P. and Boral, H. Evaluation of recursive queries using join indices. In Proc. 1st Expert Database Systems, pages 271{293, 1986.

[19] Vardi, M.Y. Decidability and undecidability results for boundedness of linear recursive queries. In Proc. 7th ACM SIGACT-SIGMOD-SIGART Symp. on Principles of Database Systems, pages 341{351, 1988. [20] Wood, P.T. Syntactic characterizations of 1bounded datalog programs. In International

p

pl

pr

p lr p rl

p ll

Conference on Deductive and Object-Oriented Databases, 1991.

p rr

(A) T2

[21] Zhang, W., Yu, C.T., and Troy, D. Necessary and sucient conditions to linearize doubly recursive programs in logic databases. ACM Transactionsp on Database Systems, pages 271{293, 1990.

p

pi

p

pj

p r*

i

p l*

pj

pk

k

p

(C) T right where

p*

p

pi

p

i

(B) T 1

p

p

j

(D) T left

p i,p j,p k

pj

(E) T squash

{ p ll , p lr , p rr , p rl }

Fig. 1 The five fundamental proof-trees and the embeddings associated with Sp-linearizability.

C_r(P,C,D)

C_r(P,E,F) p(E,C)

C_r(P,C,D)

p(H,D) C_r(P,G,H)

C_r(P,E,H) p(E,C)

C_r(P,E1,F1) p(E1,E) p(H1,F) C_r(P,G1,H1) C_r(P,E2,F2) p(E2,G) p(H,G2) C_r(P, G2,H2) C_r(P,E1,F1) pE1,E)

p(H,D)

p(H2,H) C_r(P,G2,H2)

Fig 2 Embedding Squash2 for Example 1.1 p

p

pl

p ll

pr

p lr prl

plr p rr

pr p ll

plr

Fig 3 (a) An Embedding corresponding to Mixed Linearization. (See example 1.2) p(X1, X2)

p(U,V)

p(U1,V1)

a(U)

a(X1)

p(V,U1)

p(U2, V2)

p(X1, X2)

p(V, U1)

p(X2,U)

a(X2)

p(U,U2)

a(X1)

p(U1, V1)

p(X2, V)

a(X2)

Fig 3 (b) Embedding Right4 for Example 1.2

Figure 1: The ve fundamental proof-trees.

p(V,U1)