Parallel evaluation of recursive rule queries

We investigate the parallel computational complexity of recursive rule queries. These queries are a subset of first-order relational queries augmented with recursion. They form an important psrt of the PROLOG language aud can be eva! uated in PTIME. In [32] Sagiv has shown that it is decidable whether a typed recursive rule query is equivalent to a first-order relational query. We present an alternative proof of this fact We demonstrate a “gap” theorem for these queries. We provide two classes of queries, which can be evaluated in NC, using a logarithmic number of iterations of a first-order query. Finally, we give various, syntactically tight, queries which are logspace-complete in ETIME and cannot be evaluated in this fashion. 1. InJroduction Relational query languages [IO, 351 augmented with recursion (as an added primitive) have received considerable attention in the literature. e.g., [27,14.3. 6,7.37. 21.22,23.13. 18.30. la]. The principal object of study has been the expres.vM powt=~ of the-se languages. In the presence of an onfer reiation. such languages can express exactly the queries in various complexity classes [14,22,23,37.30]. Classical methods fmm logic can be used to obtain separation results when the language does not include order [14,6,21]. or under syntactic restrictions 1131. 1 Resclrch support~! ~y by an IRM Faculty Development Award, and purliy by Mcc. Alathl. TX. Permission to copy without fee all or part of this material is granted provided that the copies are not made or distributed for direct commercial advantage, the ACM copyright notice and the title of the publication and its date appear, and notice is given that copying is by permission of the Association for Computing Machinery. To copy otherwise, or to republish, requires a fee and/or specific permission, In this paper we study recursive rule queries detined by Horn &uses, e.g., [4,39,26,8,16J. Such queries lie at the heart of PROLOG (when used as 3 relational query language), The expressive power of Horn clauses has been examined in m. By contrast, we are concerned with the compuzutional power of the janguage, that is to say with the complexity of evaluating specific queries. Our measure of complexity is &a compfexity [6.371. ‘Ihat is, we make the reasonable assumption that the size of the query, as a program, is dominated by the size of the database. The queries we are examining do not contain negation or function symbols: note that negation is a central primitive whose expressive power is examined in [6,22]. Our approach is motivated by the current research on pamIle implementations of PROLOG (e.g. [33? ). We will consider that a query can be evaluated effrciendy in parallel if it can be evaluated by a NC algorithm [ll, 311. These are algorithms that can be implemented using a pcIynomiaI in n number of processors. and run in polylo@rithmic in n parallel time (where n is the size of the database). The class NC is of course contained in the class PTIME (polynomial-time algorithms). but it is not known whether this containment is strict. On the other hand. fogspucewnqdetencss of a problem in the class PTIME[~O, 11.17. 25] is usually considered satisfactory evidence that the problem is tnhmwtly sequential, i.c. it cannot he &cd efficiently in parallcl. The main thrust of our investigation is to draw a -line between recursive qucrics that can be evaluated by NC algorithms and recursive queries that are complete in PTIME This goal is similar to the one of IL? ], which examines pamIle un#kation of PROLOG terms (i.e., when function symbols are present). 01986 ACM-O-8979L179-2/86/03CGO280 $00.75 In Section 2 we give some basic definitions and background. The notion of a single rule program sirup, presented in this section, iS really a nOtatiOnal variant of the full untyped tagged diltabase tableau with fixpoint semantics[35]. Section 3 contains some tools from relational theory P, 28,lS. 2.34,32,5,19], which are very useful in analysing typed recursive rules. The queries we consider can always be evaluated by iterating an underlying first-order relational query a polynomial number of times. Each iteration can be executed by an NC algorithm, so if the number of iterations is actually polylogarlthmic then the overall computation can be performed in NC. The first interesting question is: given a recursive rule query decide whether the number of iterations is constant, i.e., independent of the database size, Queries which require only a constant number of iterations arc called bounded queries. “fhe recursion in such queries can be removed. Such queries have been investigated in [24]. where a decision procedure for boundedness i given for a class of linear sirups. The result of [24] are genernlizcd in 1291. For typed recursive rule queries boundcdness is also dccidnblc 1321. This particular cnse illustrates the power of the techniques dcvclopcd in database theory. as part of the study of the foundations of the univers,? l relation model I28.19. 35]. From [28] it follows that a typed rccunive rule query is houndsd if :Lld only if it is cquivalcnt to a lirst-order rcl;nion;ll query. The dccidnbility result of[32] is derived in the context of computing projections Of representative instances, a popular variant of the universal relation model, In Section 3 we present an alternative proof of this result, which uses mostly simple properties of fixpoints and might be helpful in generalizing the theorem beyond the typed case, Interestingly if a typed query is not bounded (or equivalently first-order) then its evaluation requires at least logn iterations (Theorem 1, Section 3). This is a “gap” theorem for computing with recursive rules. h S&on 4 we provide two classes of queries where a logarithmic number of iterations of a first-order relational query is sufficient for evaluation, (Theorems 2 and 3). As a matter of fact, in either of these cases query evaluation can be R&ced to a transitive closure computation Theorem 2 deals witi pje(xwise linear queries. These queries occur often in PlWdCe. They have a natural syntactic characterization in terns Of the strong components of a graph [l]. An efficient Parallel algorithm for linear queries, of which piecewise linear WXkS are a slight generalization, was discovered independently by M.Y. Vardi and D. Maier [38]. Theorem 2, was also derived independently in [36] as a consequence of a more general condition involving trecsize[36]. Theorem 3 provides an example of a non-linear class of typed sirups in NC. Finally. in Section 5, theorem 4, we present various queries, syntactically tight situps. which are logspace-complete in PWME. Other such situps appear in [36]: These queries cannot be evaluated using Q(log%$ itcmtions of a first-order query. for any constant c>k this is nn easy consequence ofjll, 231. Conclusions and open questions are in Section 6.