Semantic Query Optimization for Bottom-Up Evaluation ? P. Godfrey1 , J. Gryz1 , J. Minker1 ; 2 fgodfrey , jarek , minkerg@cs.umd.edu Department of Computer Science1 and Institute for Advanced Computer Studies2 University of Maryland , College Park , Maryland 20742 Abstract Semantic query optimization uses semantic knowledge in databases -LRB- represented in the form of integrity constraints -RRB- to rewrite queries and logic programs for the purpose of more efficient query evaluation . Much work has been done to develop various techniques for optimization . Most of it , however , is only applicable to top-down query evaluation strategies . Moreover , little attention has been paid to the cost of the optimization itself . In this paper , we address the issue of semantic query optimization for bottom-up query evaluation strategies with an emphasis on overall efficiency . We restrict our attention to a single optimization technique , join elimination . We discuss various factors that influence the cost of semantic optimization , and present two abstract algorithms for different optimization approaches . The first one pre-processes a query statically before it is evaluated ; the second approach combines query evaluation with semantic optimization using heuristics to achieve the largest possible savings . ? This research was supported by by the following grant : NSF IRI-9300691 1 Introduction Semantic query optimization uses semantic knowledge in the form of integrity constraints to rewrite queries and logic programs for the purpose of more efficient query evaluation . Several researchers have developed methods for semantic optimization in relational and deductive databases -LSB- 1 , 8 , 16 -RSB- . Recently , this work has been extended to programs with recursion -LSB- 9 , 10 , 12 -RSB- and negation -LSB- 2 -RSB- . In this paper we accomplish the following . First , our semantic query optimization method applies to bottom-up query evaluation strategies . Such optimization methods are crucial because bottom-up query evaluation is significantly more efficient , in most all cases , than top-down evaluation . To our knowledge only one paper -LSB- 11 -RSB- addresses specifically the issue of semantic query optimization for bottom-up evaluation . However , the optimizations they consider are restricted to certain types of integrity constraints , and no general technique for query rewriting is provided . Second , we present a cost analysis of our optimization approach and we show how our method exploits this analysis . Last , our optimization technique allows for the efficient use of integrity constraints which contain both EDB and IDB predicates . In most previous work , integrity constraints are restricted to contain only EDB predicates . -LRB- Papers -LSB- 9 , 12 , 16 -RSB- state this condition explicitly . -RRB- The paper is organized as follows . Section 2 introduces notation , and discusses the advantage of bottom-up over top-down query evaluation . Section 3 describes the main focus of our optimization algorithms , namely the removal of joins of tables , which are known beforehand -LRB- via deduction over the ICs and rules -RRB- not to return any answers . The cost of this semantic optimization is discussed in Section 4 . An overview of two such optimization algorithms is provided in Section 5 . The paper concludes with a summary and future research directions in Section 6 . 2 Preliminaries 2.1 Terminology We assume familiarity with the terminology of relational and deductive databases -LSB- 17 -RSB- . A database , DB , consists of an extensional database -LRB- EDB -RRB- , an intensional database -LRB- IDB -RRB- , and a set of integrity constraints -LRB- IC -RRB- . We assume that DB is function-free , the EDB consists of ground , positive facts and the IDB of rules . We also assume here that IDB rules are nonrecursive . An integrity constraint is a rule with an empty head and whose body contains nonground atoms . EDB predicates are those that appear only in bodies of rules . IDB predicates are the rest . We also describe the concept of a query tree -LRB- an AND/OR tree -RRB- . A query tree of an IDB predicate p is the \ parse tree '' of an expression in relational algebra -LRB- X , p p , -RRB- employee -LRB- X , p p -RRB- benefits -LRB- X , hmo -RRB- faculty -LRB- X , p p , -RRB- ta -LRB- X , p p -RRB- staff health-plan -LRB- X , hmo , -RRB- life-ins -LRB- X , hmo , -RRB- query -LRB- X -RRB- Figure 1 : The query tree representation of the query of Example 1 that yields the relation p in terms of the EDB .1 We are mainly interested in union and join operations , so we do not represent selections and projections explicitly in the tree . However , selections and projections are implicitly apparent . Also , whenever an intermediate node of the query tree represents an IDB predicate q , we likewise label that node as q . The following example shows a query tree for the query query -LRB- X -RRB- . Example 1 Let the database contain five base relations : faculty -LRB- Name , Department , Rank -RRB- , staff -LRB- Name , Department , Years of Employment -RRB- , ta -LRB- Name , Department -RRB- , life ins -LRB- Name , Provider , Monthly premium -RRB- and health plan -LRB- Name , Provider , Monthly premium -RRB- . Let there be two rules in the database : the first one defines an employee relation -LRB- via the union of the ta relation and projections from the faculty and staff relations -RRB- ; the second defines a benefits relation -LRB- via the union of projections from the life ins and health plan relations -RRB- . employee -LRB- X , Y -RRB- faculty -LRB- X , Y , Z -RRB- . benefits -LRB- X , Z -RRB- life ins -LRB- X , Z , W -RRB- . employee -LRB- X , Y -RRB- staff -LRB- X , Y , Z -RRB- . benefits -LRB- X , Z -RRB- health plan -LRB- X , Z , W -RRB- . employee -LRB- X , Y -RRB- ta -LRB- X , Y -RRB- . Let a query ask for the names of all employees of the physical plant , p p , whose benefits are provided by hmo : query -LRB- X -RRB- : employee -LRB- X , p p -RRB- , benefits -LRB- X , hmo -RRB- The query tree representation of this query is given in Figure 1 . It is very easy to translate a tree representation of a query to an equivalent relational algebra representation . We often switch between the two representations . The relational algebra representation2of the query -LRB- call it Q -RRB- of Example 1 is : Q = -LRB- ssXfaculty -LRB- X , p p , Y -RRB- -RRB- -LSB- ssXstaff -LRB- X , p p , Z -RRB- -LSB- ta -LRB- X , p p -RRB- -RRB- 1 -LRB- ssXlife ins -LRB- X , hmo , W -RRB- -LSB- ssXhealth plan -LRB- X , hmo , V -RRB- -RRB- Next we define several concepts which we will use in the paper . 1Algorithm 3.2 of -LSB- 17 -RSB- describes how such an expression is derived . 2We ignore for clarity explicit representation of select operations . Definition 2.1 Let Q be a query . U is an unfolding of Q in DB iff ffl U = Q ; ffl U = q1 -LRB- v1 -RRB- ; : : : ; qi ? 1 -LRB- vi ? 1 -RRB- ; P ? ; qi +1 -LRB- vi +1 -RRB- ; : : : ; qm -LRB- vm -RRB- , where U = q1 -LRB- v1 -RRB- ; : : : ; qi ? 1 -LRB- vi ? 1 -RRB- ; qi -LRB- vi -RRB- ; qi +1 -LRB- vi +1 -RRB- ; : : : ; qm -LRB- vm -RRB- is an unfolding of Q and there is a rule < qi -LRB- xi -RRB- P > in IDB for which qi -LRB- vi -RRB- ? = qi -LRB- xi -RRB- ? and ? is an mgu . U is a complete unfolding of Q if it contains only EDB predicates . Example 2 A set of complete unfoldings of the query of Example 1 is : faculty -LRB- X , p p , -RRB- , life ins -LRB- X , hmo , -RRB- : faculty -LRB- X , p p , -RRB- , health plan -LRB- X , hmo , -RRB- : ta -LRB- X , p p -RRB- , life ins -LRB- X , hmo , -RRB- : ta -LRB- X , p p -RRB- , health plan -LRB- X , hmo , -RRB- : staff -LRB- X , p p , -RRB- , life ins -LRB- X , hmo , -RRB- : staff -LRB- X , p p , -RRB- , health plan -LRB- X , hmo , -RRB- : Note that atoms in a -LRB- complete -RRB- unfolding of a query Q represent -LRB- leaf -RRB- nodes in the respective query tree for Q. Definition 2.2 Let U be an unfolding -LRB- not necessarily complete -RRB- of Q. U is a null unfolding of Q in DB iff IDB -LSB- IC j = :9 U Example 3 Let an integrity constraint be : < ta -LRB- X , Y -RRB- , life ins -LRB- X , Z , W -RRB- > , which states that teaching assistants are not entitled to receive life insurance . Then , ta -LRB- X , p p -RRB- , life ins -LRB- X , hmo , -RRB- is a null unfolding of Q of Example 1 . We assume that the null unfoldings of a query are identified beforehand and are provided as input to the optimization algorithm . The reader is refered to -LSB- 4 -RSB- for details on how this is done . In this paper , we discuss the problem of semantic query optimization in the context of bottom-up query evaluation . We assume that the query evaluation proceeds bottom-up , as described in the semi-naive algorithms presented in -LSB- 17 -RSB- -LRB- chapter 3 -RRB- and in -LSB- 7 -RSB- . The problem we address in this paper can be stated informally as follows : given a query tree and a set of null unfoldings , rewrite the query tree -LRB- that is , reformulate the query -RRB- to achieve the largest savings possible . We focus on the elimination of redundant joins . Thus , to achieve the largest savings means maximizing the difference between the savings conferred by the join elimination and the cost of computing the optimized form itself . This cost , as we show later in the paper , can be non-trivial . This is a very different scenario from semantic query optimization for a top-down evaluation strategies . In the top-down case , the cost of optimization is only the cost of identifying null unfoldings . We share that cost also , which can be non-trivial too , but we do not consider that issue here . 2.2 Top-Down versus Bottom-Up Query Processing Most work in semantic query optimization has been done in the context of the top-down , PROLOG style query processing . This type of query processing , however , is impractical in most cases for database query evaluation . First , a topdown approach requires evaluating independently all the complete unfoldings of the query . The number of complete unfoldings for a given query can be exponential in the size of the rule base . In most contemporary databases , this is not so problematic since the number of rules -LRB- views -RRB- is often small . The introduction of deductive databases -LRB- such as Aditi -LSB- 14 -RSB- and CORAL -LSB- 13 -RSB- -RRB- , and heterogenous database systems , incurs increases to the size of the rule base , to the point where top-down query processing becomes unmanageable . Another problem incurred with a top-down approach is redundancy in query processing . If a predicate P is defined by two rules , say R1 and R2 , and each of these rules , given the selections and projections of the query , computes many of the same set of tuples , then the two unfoldings will compute many of the tuples twice . If there are k unfoldings , a given answer -LRB- tuple -RRB- may be computed k times . Bottom-up evaluation largely escapes this problem . Example 4 Consider again the database and the query of Example 1 . Assume additionally that the provider hmo sells its life insurance and its health insurance as a single package , in other words , ssX -LRB- oeY = 0hmo0 -LRB- health plan -LRB- X , Y , Z -RRB- -RRB- = ssT -LRB- oeV = 0hmo0 life ins -LRB- T , V , W -RRB- -RRB- . Then , all answers to the query can be found via just three unfoldings : faculty -LRB- X , p p , -RRB- , life ins -LRB- X , hmo , -RRB- . ta -LRB- X , p p -RRB- , life ins -LRB- X , hmo , -RRB- . staff -LRB- X , p p , -RRB- , life ins -LRB- X , hmo , -RRB- . To evaluate any of the rest of the unfoldings would be redundant . The difference between top-down and bottom-up query evaluation can be expressed as a difference in query representation . For top-down evaluation , the query is represented as a set of complete unfoldings ; for bottom-up evaluation , as a query tree . These two representations differ greatly in their compactness when viewed as formulas in relational algebra written over the EDB predicates . If this compactness is measured -LRB- inversely -RRB- by the number of elementary join and union operations that need to be executed to evaluate the query , then the topdown query representation is the least compact of all equivalent -LRB- in relational algebra -RRB- query forms .3 On the other hand , the query tree tends to minimize the number of these operations providing a compact form of query representation . Example 5 Consider the database and the query of Example 1 . The query tree requires four operations to evaluate the query -LRB- two union operations over the three EDB relations in the left branch , one union over the two EDB relations in the right branch and the final join -RRB- ; whereas the top-down representation of the same query in Example 2 requires eleven operations -LRB- six joins and five unions -RRB- . The query tree representation in this example is most compact . To unfold a query is to distribute one -LRB- or more -RRB- of the unions of its relational algebra representation ; to refold it is to factor out one -LRB- or more -RRB- of its subexpressions from one -LRB- or more -RRB- of the unions of its relational algebra representation . Thus , unfolding a query increases the number of its operations , while refolding decreases the number . 3We assume non-redundancy in the formula . 3 General Optimization Strategy The problem we need to address first is the following : given a query tree and a set of null unfoldings of the query ,4 rewrite the tree to guarantee that the joins that these unfoldings represent are not part of the transformed query . Note that by doing this -LRB- assuming that the tables to be joined are not empty -RRB- we always save in terms of query processing time by not having to do the unnecessary join -LRB- in other words , the join of tables from the null unfolding -RRB- which we know is not going to return any values anyway . In the extreme case , when a query itself is a null unfolding -LRB- such a query is called a simple misconception in the cooperative answering literature -LSB- 3 -RSB- -RRB- , the query does not need to be evaluated at all since we know the answer set is empty . As stated in Section 2.2 , redundant join elimination is straightforward for top-down query processing . Thus , the first approximation to an optimization algorithm can be stated as follows : 1 . unfold the query in all possible ways ; 2 . remove null unfoldings ; and 3 . refold the query resulting from step 2 back as much as possible . Clearly , we do not need to unfold the query in all possible ways . Rather , it is enough to unfold the query partially , just to the extent that the null unfoldings are explicitly represented so that they may be removed . We show informally how this is done on the following example . Example 6 Consider again the database and the query of Example 1 and the null unfolding of Example 3 . The query Q and the null unfolding N expressed in relational algebra are respectively : Q = -LRB- ssXfaculty -LRB- X , p p , Y -RRB- -RRB- -LSB- ssXstaff -LRB- X , p p , Z -RRB- -LSB- ta -LRB- X ; p p -RRB- -RRB- 1 -LRB- ssX life ins -LRB- X , hmo , W -RRB- -LSB- ssXhealth plan -LRB- X , hmo , V -RRB- -RRB- N = ssX -LRB- life ins -LRB- X , hmo , W -RRB- 1 ta -LRB- X ; p p -RRB- -RRB- To represent the unfolding explicitly , we may unfold the query -LRB- partially -RRB- as : Q0 = -LRB- ssXfaculty -LRB- X , p p , Y -RRB- -LSB- ssXstaff -LRB- X , p p , Z -RRB- -RRB- 1 ssXlife-ins -LRB- X , hmo , W -RRB- -LSB- ta -LRB- X , p p -RRB- 1 ssXlife-ins -LRB- X , hmo , W -RRB- -LSB- -LRB- ssX faculty -LRB- X , p p , Y -RRB- -LSB- ta -LRB- X ; p p -RRB- -LSB- ssXstaff -LRB- X , p p , Z -RRB- -RRB- 1 ssXhealth-plan -LRB- X , hmo , V -RRB- After the null unfolding is removed we obtain : Q1 = Q11 -LSB- Q21 , where : Q11 = -LRB- ssXfaculty -LRB- X , p p , Y -RRB- -LSB- ssXstaff -LRB- X , p p , Z -RRB- -RRB- 1 ssX life-ins -LRB- X , hmo , W -RRB- Q21 = -LRB- ssXfaculty -LRB- X , p p , Y -RRB- -LSB- ta -LRB- X , p p -RRB- -LSB- ssXstaff -LRB- X , p p , Z -RRB- -RRB- 1 ssXhealth-plan -LRB- X , hmo , V -RRB- Q11 and Q21 have straightforward representations as query trees as shown in Figure 2 . Since unfolding a query always increases the number of operations in its respective relational algebra representation , it may be viewed as bringing the query form closer to its top-down representation . In the extreme case , when 4An algorithm for computing this set for a given database and a query is presented in -LSB- 4 -RSB- . 1 1 Q -LRB- X -RRB- Q -LRB- X -RRB- 2 1 staff ta -LRB- X , p p -RRB- stafffacult y -LRB- X , p p , -RRB- -LRB- X , p p , -RRB- faculty -LRB- X , p p , -RRB- -LRB- X , p p , -RRB- life ins -LRB- X , hmo , -RRB- health plan -LRB- X , hmo , -RRB- Figure 2 : The query tree representation of Q11 and Q21 there are many null unfoldings the query may have to be unfolded almost completely and can not be refolded to any extent , this worst case converges on the form of the query 's top-down representation . The last issue that deserves to be addressed is the compactness of the optimized query . As stated in Section 2.2 , the difference between the top-down and bottom-up query representations can be expressed syntactically as a difference in their number of operations -LRB- unions and joins -RRB- . The top-down approach maximizes that number , while the bottom-up approach tends to minimize it . We assumed above that the query is unfolded only to the degree necessary so that the null unfoldings are represented explicitly , and then after removing these null unfoldings refolded back from that form . This does not guarantee , however , that the final form of the query is in the most compact form -LRB- that is , has the least number of operations -RRB- . The following example shows this . Example 7 Let the query be : Q = G 1 -LRB- A 1 -LRB- B -LSB- C 1 D -RRB- -LSB- E 1 -LRB- F -LSB- C 1 D -RRB- -RRB- and the null unfolding be : U = E 1 F By simply unfolding the query , removing the null unfolding and refolding the query back we get : Q0 = G 1 -LRB- A 1 -LRB- B -LSB- C 1 D -RRB- -LSB- E 1 C 1 D -RRB- However , the most compact query form is : Q00 = G 1 -LRB- C 1 D 1 -LRB- A -LSB- E -RRB- -LSB- A 1 B -RRB- . There are two reasons for not trying to minimize -LRB- absolutely -RRB- the number of operations in the query . First , it can be shown easily that the minimization problem is NP-complete . Second , we adopt as a working hypothesis the assumption that the input to the optimization algorithm , the query tree , is close to any minimum representation of the query . We conjecture then that the optimized query is also close to any ideal optimized query . We argue , moreover , that even if a polynomial time algorithm were available for optimality , there are still good reasons for not choosing the number of operations as our sole criterion for designing an algorithm . In the next section , it is shown that other costs of 7 semantic optimization can easily overshadow the value of an optimal -LRB- in the above sense -RRB- algorithm . 4 Optimization trade-offs As stated in the previous section , removing null unfoldings from a query produces a less compact query , bringing it closer to its top-down representation . As a consequence , some of the undesirable features of the top-down approach to query evaluation become prominent in the evaluation of the optimized query . 1 . Query fragmentation . Query fragmentation is an inherent feature of semantic optimization for bottom-up query evaluation . There is only one type of null unfolding removal of which does not increase the number of operations in the optimized query . We call such null unfoldings which have this property nice .5 Definition 4.1 Let Q = A1 1 : : : 1 An be a query expressed in relational algebra and U be an unfolding of Q. U is nice iff U = Ai1 1 : : : 1 Ain ? 1 1 B ; ij 2 f1 ; : : : ; n ? 1g ; ij < > ik if j < > k where B is a subexpression of Ain . On the other hand , there are cases where the optimized query will have almost twice the number of operation of the original one . The degree of query fragmentation depends also on the algorithm used . If the optimization algorithm is iterative , that is , it removes null unfoldings sequentially , independently of one another , query fragmentation can be worse than in the case of a global approach . Consider the following extension of Example 6 . Assume that health plan is not an extensional predicate , but is further defined as : health plan -LRB- X , W , V -RRB- subsidized health plan -LRB- X , W , V -RRB- . health plan -LRB- X , W , V -RRB- unsubsidized health plan -LRB- X , W , V -RRB- . Assume also that there is another null unfolding to consider : ta -LRB- X , p p -RRB- , subsidized health plan -LRB- X , hmo , -RRB- . Removing this unfolding from a query Q1 of Example 6 , -LRB- where health plan -LRB- X , hmo , -RRB- has been rewritten via the above rules fragments the query again . Notice , however , that if the original query were split in a different way , for instance , into : Q2 -LRB- X -RRB- = Q12 -LRB- X -RRB- -LSB- Q22 -LRB- X -RRB- in which : Q12 -LRB- X -RRB- = -LRB- faculty -LRB- X , p p , -RRB- -LSB- staff -LRB- X , p p , -RRB- -RRB- 1 -LRB- subsidized health plan -LRB- X , hmo , -RRB- -LSB- unsubsidized health plan -LRB- X , hmo , -RRB- -LSB- life ins -LRB- X , hmo , -RRB- -RRB- Q22 -LRB- X -RRB- = ta -LRB- X , p p -RRB- 1 -LRB- subsidized health plan -LRB- X , hmo , -RRB- -LSB- unsubsidized health plan -LRB- X , hmo , -RRB- -RRB- then removing the second null unfolding does not increase the number of nodes in the tree -LRB- only the second subquery , Q22 -LRB- X -RRB- needs to be rewritten -RRB- . 5Such integrity constraints -LRB- with two atoms -RRB- were called semi-complete join pairs in -LSB- 11 -RSB- . One of the key differences between the two algorithms presented in the next section is the way they handle the removal of multiple null unfoldings . 2 . Recomputation of joins due to table overlaps . Materialized tables in bottom-up query evaluation described here do not contain duplicates -LRB- we assume that duplicates are removed whenever tables are unioned -RRB- . Consider again the database and the query of Example 6 and the condition of Example 4 holds , that is health plan -LRB- X , hmo , Y -RRB- life ins -LRB- X , hmo , Z -RRB- . Then , all answers to the query Q are computed by Q21 and so Q11 is redundant . This redundant computation would not have taken place if the query had not been optimized . 3 . Recomputation of joins due to independent computation of subqueries . Consider yet another extension of Example 6 : assume that health plan is not an extensional predicate , but it is further defined as : health plan -LRB- X , Y , Z -RRB- personel -LRB- SSN , X -RRB- , insurance -LRB- SSN , Y , Z -RRB- . Also assume that the query has been split as in Q3 . Q3 -LRB- X -RRB- = Q13 -LRB- X -RRB- -LSB- Q23 -LRB- X -RRB- in which : Q13 -LRB- X -RRB- = -LRB- faculty -LRB- X , p p , -RRB- -LSB- staff -LRB- X , p p , -RRB- -RRB- 1 -LRB- personel -LRB- SSN , X -RRB- 1 insurance -LRB- SSN , hmo , -RRB- -LSB- life ins -LRB- X , hmo , -RRB- -RRB- Q23 -LRB- X -RRB- = ta -LRB- X , p p -RRB- 1 personel -LRB- SSN , X -RRB- 1 insurance -LRB- SSN , hmo , -RRB- Note that both Q13 and Q23 involve computing the join of personel -LRB- SSN , X -RRB- 1 insurance -LRB- SSN , hmo , -RRB- . However , since the two queries are evaluated independently , the optimal plan for query Q22 -LRB- X -RRB- = ta -LRB- X , p p -RRB- 1 personel -LRB- SSN , X -RRB- 1 insurance -LRB- SSN , hmo , -RRB- may require computing the join ta -LRB- X , p p -RRB- 1 personel -LRB- SSN , X -RRB- first and then joining the result with insurance -LRB- SSN , hmo , -RRB- . Clearly , considering the fact that the join personel -LRB- SSN , X -RRB- 1 insurance -LRB- SSN , hmo , -RRB- has to be computed as part of Q13 , it may be better to compute Q23 in a different order . 4 . Elusive savings . The savings achieved by join elimination are proportional to the sizes of tables whose join can be eliminated from the query because of the presence of an appropriate null unfolding . These savings may be too small , however , to justify applying semantic optimization , given the overhead costs . Assume that ta -LRB- X , p p -RRB- in Example 6 is empty ; that is , there is no teaching assistant employed in the physical plant department . Thus , removing the null unfolding ta -LRB- X , p p -RRB- 1 life ins -LRB- X , hmo , -RRB- saves nothing . In the ideal situation , we should be able to discover such cases to avoid rewriting the query . The problems discussed in points 2 and 3 can be solved easily . Recomputation of joins due to table overlap can be solved in the following fashion . Let U1 ; : : : ; Un be a null unfolding , U1i ; : : : ; Uki be the siblings of Ui ; 1 < = i < = n , in the query tree . We state without formal proof that substituting U ji ; 1 < = j < = k with U ji ? Ui does not change the answer set of the evaluated query while prevent - ing at the same time recomputation of joins due to table overlaps .6 Note also that this computation does not add an extra cost to query evaluation since it is equivalent to duplicate removal from materialized tables . The problem of recomputation of joins due to independent evaluation of subqueries is addressed by multiple query optimization -LRB- see -LSB- 6 , 15 -RSB- on this topic -RRB- . If the savings analysis is to be a part of an optimization algorithm , then the sizes of the tables in the query tree must be part of the input to the algorithm . But the only way7 the sizes of intermediate nodes of the query tree can be learned is by materializing these nodes . Materializing all the nodes of the tree before doing any semantic optimization of course defeats the purpose of optimization -LRB- since this is equivalent to evaluating the query -RRB- . Hence , materialization should be done in stages , interleaving the steps of evaluation and optimization . A consequence , however , is that this type of optimization algorithm must be iterative since we can not know in advance which null unfoldings should be removed . Thus , there is a clear trade-off between a global optimization -LRB- which produces a potentially more compact query as point 1 of this section showed -RRB- and exploiting the savings analysis . The two algorithms in the next section emphasize these different choices . 5 The Algorithms 5.1 A Global Algorithm First we consider a global approach in which all the null unfoldings are removed from the query in parallel . The algorithm will ensure that the rewritten query is minimal . We wish to avoid \ evaluating '' any of the known null unfoldings of a query whenever we evaluate the query . Our approach is to rewrite the query as a set of unfoldings that are independent of the null unfoldings , but which , when evaluated , result in the same answer set as the query 's . This unfolding set , call it S , should have the following properties . Let N be the set of null unfoldings . ffl No unfolding in S should overlap with any unfolding in N ; that is , for U 2 S and V 2 N , U and V have no unfolding in common . -LRB- Call U and V independent of one another in this case . -RRB- ffl N -LSB- S should be a cover of the query ; that is , any complete unfolding of the query is an unfolding of some unfolding in N or S. ffl Set S should be most general : -LCB- no unfolding in S can be refolded at all , and still preserve the above properties ; and 6Note that the difference operation makes sense because nodes in the tree represent tables . We also assume that all atoms of null unfoldings are OR nodes in the query tree . 7Estimating the sizes of intermediate nodes based on the sizes of the tree leaves may be very unreliable -LCB- for any U 2 S , -LRB- N -LSB- S -RRB- ? fUg is not a cover of the query . Techniques from the Carmin System can be used to determine the set of null unfoldings , N , for a query -LSB- 5 , 4 -RSB- . Carmin is a cooperative database system , which provides cooperative responses to queries , in addition to the answer sets . If Carmin can find a set of null unfoldings N for a query which is a cover of the query , and each such null unfolding is provably null , the query is said to be a complex misconception . Carmin detects misconceptions -LRB- both simple and complex -RRB- , and explains them -LRB- based on the proofs -RRB- to the user . Detecting that a query is a misconception is the ultimate in semantic query optimization ; the query does not need to be evaluated because its answer set is known to be empty . A system like Carmin will determine N in attempting to deduce misconceptions . We are interested in intermediate cases where N is not a cover , and so we still need to evaluate -LRB- some optimized form of -RRB- the query .8 Given a query Q and its set of null unfoldings N , the routine find cover finds the unfolding set S as defined above . find cover -LRB- Q , N -RRB- S : = fg while new unfolding -LRB- Q , N -LSB- S , U -RRB- V : = refolding -LRB- U , N -RRB- S : = S -LSB- fVg return S The routine new unfolding is implemented in Carmin . It returns false if N -LSB- S is a cover of Q. Otherwise , it evaluates true , and returns a new complete unfolding as U which is not a sub-unfolding of any unfolding in N -LSB- S. -LRB- So U is a witness that N -LSB- S is not a cover . -RRB- This routine is the computational bottleneck in this approach . It is NP-hard over the size of N -LSB- S. However , for reasonably small input sizes , it runs with good average case performance . The refolding step is simple . It refolds the unfolding U as much as possible without overlapping with any of the null unfoldings in N . Evaluating each unfolded query in S and unioning the results is equivalent to evaluating the original query . It is also obvious this does not evaluate any of the join expressions of the null unfoldings . This approach 's key advantage is that S can be guaranteed to be minimal . The disadvantage is that if N is large , the algorithm will tend towards intractable . This can also happen if the minimal S deduced is inherently large -LRB- although there are reasons to believe that this does not happen , in average case , unless N is large . -RRB- A second disadvantage , perhaps , is that every null unfolding is \ removed '' , regardless of whether that truly yields a worthwhile optimization . This method does not allow for potential savings to be estimated , to decide which null unfoldings to attend and which to ignore , in conjunction with the query rewrite and 8We do not discuss the costs of deducing N in this paper . evaluation . Next , we consider an alternate , dynamic approach which integrates estimations , rewriting , and evaluation . 5.2 A Dynamic Iterative Algorithm We have assumed so far that the null unfoldings of a query are given as input and are to be removed . This is an acceptable strategy if the number of null unfoldings is small -LRB- hence the degree of query fragmentation will be small -RRB- . Contemporary databases , however , often contain too many integrity constraints , resulting in too many null unfoldings for a given query , to make the use of all of them for optimization feasible .9 We could focus instead on a small subset of the null unfoldings for the given query . We would like this subset of unfoldings to be optimal , in the sense that it contains only unfoldings that yield large savings in the query 's evaluation -LRB- and leaves out ones resulting in only insignificant savings -RRB- . As we demonstrated earlier , the savings can be measured via the sizes of the tables involved in a given null unfolding . Then only those unfoldings that \ save '' the most in that sense are selected . We propose a dynamic algorithm to rewrite the query during the evaluation , removing null unfoldings iteratively throughout the evaluation . The idea of this approach is to proceed with the evaluation in stages . Each stage proceeds until enough tables have been materialized so that there is enough information to estimate the savings that would be achieved by removing a given null unfolding . If the estimated savings are greater than some fixed threshold , the query is rewritten and the evaluation proceeds until the next checkpoint . Otherwise , that unfolding is not removed , and the query evaluation proceeds as normal . The downside of this type of dynamic optimization is a non-optimal query fragmentation . Since we do not know in advance which null unfoldings are to be removed , we can not predict what the best query rewriting at any given checkpoint will be . Point 1 Query fragmentation of Section 4 illustrates this problem . We assume for this algorithm that the set of null unfoldings N for a given query Q with a query tree T is ordered .10 We also assume that we are given some threshold value , say h -LRB- for example based on experiments -RRB- which indicates how big the tables to be joined ought to be to justify the optimization step . remove unfolding -LRB- T , N -RRB- is a simple algorithm described informally in Example 6 that given a query tree and a null unfolding unfolds the query , removes that unfolding , and refolds back the query to its compact form . 9Besides the set of integrity constraints given by the database administrator one can also use for optimization the so-called propagated integrity constraints -LSB- 10 -RSB- as well as dynamic integrity constraints -LSB- 18 -RSB- . 10Informally , N1 is before N2 in a sequence of ordered unfoldings if all atoms of N1 are below atoms of N2 in the query tree . A formal definition of the ordering and a discussion of a possibility of such ordering is beyond the scope of this paper . We assume that all nice unfoldings have been removed prior to running this algorithm . evaluate optimize -LRB- T ; N -RRB- If N = ; Materialize all nodes of T , return Root -LRB- T -RRB- -LSB- evaluated query -RSB- Else Let N = N1 ; : : : ; Nn Let N1 = N11 ; : : : ; Nn1 Materialize all subtrees rooted at N11 ; : : : ; Nn1 If Size -LRB- N11 -RRB- ? : : : ? Size -LRB- Nn1 -RRB- > h T : = remove unfolding -LRB- T ; N1 -RRB- N : = N ? N1 evaluate optimize -LRB- T ; N -RRB- 6 Summary and Future Work We discussed in this paper semantic query optimization for bottom-up query evaluation strategies . We presented the goal of such an optimization , analyzed its cost , and proposed two algorithms . Our optimization techniques are general enough so that they can be implemented with any particular bottom-up query evaluation method . We believe that the bottom-up evaluation strategy will be a method of choice in future deductive and heterogenous database systems . Such databases tend to have a large number of integrity constraints which could be used to constrain the search space for answers by means of semantic optimization . We plan to extend this work in two directions . First , algorithms for other types of semantic optimization -LRB- such as restriction elimination or restriction introduction -RRB- should be developed and tested . Second , the algorithms for join elimination presented here should be generalized to work for databases with resursion and negation -LRB- in queries , rules and ICs -RRB- . We intend to implement the algorithms on the testbed provided by the Carmin system -LSB- 4 , 5 -RSB- . We plan to experiment with large databases to determine the conditions under which these algorithms perform well , and when to use one method over another . References -LSB- 1 -RSB- U. Chakravarthy , J. Grant , and J. Minker . Logic-based approach to semantic query optimization . ACM Transactions on Database Systems , 15 -LRB- 2 -RRB- :162 -LCB- 207 , June 1990 . -LSB- 2 -RSB- T. Gaasterland and J. Lobo . Processing negation and disjunction in logic programs through integrity constraints . Journal of Intelligent Information Systems , 2 -LRB- 3 -RRB- , 1993 . -LSB- 3 -RSB- Terry Gaasterland , Parke Godfrey , and Jack Minker . An overview of cooperative answering . Journal of Intelligent Information Systems , 1 -LRB- 2 -RRB- :123 -LCB- 157 , 1992 . Invited paper . -LSB- 4 -RSB- Parke Godfrey . An Architecture and Implementation for a Cooperative Database System . PhD thesis , University of Maryland , Dept. of Computer Science , University of Maryland , College Park , MD 20742 , USA , December 1995 . -LSB- 5 -RSB- Parke Godfrey , Jack Minker , and Lev Novik . An architecture for a cooperative database system . In Witold Litwin and Tore Risch , editors , Proceedings of the First International Conference on Applications of Databases , Lecture Notes in Computer Science 819 , pages 3 -LCB- 24 . Springer Verlag , Vadstena , Sweden , June 1994 . -LSB- 6 -RSB- J. Grant and J. Minker . On optimizing the evaluation of a set of expressions . International Journal of Computer and Information Sciences , 11:179 -LCB- 191 , 1982 . -LSB- 7 -RSB- L.J. Henschen and S.A. Naqvi . On compiling queries in recursive first-order databases . J.ACM , 31 -LRB- 1 -RRB- :47 -LCB- 85 , January 1984 . -LSB- 8 -RSB- J.J. King . Quist : A system for semantic query optimization in relational databases . Proc . 7th International Conference on Very Large Data Bases , pages 510 -LCB- 517 , September 1981 . -LSB- 9 -RSB- Laks V. S. Lakshmanan and R. Missaoui . On semantic query optimization in deductive databases . In Proc . IEEE International Conference on Data Engineering , pages 368 -LCB- 375 , 1992 . -LSB- 10 -RSB- S. Lee and J. Han . Semantic query optimization in resursive databases . In Proc . IEEE International Conference on Data Engineering , pages 444 -LCB- 451 , 1988 . -LSB- 11 -RSB- S. Lee , L.J.Henschen , and G.Z. Qadah . Semantic query reformulation in deductive databases . In Proc . IEEE International Conference on Data Engineering , pages 232 -LCB- 239 , Los Amitos , CA , 1991 . IEEE Computer Society Press . -LSB- 12 -RSB- A.Y. Levy and Y. Sagiv . Semantic query optimization in datalog programs . In Proc . PODS , 1995 . -LSB- 13 -RSB- Raghu Ramakrishnan , Per Bothner , Devesh Srivastava , and S. Sudarshan . CORAL -LCB- A database programming language . Technical Report TR-CS-90-14 , Dept. of Computing and Information Sciences , Kansas State University , 1990 . Also in NACLP90 Workshop on Deductive Databases , ed Jan Chomicki . -LSB- 14 -RSB- K. Ramamohanarao . An implementation overview of the aditi deductive database system . In Proc . 3rd International Conference DOOD , Arizona , 1993 . -LRB- Invited Talk -RRB- . -LSB- 15 -RSB- T. Sellis . Global query optimization . Proc . 1986 ACM-SIGMOD International Conference on Management of Data , May 1986 . -LSB- 16 -RSB- S.T. Shenoy and Z.M. Ozsoyoglu . Design and implementation of a semantic query optimizer . IEEE Transactions on Knowledge and Data Engineering , 1 -LRB- 3 -RRB- :344 -LCB- 361 , September 1989 . -LSB- 17 -RSB- J. D. Ullman . Principles of Database and Knowledge-Base Systems II . Principles of Computer Science Series . Computer Science Press , Rockville , Maryland 20850 , 1988 . -LSB- 18 -RSB- Clement T. Yu and Wei Su . Automatic knowledge acquisition and maintenance for semantic query optimization . IEEE Transactions on Knowledge and Data Engineering , 1 -LRB- 3 -RRB- :362 -LCB- 375 , September 1989 .

