Advances in Database Technology P10
lượt xem 3
download
Advances in Database Technology P10
Tham khảo tài liệu 'advances in database technology p10', công nghệ thông tin, cơ sở dữ liệu phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Bình luận(0) Đăng nhập để gửi bình luận!
Nội dung Text: Advances in Database Technology P10
 432 A. Nash and B. Ludäscher This domain enumeration approach has been used in various forms [DL97]. Note that in our setting of ANSWER* we can create a very dynamic handling of answers: if ANSWER* determines that the user may want to decide at that point whether he or she is satisfied with the answer or whether the possibly costly domain enumeration views should be used. Similarly, the relative answer completeness provided by ANSWER* can be used to guide the user and/or the system when introducing domain enumeration views. 5 Feasibility of Unions of Conjunctive Queries with Negation We now establish the complexity of deciding feasibility for safe queries. 5.1 Query Containment We need to consider query containment for queries. In general, query P is said to be contained in query Q (in symbols, if for all instances D, We write for the following decision problem: For a class of queries given determine whether For P, a function is a containment mapping if P and Q have the same free (distinguished) variables, is the identity on the free variables of Q, and, for every literal in Q, there is a literal in P. Some early results in database theory are: Proposition 6 [CM77] CONT(CQ) and CONT(UCQ) are NPcomplete. Proposition 7 [SY80,LS93] and are complete. For many important special cases, testing containment can be done efficiently. In particular, the algorithm given in [WL03] for containment of safe and uses an algorithm for CONT(CQ) as a subroutine. Chekuri and Rajara man [CR97] show that containment of acyclic CQs can be solved in polynomial time (they also consider wider classes of CQs) and Saraiya [Sar91] shows that containment of CQs, in the case where no relation appears more than twice in the body, can be solved in linear time. By the nature of the algorithm in [WL03], these gains in efficiency will be passed on directly to the test for containment of CQs and UCQs (so the check will be in NP) and will also improve the test for containment of and 5.2 Feasibility Definition 8 (Feasibility Problem) is the following decision problem: given decide whether Q is feasible for the given access patterns. Please purchase PDF SplitMerge on www.verypdf.com to remove this watermark
 Processing Unions of Conjunctive Queries with Negation 433 Before proving our main results, Theorems 16 and 18, we need to estab lish a number of auxiliary results. Recall that we assume queries to be safe; in particular Theorems 12 and 13 hold only for safe queries. Proposition 8 is unsatisfiable iff there exists a relation R and terms so that both and appear in Q. PROOF Clearly if there are such R and then Q is unsatisfiable. If not, then consider the frozen query is a Herbrand model of Clearly so Q is satisfiable. Therefore, we can check whether is satisfiable in quadratic time: for every in look for in Proposition 9 If is Qanswerable, then it is Proposition 10 If is Qanswerable, and for every literal in is Panswerable, then is Panswerable. PROOF If is Qanswerable, it is by Proposition 9. By defini tion, there must be executable consisting of and literals from Since every literal in is Panswerable, there must be executable consist ing of and literals from P. Then the conjunction of all is executable and consists of and literals from P. That is, is Panswerable. Proposition 11 If is a containment mapping and is Qanswerable, then is Panswerable. PROOF If the hypotheses hold, there must be executable consisting of and literals from Q. Then consists of and literals from P. Since we can use the same adornments for as the ones we have for is executable and therefore, is Panswerable. Given P, where and and where and are quantifier free (i.e., consist only of joins), we write P, Q to denote the query Recently, [WL03] gave the following theorems. Theorem 12 [WL03, Theorem 2] If P, then iff P is un satisfiable or there is a containment mapping witnessing such that, for every negative literal in Q, is not in P and P, Theorem 13 [WL03, Theorem 5] If and with then iff P is unsatisfiable or if there is and a containment mapping witnessing such that, for every negative in is not in P and Please purchase PDF SplitMerge on www.verypdf.com to remove this watermark
 434 A. Nash and B. Ludäscher Therefore, if and with we have that iff there is a tree with root for some and where each node is of the form and represents a true containment except when is unsatisfiable, in which case also the node has no children. Otherwise, for some containment mapping witnessing the containment, there is one child for every negative literal in Each child is of the form where and appears in We will need the following two facts about this tree, in the special case where with E executable, in the proof of Theorem 16. Lemma 14 If is it is answerable. PROOF By induction. It is obvious for Assume that the lemma holds for and that is We have for some witnessed by a contain ment mapping and for some literal appearing in Since is executable, by Propositions 1 and 9, is Therefore by Proposition 11, is and by the induction hypothesis, Therefore, by Proposition 10 and the induction hypothesis, Lemma 15 If the conjunction is unsatisfiable, then the conjunction ans(Q), is also unsatisfiable. PROOF If Q is satisfiable, but Q, is unsatisfiable, then by Proposition 8 we must have some in Q. must have been added from some in and some containment map satisfying Since is executable, by Propositions 1 and 9, is answerable. Therefore by Proposition 11, is answerable and by Lemma 14, Therefore, we must have in ans(Q), so ans(Q), is also unsatisfiable. We include here the proof of Proposition 4 and then prove our main results, Theorems 16 and 18. PROOF (Proposition 4) For this is clear since ans(Q) contains only literals from Q and therefore the identity map is a containment mapping from ans(Q) to Q. If and Q is unsatisfiable, the result is obvious. Otherwise the identity is a containment mapping from to If a negative literal appears in ans(Q), then since also appears in Q, we have that is unsatisfiable, and therefore by Theorem 12. Please purchase PDF SplitMerge on www.verypdf.com to remove this watermark
 Processing Unions of Conjunctive Queries with Negation 435 Theorem 16 If E is executable, and then E. That is, ans(Q) is a minimal feasible query containing Q. PROOF We have from Proposition 4. Set We know that for all We will show that implies from which it follows that If is unsatisfiable, then is also unsatisfiable, so holds trivially, Therefore assume, to get a contradiction, that is satisfiable, and Since is satisfiable and by [WL03, Theorem 4.3] we must have a tree with root for some and where each node is of the form and represents a true containment except when is unsatisfiable, in which case also the node has no children. Otherwise, for some containment mapping witnessing the containment there is one child for every negative literal in Each child is of the form where and appears in Since E, if in this tree we replace every by by Lemma 15 we must have some nonterminal node where the containment doesn’t hold. Accordingly, assume that and For this to hold, there must be a containment mapping which maps into some literal which appears in but not in That is, there must be some so that appears in and By Propositions 1 and 9, since is executable, is By Proposition 11, is and so, by Lemma 14, Therefore, is in which is a contradiction. Corollary 17 Q is feasible iff Theorem 18 That is, determining whether a query is feasible is polynomialtime many one equivalent to determining whether a query is contained in another query. PROOF One direction follows from Corollary 17 and Proposition 2. For the other direction, consider two queries where The query where is a variable not appearing in P or Q and B is a relation not appearing in P or Q with access pattern We give relations R appearing in P or Q output access patterns (i.e., As a result, P and Q are both executable, Please purchase PDF SplitMerge on www.verypdf.com to remove this watermark
 436 A. Nash and B. Ludascher but and is not feasible. We set Clearly, If then so by Corollary 17, is feasible. If then since and we have so again by Corollary 17, is not feasible. Since is we have Corollary 19 is includes the classes CQ, UCQ, and We have the following strict inclusions Algorithm FEASIBLE essentially consists of two steps: (i) compute ans(Q), and (ii) test Below we show that FEASIBLE provides optimal processing for all the above subclasses of Also, we compare FEASIBLE to the algorithms given in [LC01]. 5.3 Conjunctive Queries Li and Chang [LC01] show that FEASIBLE(CQ) is NPcomplete and provide two algorithms for testing feasibility of Find a minimal so then check that ans(M) = M (they call this algorithm CQstable). Compute ans(Q), then check that (they call this algorithm CQstable*). The advantage of the latter approach is that ans(Q) may be equal to Q, elim inating the need for the equivalence check. For conjunctive queries, algorithm FEASIBLE is exactly the same as CQstable*. Example 9 (CQ Processing) Consider access patterns and and the conjunctive query which is not orderable. Algorithm CQstable first finds the minimal then checks M for orderability (M is in fact executable). Algorithms CQstable* and FEASIBLE first find A := ans(Q) then check that holds (which is the case). 5.4 Conjunctive Queries with Union Li and Chang [LC01] show that FEASIBLE(UCQ) is NPcomplete and provide two algorithms for testing feasibility of with Please purchase PDF SplitMerge on www.verypdf.com to remove this watermark
 Processing Unions of Conjunctive Queries with Negation 437 Find a minimal (with respect to union) so with then check that every is feasible using either CQstable or CQstable* (they call this algorithm UCQstable) Take the union P of all the feasible then check that (they call this algorithm UCQstable*). Clearly, holds by construction. For UCQs, algorithm FEASIBLE is different from both of these and thus pro vides an alternate algorithm. The advantage of CQstable* and FEASIBLE over CQstable is that P or ans(Q) may be equal to Q, eliminating the need for the equivalence check. Example 10 (UCQ Processing) Consider access patterns and and the query Algorithm UCQstable first finds the minimal (with respect to union) then checks that M is feasible (it is). Algorithm UCQstable* first finds P, the union of the feasible rules in Q then checks that holds (it does). Algorithm FEASIBLE finds A := ans(Q) the union of the answerable part of each rule in Q then checks that holds (it does). 5.5 Conjunctive Queries with Negation Proposition 20 Assume are given by where the and are not necessarily distinct and the and are also not necessarily distinct. Then define Please purchase PDF SplitMerge on www.verypdf.com to remove this watermark
 438 A. Nash and B. Ludäscher with access patterns Then clearly and therefore iff iff ans(L) iff L is feasible. The second iff follows from the fact that every containment mapping corresponds to a unique containment mapping ans(L) and vice versa. Since is we have Corollary 21 is 6 Discussion and Conclusions We have studied the problem of producing and processing executable query plans for sources with limited access patterns. In particular, we have extended the results by Li et al. [LC01,Li03] to conjunctive queries with negation and unions of conjunctive queries with negation Our main theorem (Theorem 18) shows that checking feasibility for and is equivalent to checking containment for and respectively, and thus is complete. Moreover, we have shown that our treatment for nicely unifies previous results and techniques for CQ and UCQ respectively and also works optimally for In particular, we have presented a new uniform algorithm which is optimal for all four classes. We have also shown how we can often avoid the theoretical worstcase complexity, both by approximations at compiletime and by a novel runtime processing strategy. The basic idea is to avoid performing the computationally hard containment checks and instead (i) use two efficiently computable approximate plans and which produce tight underestimates and overestimates of the actual query answer for Q (algorithm PLAN*), and de fer the containment check in the algorithm FEASIBLE if possible, and (ii) use a runtime algorithm ANSWER*, which may report complete answers even in the case of infeasible plans, and which can sometimes quantify the degree of com pleteness. [Li03, Sec.7] employs a similar technique to the case of CQ. However, since union and negation are not handled, our notion of bounding the result from above and below is not applicable there (essentially, the underestimate is always empty when not considering union). Although technical in nature, our work is driven by a number of practical engineering problems. In the Bioinformatics Research Network project [BIR03], we are developing a database mediator system for federating heterogeneous brain data [GLM03,LGM03]. The current prototype takes a query against a globalas view definition and unfolds it into a plan. We have used ANSWERABLE and a simplified version (without containment check) of PLAN* and ANSWER* in the system. Similarly, in the SEEK and SciDAC projects [SEE03,SDM03] we are building distributed scientific workflow systems which can be seen as procedural variants of the declarative query plans which a mediator is processing. Please purchase PDF SplitMerge on www.verypdf.com to remove this watermark
 Processing Unions of Conjunctive Queries with Negation 439 We are interested in extending our techniques to larger classes of queries and to consider the addition of integrity constraints. Even though many ques tions become undecidable when moving to full firstorder or Datalog queries, we are interested in finding analogous compiletime and runtime approximations as presented in this paper. Acknowledgements. Work supported by NSFACI 9619020 (NPACI), NIH 8P41 RR0860508S1 (BIRNCC), NSFITR 0225673 (GEON), NSFITR 0225676 (SEEK), and DOE DEFC0201ER25486 (SciDAC). References [BIR03] Biomedical Informatics Research Network Coordinating Center (BIRN CC), University of California, San Diego. http://nbirn.net/, 2003. [CM77] A. K. Chandra and P. M. Merlin. Optimal Implementation of Conjunc tive Queries in Relational Data Bases. In ACM Symposium on Theory of Computing (STOC), pp. 77–90, 1977. [CR97] C. Chekuri and A. Rajaraman. Conjunctive query containment revisited. In Intl. Conf. on Database Theory (ICDT), Delphi, Greece, 1997. [DL97] O. M. Duschka and A. Y. Levy. Recursive plans for information gathering. In Proc. IJCAI, Nagoya, Japan, 1997. [FLMS99] D. Florescu, A. Y. Levy, I. Manolescu, and D. Suciu. Query Optimization in the Presence of Limited Access Patterns. In SIGMOD, pp. 311–322, 1999. [GLM03] A. Gupta, B. Ludäscher, and M. Martone. BIRNM: A Semantic Mediator for Solving RealWorld Neuroscience Problems. In ACM Intl. Conference on Management of Data (SIGMOD), 2003. System demonstration. [LC01] C. Li and E. Y. Chang. On Answering Queries in the Presence of Limited Access Patterns. In Intl. Conference on Database Theory (ICDT), 2001. [LGM03] B. Ludäscher, A. Gupta, and M. E. Martone. Bioinformatics: Manag ing Scientific Data. In T. Critchlow and Z. Lacroix, editors, A Model Based Mediator System for Scientific Data Management. Morgan Kauf mann, 2003. [Li03] C. Li. Computing Complete Answers to Queries in the Presence of Limited Access Patterns. Journal of VLDB, 12:211–227, 2003. [LS93] A. Y. Levy and Y. Sagiv. Queries Independent of Updates. In Proc. VLDB, pp. 171–181, 1993. [NL04] A. Nash and B. Ludäscher. Processing FirstOrder Queries under Limited Access Patterns. submitted for publication, 2004. [PGH98] Y. Papakonstantinou, A. Gupta, and L. M. Haas. CapabilitiesBased Query Rewriting in Mediator Systems. Distributed and Parallel Databases, 6(1):73–110, 1998. [Sar91] Y. Saraiya. Subtree elimination algorithms in deductive databases. PhD thesis, Computer Science Dept., Stanford University, 1991. [SDM03] Scientific Data Management Center (SDM). http://sdm.lbl.gov/sdmcenter/ and http://www.er.doe.gov/scidac/, 2003. [SEE03] Science Environment for Ecological Knowledge (SEEK). http://seek.ecoinformatics.org/, 2003. Please purchase PDF SplitMerge on www.verypdf.com to remove this watermark
 440 A. Nash and B. Ludäscher [SY80] Y. Sagiv and M. Yannakakis. Equivalences Among Relational Expressions with the Union and Difference Operators. Journal of the ACM, 27(4) :633– 655, 1980. [Ull88] J. Ullman. The Complexity of Ordering Subgoals. In ACM Symposium on Principles of Database Systems (PODS), 1988. [WL03] F. Wei and G. Lausen. Containment of Conjunctive Queries with Safe Negation. In Intl. Conference on Database Theory (ICDT), 2003. [WSD03] Web Services Description Language (WSDL) Version 1.2. http://www.w3.org/TR/wsdl12, June 2003. Please purchase PDF SplitMerge on www.verypdf.com to remove this watermark
 Projection Pushing Revisited* Benjamin J. McMahan1, Guoqiang Pan1, Patrick Porter2, and Moshe Y. Vardi1 1 Department of Computer Science, Rice University, Houston, TX 770051892, U.S.A. {mcmahanb,gqpan}@rice.edu, vardi@cs.rice.edu 2 Scalable Software Patrick.Porter@scalablesoftware.com Abstract. The join operation, which combines tuples from multiple relations, is the most fundamental and, typically, the most expensive operation in database queries. The standard approach to joinquery optimization is cost based, which requires developing a cost model, assigning an estimated cost to each query processing plan, and searching in the space of all plans for a plan of minimal cost. Two other approaches can be found in the databasetheory literature. The first approach, initially proposed by Chandra and Merlin, focused on minimizing the number of joins rather then on selecting an optimal join order. Unfortunately, this approach requires a homomorphism test, which itself is NPcomplete, and has not been pursued in practical query processing. The second, more recent, approach focuses on structural properties of the query in order to find a projectjoin order that will minimize the size of intermediate results during query evaluation. For example, it is known that for Boolean projectjoin queries a projectjoin order can be found such that the arity of intermediate results is the treewidth of the join graph plus one. In this paper we pursue the structuraloptimization approach, motivated by its success in the context of constraint satisfaction. We chose a setup in which the costbased approach is rather ineffective; we generate projectjoin queries with a large number of relations over databases with small relations. We show that a standard SQL planner (we use PostgreSQL) spends an exponential amount of time on generating plans for such queries, with rather dismal results in terms of per formance. We then show how structural techniques, including projection pushing and join reordering, can yield exponential improvements in query execution time. Finally, we combine early projection and join reordering in an implementation of the bucketelimination method from constraint satisfaction to obtain another exponential improvement. 1 Introduction The join operation is the most fundamental and, typically, the most expensive operation in database queries. Indeed, most database queries can be expressed as selectprojectjoin queries, combining joins with selections and projections. Choosing an optimal plan, i.e., the particular order in which to perform the select, project, and join operations * Work supported in part by NSF grants CCR9988322, CCR0124077, CCR0311326, IIS 9908435, IIS9978135, and EIA0086264. E. Bertino et al. (Eds.): EDBT 2004, LNCS 2992, pp. 441–458, 2004. © SpringerVerlag Berlin Heidelberg 2004 Please purchase PDF SplitMerge on www.verypdf.com to remove this watermark
 442 B.J. McMahan et al. in the query, can have a drastic impact on query processing time and is therefore a key focus in queryprocessing research [32,19]. The standard approach is that of cost based optimization [22]. This approach requires the development of a cost model, based on database statistics such as relation size, block size, and selectivity, which enables assigning an estimated cost to each plan. The problem then reduces to searching the space of all plans for a plan of minimal cost. The search can be either exhaustive, for search spaces of limited size (cf. [4]), or incomplete, such as simulated annealing or other approaches (cf. [25]). In constructing candidate plans, one takes into account the fact that the join operation is associative and commutative, and that selections and projections commute with joins under certain conditions (cf. [34]). In particular, selections and projections can be “pushed” downwards, reducing the number of tuples and columns in intermediate relations [32]. Costbased optimizations are effective when the search space is of manageable size and we have reasonable cost estimates, but it does not scale up well with query size (as our experiments indeed show). Two other approaches can be found in the databasetheory literature, but had little impact on queryoptimization practice. The first approach, initially proposed by Chandra and Merlin in [8] and then explored further by Aho, Ullman, and Sagiv in [3,2], focuses on minimizing the number of joins rather than on selecting a plan. Unfortunately, this approach generally requires a homomorphism test, which itself is NPhard [20], and has not been pursued in practical query processing. The second approach focuses on structural properties of the query in order to find a projectjoin order that will minimize the size of intermediate results during query evaluation. This idea, which appears first in [34], was first analytically studied for acyclic joins [35], where it was shown how to choose a projectjoin order in a way that establishes a linear bound on the size of intermediate results. More recently, this approach was extended to general projectjoin queries. As in [35], the focus is on choosing the project join order in such a manner so as to polynomially bound the size of intermediate results [10,21,26,11]. Specific attention was given in [26,11] to Boolean projectjoin queries, in which all attributes are projected out (equivalently, such a query simply tests the nonemptiness of a join query). For example, [11] characterizes the minimal arity of intermediate relations when the projectjoin order is chosen in an optimal way and projections are applied as early as possible. This minimal arity is determined by the join graph, which consists of all attributes as nodes and all relation schemes in the join as cliques. It is shown in [11] that the minimal arity is the treewidth of the join graph plus one. The treewidth of a graph is a measure of how close this graph is to being a tree [16] (see formal definition in Section 5). The arity of intermediate relations is a good proxy for their size, since a constantarity bound translates to a polynomialsize bound. This result reveals a theoretical limit on the effectiveness of projection pushing and join reordering in terms of the treewidth of the join graph. (Note that the focus in [28] is on projection pushing in recursive queries; the nonrecursive case is not investigated.) While acyclicity can be tested efficiently [31], finding the treewidth of a graph is NPhard [5]. Thus, the results in [11] do not directly lead to a feasible way of finding an optimal projectjoin order, and so far the theory of projection pushing, as developed in [10,21,26,11], has not contributed to query optimization in practice. At the same time, the projectionpushing strategy has been applied to solve constraintsatisfaction Please purchase PDF SplitMerge on www.verypdf.com to remove this watermark
 Projection Pushing Revisited 443 problems in Artificial Intelligence with good experimental results [29,30]. The input to a constraintsatisfaction problem consists of a set of variables, a set of possible val ues for the variables, and a set of constraints between the variables; the question is to determine whether there is an assignment of values to the variables that satisfies the given constraints. The study of constraint satisfaction occupies a prominent place in Artificial Intelligence, because many problems that arise in different areas can be mod eled as constraintsatisfaction problems in a natural way; these areas include Boolean satisfiability, temporal reasoning, belief maintenance, machine vision, and scheduling [14]. A general method for projection pushing in the context of constraint satisfaction is the bucketelimination method [15,14]. Since evaluating Boolean projectjoin queries is essentially the same as solving constraintsatisfaction problems [26], we attempt in this paper to apply the bucketelimination approach to approximate the optimal projectjoin order (i.e., the order that bounds the arity of the intermediate results by the treewidth plus one). In order to focus solely on projection pushing in projectjoin expressions, we choose an experimental setup in which the costbased approach is rather ineffective. To start, we generate projectjoin queries with a large number (up to and over 100) of relations. Such expressions are common in mediatorbased systems [36]. They challenge cost based planners, because of the exceedingly large size of the search space, leading to unacceptably long query compile time. Furthermore, to factor out the influence of cost information we consider small databases, which fit in main memory and where cost information is essentially irrelevant. (Such databases arise naturally in query containment and join minimization, where the query itself is viewed as a database [8]. For a survey of recent applications of query containment see [23].) We show experimentally that a standard SQL planner (we use PostgreSQL) spends an exponential amount of time on generating plans for such queries, with rather dismal results in terms of performance and without taking advantage of projection pushing (and neither do the SQL planners of DB2 and Oracle, despite the widely held belief that projection pushing is a standard queryoptimization technique). Our experimental test suite consists of a variety of projectjoin queries. We take advantage of the correspondence between constraint satisfaction and projectjoin queries [26] to generate queries and databases corresponding to instances of 3COLOR problems [20]. Our main focus in this paper is to study the scalability of various projectionpushing methods. Thus, our interest is in comparing the performance of different optimization techniques when the size of the queries is increased. We considered both random queries as well as a variety of queries with specific structures, such as “augmented paths”, “ladders”, “augmented ladders”, and “augmented circular ladders” [27]. To study the effectiveness of the bucketelimination approach, we start with a straightforward plan that joins the relations in the order in which they are listed, without applying projection pushing. We then proceed to apply projection pushing and join reordering in a greedy fashion. We demonstrate experimentally that this yields exponential improvement in query execution time over the straightforward approach. Finally, we combine projection pushing and join reordering in an implementation of the bucketelimination method. We first prove that this method is optimal for general projectjoin queries with respect to intermediateresult arity, provided the “right” order of “buckets” is used (this was Please purchase PDF SplitMerge on www.verypdf.com to remove this watermark
 444 B.J. McMahan et al. previously known only for Boolean projectjoin queries [15,17,26,11]). Since finding such an order is NPhard [5], we use the “maximum cardinality” order of [31], which is often used to approximate the optimal order [7,29,30]. We demonstrate experimentally that this approach yields an exponential improvement over the greedy approach for the complete range of input queries in our study. This shows that applying bucket elimination is highly effective even when applied heuristically and it significantly dominates greedy heuristics, without incurring the excessive cost of searching large plan spaces. The outline of the paper is as follows. Section 2 describes the experimental setup. We then describe a naive and straightforward approach in Section 3, a greedy heuristic approach in Section 4, and the bucketelimination approach in Section 5. We report on our scalability experiments in Section 6, and conclude with a discussion in Section 7. 2 Experimental Setup Our goal is to study joinquery optimization in a setting in which the traditional cost based approach is ineffective, since we are interested in using the structure of the query to drive the optimization. Thus, we focus on projectjoin queries with a large number of relations over a very small database, which not only easily fits in main memory, but also where index or selectivity information is rather useless. First, to neutralize the effect of queryresult size we consider Boolean queries in which all attributes are projected out, so the final result consists essentially of one bit (empty result vs. nonempty result). Then we also consider queries where a fraction of attributes are not projected out, to simulate more closely typical database usage. We work with projectjoin queries, also known as conjunctive queries (conjunctive queries are usually defined as positive, existential conjunctive firstorder formulas [1]). Formally, an projectjoin query is a query definable by the projectjoin fragment of relational algebra; that is, by an expression of the form where the are relations and are the free variables (we use the terms “variables” and “attributes” interchangably). Initially, we focus on Boolean projectjoin queries, in which there are no free variables. We emulate Boolean queries by including only a single variable in the projection (i.e., Later we consider nonBoolean queries where there are a fixed fraction of free variables by listing them in the projection. In our experiments, we generate queries with the desired characteristics by translating graph instances of 3COLOR into projectjoin queries, cf. [8]. This translation yields queries over a single binary relation with six tuples. It is important to note, however, that our algorithms do not rely on the special structure of the queries that we get from 3COLOR instances (i.e., bounded arity of relations and bounded domain size)–they are applicable to projectjoin queries in general. An instance of 3COLOR is a graph G = (V, E) and a set of colors C = {1,2,3}, where and For each edge there are six possible colorings of to satisfy the requirement of no monochromatic edges. We define the relation edge as containing all six tuples corresponding to all pairs of distinct colors. The query is then expressed as the projectjoin expression This query returns a nonempty result over the edge relation iff G is 3colorable [8]. Please purchase PDF SplitMerge on www.verypdf.com to remove this watermark
 Projection Pushing Revisited 445 Fig. 1. Augmented path, ladder, augmented ladder, and augmented circular ladder We note that our queries have the following features (see our concluding remarks): Projecting out a column from our relation yields a relation with all possible tuples. Thus, in our setting, semijoins, as in the WongYoussefi algorithm [34], are useless. This enables us to focus solely on ordering joins and projections. Since we only have one relation of fixed arity, differences between the various notions of width, such as treewidth, query width, and hypertree widths are minimized [10, 21], enabling us to focus in this paper on treewidth. To generate a range of queries with varying structural properties, we start by gener ating random graph instances. For a fixed number of vertices and a fixed number of edges, instances are generated uniformly. An edge is generated by choosing uniformly at random two distinct vertices. Edges are generated (without repetition) until the right number of edges is arrived at. We measure the performance of our algorithms by scaling up the size of the queries (note that the database here is fixed). We focus on two types of scalability. First, we keep the order (i.e. the number of vertices) fixed, while scaling up the density, which is the ratio of edges to vertices. Second, we keep the density fixed while scaling up the order. Clearly, a low density suggests that the instance is un derconstrained, and therefore is likely to be 3colorable, while a high density suggests that the instance is overconstrained and is unlikely to be 3colorable. Thus, density scal ing yields a spectrum of problems, going from underconstrained to overconstrained. We studied orders between 10 and 35 and densities between 0.5 and 8.0. We also consider nonrandom graph instances for 3COLOR. These queries, sug gested in [27], have specific structures. An augmented path (Figure 1a) is a path of length where for each vertex on the path a dangling edge extends out of the vertex. A ladder (Figure 1 b) is a ladder with rungs. An augmented ladder (Figure 1c) is a ladder where every vertex has an additional dangling edge, and an augmented circular ladder (Figure 1d) is an augmented ladder where the top and bottom vertices are connected together with an edge. For these instances only the order is scaled; we used orders from 5 to 50. All experiments were performed on the Rice Tersascale Cluster1, which is a Linux cluster of Itanium II processors with 4GB of memory each, using PostgreSQL2 7.2.1. 1 http://www.citi.rice.edu/rtc/ 2 http://www.postgresql.org/ Please purchase PDF SplitMerge on www.verypdf.com to remove this watermark
 446 B.J. McMahan et al. For each run we measured the time it took to generate the query, the time the PostgreSQL Planner took to optimize the query, and the execution time needed to actually run the query. For lack of space we report only median running times. Using commandline parameters we selected hash joins to be the default, as hash joins proved most efficient in our setting. 3 Naive and Straightforward Approaches Given a conjunctive query edge we first use a naive trans lation of into SQL: As SQL does not explicitly allow us to express Boolean queries, we instead put a single vertex in the SELECT section. The FROM section simply enumerates all the atoms in the query, referring to them as and renames the columns to match the vertices of the query. The WHERE section enforces equality of different occurrences of the same vertex. More precisely, we enforce equality of each occurrence to the first occurrence of the same vertex; points to the first occurrence of the vertex We ran these queries for instances of order 5 and integral densities from 1 to 8 (the database engine could not handle larger orders with the naive approach). The PostgreSQL Planner found the naive queries exceedingly difficult to compile; compile time was four orders of magnitude longer than execution time. Furthermore, compile time scaled exponentially with the density as shown in Figure 2. We used the PostgreSQL Planner’s genetic algorithm option to search for a query plan, as an exhaustive search for our queries was infeasible. This algorithm proved to be quite slow as well as ineffective for our queries. The plans generated by the Planner showed that it does not utilize at all projection pushing; it simply chooses some join order. In an attempt to get around the Planner’s ineffectiveness, we implemented a straight forward approach. We explicitly list the joins in the FROM section of the query, instead of using equalities in the WHERE section as in the naive approach. Parentheses forces the evaluation to proceed from to and onwards (i.e., (... We omit parentheses here for sake of readability. The order in which the relations are listed then becomes the order that the database engine evaluates the query. This effectively limits what the Planner can do and therefore drastically decreases compile time. As is shown in Figure 2, compile time still scales exponentially with density, but more gracefully than the compile time for the naive approach. Please purchase PDF SplitMerge on www.verypdf.com to remove this watermark
 Projection Pushing Revisited 447 Fig. 2. Naive and straightforward approaches: density scaling of compile time, 3SAT, 5 variables, logscale We note that the straightforward approach also does not take advantage of projection pushing. We found query execution time for the naive and straightforward approaches to be essentially identical; the join order chosen by the genetic algorithm is apparently no better than the straightforward order. In the rest of the paper we show how we can take advantage of projection pushing and join reordering to improve query execution time dramatically. As a side benefit, since we use subqueries to enforce a particular join and projection order, compile time becomes rather negligible, which is why we do not report it. 4 Projection Pushing and Join Reordering The conjunctive queries we are considering have the form If does not appear in the relations then we can rewrite the formula into an equivalent one: where livevars are all the variables in the scope minus This means we can write a query to join the relations project out and join the result with relations We then say that the projection of has been pushed in and has been projected early. The hope is that early projection would reduce the size of intermediate results by reducing their arity, making further joins less expensive, and thus reducing the execution time of the query. Note that the reduction in size of intermediate results has to offset the overhead of creating a copy of the projected relations. We implemented early projection in SQL using subqueries. The subformula found in the scope of each nested existential quantifier is itself a conjunctive query, therefore each nested existential quantifier becomes a subquery. Suppose that and above are minimal. Then the SQL query can be rewritten as: Please purchase PDF SplitMerge on www.verypdf.com to remove this watermark
 448 B.J. McMahan et al. where is obtained by translating the subformula into SQL according to the straightforward approach (with updated to point to ward when appropriate, for occurrences of The only difference between the subquery and the full query is the SELECT section. In the subquery the SELECT section contains all live variables within its scope, i.e. all variables except for Finally, we proceed recursively to apply early projection to the join of The early projection method processes the relations of the query in a linear fashion. Since the goal of early projection is to project variables as soon as possible, reordering the relations may enable us to project early more aggressively. For example, if a variable appears only in the first and the last relation, early projection will not quantify out. But had the relations been processed in a different order, could have been projected out very early. In general, instead of processing the relations in the order we can apply a permutation and process the relations in the order The permutation should be chosen so as to minimize the number of live variables in the intermediate relations. This observation was first made in the context of symbolic model checking, cf. [24]. Finding an optimal permutation for the order of the relations is a hard problem in and of itself. So we have implemented a greedy approach, searching at each step for an atom that would result in the maximum number of variables to be projected early. The algorithm incrementally computes an atom order. At each step, the algorithm searches for an atom with the maximum number of variables that occur only once in the remaining atoms. If there is a tie, the algorithm chooses the atom that shares the least variables with the remaining atoms. Further ties are broken randomly. Once the permutation is computed, we construct the same SQL query as before, but this time with the order suggested by We then call this method reordering. 5 Bucket Elimination The optimizations applied in Section 4 correspond to a particular rewriting of the original conjunctive query according to the algebraic laws of the relational algebra [32]. By using projection pushing and join reordering, we have attempted to reduce the arity of intermediate relations. It is natural to ask what the limit of this technique is, that is, if we consider all possible join orders and apply projection pushing aggressively, what is the minimal upper bound on the arity of intermediate relations? Consider a projectjoin query over the set of relations, where A is the set of attributes in and the target schema is a subset of A. A joinexpression tree of Q can be defined as a tuple where T is a tree, with nodes and edges rooted at and both and label the nodes of T with sets of attributes. For each node is called ’s working label and is called ’s projected label. For every leaf node there is some such that Please purchase PDF SplitMerge on www.verypdf.com to remove this watermark
 Projection Pushing Revisited 449 For every nonleaf node we define as the union of the projected labels of its children. The projected label of a node is the subset of that consists of all that appear outside the subtree of T rooted at All other attributes are said to be unnecessary for Intuitively, the join expression tree describes an evaluation order for the join, where the joins are evaluated bottom up and projection is applied as early as possible for that particular evaluation order. The width of the joinexpression tree is defined as the maximum size of the working label. The join width of Q is the width over all possible joinexpression trees of Q. To understand the power of join reordering and projection pushing, we wish to char acterize the join width of projectjoin queries. We now describe such a characterization in terms of the join graph of Q. In the join graph the node set V is the set A of attributes, and the edge set E consists of all pairs of attributes that cooccur in some relation Thus, each relation yields a clique over its attributes in In addition, we add an edge for every pair of attributes in the schema The important parameter of the join graph is its treewidth [16]. Let G = (V, E) be a graph. A tree decomposition of G is a pair (T, X), where T = (I, F) is a tree with node set and edge set F, and is a family of subsets of V, one for each node of T, such that (1) (2) for every edge there is an with and and (3) for all if is on the path from to in T, then The width of a tree decomposition is The treewidth of a graph G, denoted by is the minimum width over all possible tree decompositions of G. For each fixed there is a lineartime algorithm that tests whether a given graph G has treewidth The algorithms actually constructs a tree decomposition of G of width [16]. We can now characterize the join width of projectjoin queries: Theorem 1. The join width of a projectjoin query Q is Proof Sketch: We first show that the join width of Q provides a bound for Given a joinexpression tree of Q with width we construct a tree decomposition of of width Intuitively, we just drop all the projected labels and use the working label as the tree decomposition labeling function. Lemma 1. Given a projectjoin query Q and joinexpression tree of width there is a tree decomposition of the join graph such that the width of is In the other direction, we can go from tree decompositions to joinexpression trees. First the join graph is constructed and a tree decomposition of width for this graph is constructed. Once we have a tree decomposition, we simplify it to have only the nodes needed for the joinexpression tree without increasing the width of the tree decomposition. In other words, the leaves of the simplified tree decomposition each correspond to a relation in and the nodes between these leaves still maintain all the treedecomposition properties. Lemma 2. Given a projectjoin query Q, its join graph and a tree decomposition (T = (I, F), X) of of width there is a simplified tree decomposition Please purchase PDF SplitMerge on www.verypdf.com to remove this watermark
 450 B.J. McMahan et al. of of width such that every leaf node of has a label containing an for some Lemma 3. Given a projectjoin query Q, a join graph and a simplified tree de composition of of treewidth there is a joinexpression tree of Q with join width Theorem 1 offers a graphtheoretic characterization of the power of projection push ing and join reordering. The theorem extends results in [11] regarding rewriting of Boolean conjunctive queries, expressed in the syntax of firstorder logic. That work ex plores rewrite rules whose purpose is to rewrite the original query Q into a firstorder formula using a smaller number of variables. Suppose we succeeded to rewrite Q into a formula of which is the fragment of firstorder logic with variables, containing all atomic formulas in these variables and closed only under conjunction and existential quantification over these variables. We then know that it is possible to evaluate Q so that all intermediate relations are of width at most yielding a polynomial upper bound on query execution time [33]. Given a Boolean conjunctive query Q, we’d like to charac terize the minimal such that Q can be rewritten into since this would describe the limit of variableminimization optimization. It is shown in [11] that if is a positive integer and Q a Boolean conjunctive query, then the join graph of Q has treewidth iff there is an that is a rewriting of Q. Theorem 1 not only uses the more intuitive concepts of join width (rather than expressibility in but also extend the characterization to nonBoolean queries. Unfortunately, we cannot easily turn Theorem 1 into an optimization method. While determining if a given graph G has treewidth can be done in linear time, this depends on being fixed. Finding the treewidth is known to be NPhard [5]. An alternative strategy to minimizing the width of intermediate results is given by the bucketelimination approach for constraintsatisfaction problems [13], which are equivalent to Boolean projectjoin queries [26]. We now rephrase this approach and extend it to general projectjoin queries. Assume that we are given an order of the attributes of a query Q. We start by creating “buckets”, one for each variable For an atom of the query, we place the relation with attributes in bucket max We now iterate on from to 1, eliminating one bucket at a time. In iteration we find in bucket several relations, where is an attribute in all these relations. We compute their join, and project out if it is not in the target schema. Let the result be If is empty, then the result of the query is empty. Otherwise, let be the largest index smaller than such that is an attribute of we move to bucket Once all the attributes that are not in the target schema have been projected out, we join the remaining relations to get the answer to the query. For Boolean queries (for which bucket elimination was originally formulated), the answer to the original query is ‘yes’ if none of the joins returns an empty result. The maximal arity of the relations computed during the bucketelimination process is called the induced width of the process relative to the given variable order. Note that the sequence of operations in the bucketelimination process is independent of the actual relations and depends only on the relation’s schemas (i.e., the attributes) and the order of the variables [17]. By permuting the variables we can perhaps minimize the induced Please purchase PDF SplitMerge on www.verypdf.com to remove this watermark
 Projection Pushing Revisited 451 width. The induced width of the query is the induced width of bucket elimination with respect to the best possible variable order. Theorem 2. The induced width of a projectjoin query is its treewidth. This theorem extends the characterization in [15,17] for Boolean projectjoin queries. Theorem 2 tells us that we can optimize the width of intermediate results by schedul ing the joins and projections according to the bucketelimination process, using a sub query for each bucket, if we are provided with the optimal variable order. Unfortunately, since determining the treewidth is NPhard [5], it follows from Theorem 2 that finding op timal variable order is also NPhard. Nevertheless, we can still use the bucketelimination approach, albeit with a heuristically chosen variable order. We follow here the heuristic suggested in [7,29,30], and use the maximumcardinality search order (MCS order) of [31]. We first construct the join graph of the query. We now number the variables from 1 to where the variables in the target schema are chosen as initial variables and then the variable is selected to maximize the number of edges to variables already selected (breaking ties randomly). 6 Experimental Results 6.1 Implementation Issues Given a graph instance, we convert the formula into an SQL query. For the nonBoolean case, before we convert the formula we pick 20% of the vertices randomly to be free. The query is then sent to the PostgreSQL backend, which returns a nonempty answer iff the graph is Most of the implementation issues arise in the construction of the optimized query from the graphs formulas. We describe these issues here. The naive implementation of this conversion starts by creating an array E of edges, where for each edge we store its vertices. We also construct an array min_occur such that for every vertex we have that is the minimal edge containing an occurrence of For the SQL query, we SELECT the first vertex that occurs in an edge, and list in the FROM section all the edges and their vertices using the edge relation. Finally, for the WHERE section we traverse the edges and for each edge and each vertex we add the condition where For the nonBoolean case, the only change is to list the free vertices in the SELECT clause. The straightforward implementation uses the same data structures as the naive implementation. The SELECT statement remains the same, but the FROM statement now first lists the edges in reverse order, separated by the keyword JOIN. Then, traversing E as before, we list the equalities as ON conditions for the JOINs (parentheses are used to ensure the joins are performed in the same order as in the naive implementation). For the earlyprojection method, we create another array max_occur such that for every vertex we have is the last edge containing Converting the formula to an SQL query starts the same way as in the straightforward implementation, listing all the edges in the FROM section in reverse order. Before listing an edge we check whether for some vertex (we sort the vertices according to max_occur to facilitate this check). In such a case, we generate a subquery Please purchase PDF SplitMerge on www.verypdf.com to remove this watermark
CÓ THỂ BẠN MUỐN DOWNLOAD

Advances in Database Technology P19
46 p  57  7

Advances in Database Technology P13
50 p  45  6

Advances in Database Technology P2
50 p  60  6

Advances in Database Technology P18
46 p  61  5

Advances in Database Technology P16
50 p  51  5

Advances in Database Technology P9
50 p  50  5

Advances in Database Technology P4
50 p  43  5

Advances in Database Technology P5
50 p  36  3

Advances in Database Technology P17
50 p  45  3

Advances in Database Technology P15
50 p  44  3

Advances in Database Technology P14
50 p  50  3

Advances in Database Technology P3
50 p  51  3

Advances in Database Technology P12
50 p  41  3

Advances in Database Technology P8
50 p  45  3

Advances in Database Technology P7
50 p  44  3

Advances in Database Technology P6
50 p  46  3

Advances in Database Technology P11
50 p  56  3