B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O

databases
intelligent information systems
semantic query optimization


NPkVt ? c NPSVt If Disjoint Pairs of Co-NP Sets are P ? seperable James A. Fostera Steven Fennerb email : foster@cs.uidaho.edu, fenner@sleepy.usmcs.maine.edu Technical Report No . LAL 95-01 aLaboratory for Applied Logic , Dept. of Computer Science , U. Idaho bUniversity of Southern Maine Abstract We show that the assumption that all disjoint co-NP sets are P ? seperable implies that every multivalued NP function with at most a constant sized image for any input can be consistently refined to a single-value NP function . Department of Computer Science University of Idaho Moscow , ID 83843 Phone : -LRB-208-RRB- 885-6589 1 INTRODUCTION 2 1 Introduction It is an open question , raised by Fenner et al. -LSB- FHOS93 -RSB- and Selman -LSB- Sel94 -RSB- , whether there exists a single-valued NP function which returns a satisfying assignment for every boolean formula in SAT . This is a relaxed version of the old , old question of whether there exists a deterministic polynomial time solution for SAT . It is also an extension of Valiant and Vazirani 's -LSB- VV86 -RSB- celebrated result that \ NP is as easy as detecting unique solutions '' | work which lead to to Toda 's equally famous result -LSB- Tod91 -RSB- that PH ? PPP . This hypothesis is true under the assumption that NP = co-NP . However , Royer -LSB- Roy93 -RSB- has shown that it is false relative to a random oracle . Selman -LSB- Sel94 -RSB- has further evidence that it is false . Hemispaandra et al. -LSB- HNOS93 -RSB- provide even stronger evidence that this hypothesis is false by showing that the existence of a single-valued NP function giving a satisfying assignment for every formula in SAT implies that the polynomial hierarchy collapses to the second level . The existence of NP algorithms to guide selection of satisfying assignments is related to one raised by Fortnow and Rogers -LSB- FR93 -RSB- : Is there a single-valued NP function which selects an accepting path on any input for any NP machine which accepts ??? These questions are also related to the complexity of inverting honest functions , since multivalued NP inverses are certainly possible , and P inverses exist if and only if P = NP -LRB- see Selman -LSB- Sel94 -RSB- for a discussion -RRB- . This connection relates these problems to the existence of one-way function , as well . We investigate a slightly weaker question : does every total multi-valued NP function with at most a constant number of distinct values in its range have a consistent , total , single valued NP refinement ? We present a positive answer to this question under the assumption that all disjoint pairs of co-NP sets are P ? seperable . This is a fairly strong assumption , since it implies that P = NP \ co-NP . However , Fortnow and Rogers -LSB- FR93 -RSB- demonstrate an oracle under which disjoint co-NP sets are P ? seperable but P < > NP . 2 TERMINOLOGY 3 2 Terminology We will often refer to the following assumption : Q0 = every disjoint pair of co-NP sets is P ? seperable -LRB- 1 -RRB- Two sets A and B are P ? seperable via separator S when , for all x , x 2 A implies that x 2 S and x 2 B implies that x 2 S . We will use the following classes of functions : Definition 1 For multivalued function f , computable on a nondeterministic Turing machine in polynomial time ffl NPSVt = ff : 8x ; jf : xj = 1g ffl NPkVt = ff : 8x ; 1 < = jf : xj < = kg for some k ffl NPPVtff : 8x ; 1 < = jf : xj < = p : jxjg for some polynomial p -LRB- Selman -LSB- Sel94 -RSB- calls this class FewPF -RRB- We also say , for two classes of functions A and B that the latter is a consistent refinement of the former , denoted A ? c B , when for any function f 2 A there is a function g 2 B such that the domain of g is the same as the domain of f and g : x ? f : x for all x. Note in particular that A ? B implies that A ? c B -LRB- hence the direction of the symbol -RRB- . We denote the catenation of x and y by x ? y . We denote the application of a function f to an argument x as f : x . In particular , the functions MIN : S and MAX : S return the minimum and maximum elements , respectively , in a set S of strings , under lexicographic ordering . We also denote the collection of strings from n to m , in lexicographic order , as -LRB- n : : m -RRB- when m and n are excluded and as -LSB- n : : m -RSB- when they are included . All ordering relations between strings are lexicographic . For example , z < = c means that z lexicographically precedes c . We denote bits i through j of a binary string oe by oe -LSB- i : : j -RSB- and assume that all strings are 3 RESULTS 4 binary , that is ? = f0 ; 1g . Finally , hx ; yi denotes a polynomial time computable and invertible bijection between pairs of binary strings and binary strings . 3 Results The results in this section depend on a binary search of strings in some range . We will refer to the nth binary string in lexicographic ordering as oe -LRB- n -RRB- , and we use rank -LRB- x -RRB- = n to denote the fact that x = ? -LRB- n -RRB- for any binary string x. Consider the following algorithm : Function BinSearch : x : y :P returns a binary string f x and y are binary strings with rank -LRB- x -RRB- < = rank -LRB- y -RRB- P is a binary predicate on binary strings g If x = y Then Return x Else mid drank -LRB- y -RRB- ? rank -LRB- x -RRB- = 2e If P.mid Then Return BinSearch : mid : y :P Else Return BinSearch : x : mid :P This is a typical binary search , and so it converges to some string determined by its input parameters . For example , in Theorem 2 we used BinSearch :0:1 p : jxj : UP , where p was the polynomial bounding the runtime of the original NP function and UP was the predicate defined via the co-NP separator . The following general result will be of interest : Lemma 1 Suppose that UP is a predicate on binary strings , and that A is a set of binary strings such that there are a ; b 2 A where UP is true for all strings in -LSB- Min : A : : a -RRB- and UP is false for all strings in -LRB- b : : Max : A -RSB- . Furthermore , let C = BinSearch : x : y : UP for binary strings x = Min : A and 3 RESULTS 5 y = Max : A . Then C 2 -LRB- a : : b -RSB- . Proof : The proof is by a simple induction on the lengths of the left and right regions of A above . If C is in any subset of the left region , then it must be the rightmost element . By induction , this implies that C = y , and so a = b and the algorithm will converge to a = b = C . A similar argument holds for subsets of the right-hand region . 2 One consequence of this observation is that if jf : xj = 1 , and one uses an appropriate binary search through f : x , then C = f : x. Fortnow 's construction in Theorem 2 works by using the convergent string C to detect the presence of a second element in f : x by detecting when this equality is violated . Fenner 's construction in Lemma 3 works by using the fact that the set fy : y < Cg is non-empty precisely when jf : xj > 1 , and that in this case jfy : y < Cgj < jf : xj . This is used implicitly in the following theorem , due to Lance Fortnow -LSB- For93 -RSB- : Theorem 2 -LRB- Fortnow -RRB- Q0 implies NP2Vt ? c NPSVt . Proof : Let f be some function in NP2Vt with runtime p. Consider the following two sets : L0 = fhx ; yi : 9z > = y ; z 2 f : xg L1 = fhx ; yi : 9z < y ; z 2 f : xg Clearly L0 and L1 are in NP and their union is ?? . So , their complements L0 and L1 are in co-NP and are disjoint . By assumption , then , they are P ? seperable . Let S P-separate L0 and L1 . Now , define the following predicate : DOWN : x : y ? hx ; yi 2 A 3 RESULTS 6 Now , consider > = y : DOWN : x : y DOWN : x : y = TRUE ? hx ; yi 2 S -RRB- hx ; yi 62 L1 -RRB- hx ; yi 2 L1 This in turn means that there is some z which precedes y such that z 2 f : x , so any algorithm looking for such a value should look down when DOWN : x : y is true . Similarly , when DOWN : x : y is false , there is a value z in f : x such that z follows y , so any search algorithm should look up . Intuitively , the DOWN predicate says \ if you 're looking for something in f : x , look below y '' . Now , we present a single-valued NP refinement of f . Function g Input x Nondeterministically select z0 2 f : x C BinSearch :0:1 p : jxj : DOWNa Let y be the least value such that DOWN : x : y ? -LRB- y < z0 -RRB- f say y `` disagrees with z0 '' g If DOWN : x : y Then nondeterministically guess a value z1 2 -LSB- 0 : : y -RSB- Verify z1 2 f : x and RETURN z1 Else RETURN z0 aThe original algorithm had If this converges to a v 2 f : x Then RETURN v , but on some nondeterministic paths , a v0 2 f : x may not be recognized due to the accepting computation not being nondeterministically chosen . This would defeat the single-valuedness of the construction by going into the rest of the algorithm . I deleted this line , as it was not needed . Clearly , if jf : xj = 1 then L0 -LSB- L1 = ?? and so DOWN : x : y -LRB- -RRB- f : x < y. consequently , this algorithm will converge to that single value . 3 RESULTS 7 Suppose that jf : xj = 2 , the only other possibility . Since the sequence of ys for which DOWN : x : y is evaluated , and consequently the value to which the binary search converges , is independent of any nondeterministic choices the algorithm makes . Clearly , C < > z0 iff some y disagrees with z0 . But such a disagreement indicates whether the other value of f : x is greater than or less than z0 . The algorithm returns z0 if the search converges to it , and MIN : f : x otherwise . This is clearly an NP algorithm which returns a single value in f : x , consistently returning the same value regardless of the nondeterministic choices . Consequently , it computes an NPSVt refinement of f . 2 A natural question to ask at this point would be whether Q0 implies that a richer NP function set than NP2Vt can be extended consistently to single-valued functions . Fenner -LSB- Fen93 -RSB- has proven the following very useful lemma Lemma 3 -LRB- Fenner -RRB- For any k , NPkVt ? c NP -LRB- k-1 -RRB- Vt. . Proof : The idea of the proof is to fix a particular string via a binary search using the partial ordering induced by a P ? seperator . This string is independent of nondeterministic choices . It will be used to divide the range of f into two non-empty sets whenever there are at least two elements in the range of f , and values in the refinement will be selected from only one of these sets . Suppose f 2 NPkVt . Let LDOWN = fhx ; yi : 9z < y ; z 2 f : xg LUP = fhx ; yi : 9z > = y ; z 2 f : xg 3 RESULTS 8 Both are in NP and union to ?? , so their complements are co-NP and disjoint . So , by assumption , there is a predicate UP 2 P which separates the complements of these sets such that So , for all x , y , UP : x : y = TRUE -RRB- hx ; yi 2 LUP UP : x : y = FALSE -RRB- hx ; yi 2 LDOWN As we have seen , the UP predicate can be used to do something like a binary search . We describe a total refinement g of f that outputs at most k ? 1 values . Suppose that f is computed by a nondeterministic machine M which runs in time p -LRB- jxj -RRB- . On input x , the function g is computed by the following NTM : Function g C BinSearch :0:1 p : jxj : UP Nondeterministically select z 2 f : x such that z < = C S fzg While -LRB- x 2 S -RRB- x < C -RRB- Do Nondeterministically selects z 2 f : x such that z 62 S S S -LSB- fzg If MAX : S = C Then RETURN C Else RETURN MIN : S The only critical case is when f : x outputs exactly k values , in which case there must be one value of f : x that this algorithm avoids regardless of nondeterministic choices . There are two cases : -LRB- Case 1 -RRB- If C = MAX : f : x , then this algorithm returns only C and so is single valued . -LRB- Case 2 -RRB- Otherwise , there is some element in f : x which is greater 4 CONCLUSIONS 9 than or equal to C. But , MAX : fz : z > C ; z 2 f : xg will never be returned by this algorithm . So , this is an NP algorithm for a refinement of f with at most -LRB- k ? 1 -RRB- values , as claimed . 2 This Lemma yields Theorem 4 If Q0 holds , then NPkVt ? c NPSVt for any k. 4 Conclusions This paper presents evidence that a great many of the multi-valued NP functions do have consistent single-valued refinements under the assumption that all pairs of disjoint pairs of co-NP sets are P ? seperable . This is still a fairly strong assumption , since it implies that P = NP \ co-NP and that PH collapses . However , there is an oracle relative to which Q0 holds , but P < > NP , as Fortnow and Rogers have shown -LSB- FR93 -RSB- so that it does not imply that PH collapses completely -LRB- so far as we know -RRB- . Selman -LSB- Sel94 -RSB- has also shown that NPMVt ? c NPSVg -LRB- for total multivalued functions and single valued functions with polynomial time decidable graphs -RRB- if and only if P = NP . He has also shown that NPPV ? c NPSVg -LRB- where the single valued functions have polynomial time decidable graphs , and none are required to be total -RRB- if and only if P = NP . These results were not for total functions , so we need to consider how they relate to the current results . However , they do place limits on the extent to which nondeterministic functions can be refined , pending a resolution of the P versus NP problem . There are several interesting open questions , though . For example , the original questions about single-valued NP refinements of multi-valued NP functions remains . Also , let Q be the assumption that all disjoint pairs of 5 ACKNOWLEDGMENT 10 NP sets are P ? seperable . It would be interesting to know whether similar results can be obtained under Q. Moreover , the exact relation between Q and Q0 is unknown . 5 Acknowledgment This work clearly owes a great debt to Lance Fortnow , Ken Regan , and Steve Mahaney . It grew out of fascinating discussions during the International Workshop on Computational Complexity in Portland , Maine , sponsored in part by the University of Maine at Portland , and on various airplanes . References -LSB- Fen93 -RSB- Steven Fenner . Personal communications . August 1993 . -LSB- FHOS93 -RSB- Steven Fenner , Steven Homer , M. Ogiwara , and Alan Selman . On using oracles that compute values . In Proc . 10th Symp . on Theoretical Aspects of Computer Science , volume 665 of Lecture Notes in Computer Science , pages 398 -LCB- 407 . Springer-Verlag , February 1993 . -LSB- For93 -RSB- Lance Fortnow . Personal communications . August 1993 . -LSB- FR93 -RSB- Lance Fortnow and John Rogers . Separability and one-way functions . Technical Report CS 93-14 , University of Chicago , August 1993 . -LSB- HNOS93 -RSB- Lane A. Hemaspaandra , Ashish V. Naik , Mitsunori Ogiwara , and Alan L. Selman . Computing solutions uniquely collapses the polynomial hierarchy . Manuscript , August 1993 . -LSB- Roy93 -RSB- J. Royer . Personal communications . August 1993 . -LSB- Sel94 -RSB- Alan Selman . A taxonomy of complexity classes of functions . J. of Computer and Systems Sciences , -LRB- 48 -RRB- :357 -LCB- 381 , 1994 . -LSB- Tod91 -RSB- S. Toda . PP is as hard as the polynomial-time hierarchy . SIAM Journal on Computing , 5:865 -LCB- 877 , 1991 . REFERENCES 11 -LSB- VV86 -RSB- L. Valiant and V. Vazirani . NP is as easy as detecting unique solutions . Theoretical Computer Science , 47:85 -LCB- 93 , 1986 .

O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O