Information Systems 58 (2016) 1–13
Contents lists available at ScienceDirect
Information Systems journal homepage: www.elsevier.com/locate/infosys
Containment for queries over trees with attribute value comparisons$ Maarten Marx, Evgeny Sherkhonov n University of Amsterdam, Science Park 904, 1098XH Amsterdam, Netherlands
a r t i c l e i n f o
abstract
Article history: Received 22 January 2015 Received in revised form 23 October 2015 Accepted 26 November 2015 Available online 5 December 2015
Björklund et al. [6] showed that containment for conjunctive queries (CQ) over trees and positive XPath is respectively Π P2 and coNP-complete. In this article we show that the same problem has the same complexity when we expand these languages with XPath's attribute value comparisons. We show that different restrictions on the domain of attribute values (finite, infinite, dense, discrete) have no impact on the complexity. Making attributes required does have an impact: the problem becomes harder. We also show that containment of tree patterns without the wildcard , which is in PTIME, becomes coNPhard when adding equality and inequality comparisons. & 2015 Elsevier Ltd. All rights reserved.
Keywords: Tree query languages Conjunctive queries over trees Positive XPath Containment Attribute
1. Introduction In this article we study the containment problem for positive XPath (PosXPath) and conjunctive queries (CQ) interpreted over finite unranked ordered trees with respect to the axes Child; NextSibling, Descendant, NextSibling þ and Following. PosXPath is a large fragment of Core XPath [14] which contains all the axes and constructs except negation. Conjunctive queries over trees are an analog of relational conjunctive queries, which correspond to the select-from-where SQL queries in which the where-condition uses only conjunctions of equality comparisons, and are the most widely used query language in practice. A thorough study of the containment problem for CQ over trees has been done in [6]. Their main result is ☆ An extended abstract announcing some of the results of this paper was presented at the 16th International Workshop on the Web and Databases (WebDB), New York, June 23, 2013. n Corresponding to: POSTBUS 94323, 1090 GH, Amsterdam, The Netherlands. Tel.: þ 31 205258627. E-mail addresses:
[email protected] (M. Marx),
[email protected] (E. Sherkhonov).
http://dx.doi.org/10.1016/j.is.2015.11.003 0306-4379/& 2015 Elsevier Ltd. All rights reserved.
Π P2 -completeness of the problem. In fact, conjunctive queries can be reformulated as the positive fragment of Core XPath with path intersection. Thus, the Π P2 hardness result also holds for the containment problem for this fragment. Inspection of the proof in [6] also indicates that the containment for just PosXPath remains in CONP. This extends the result of Miklau and Suciu [19], who showed that containment for tree patterns is CONP-complete. The query language considered in these previous results ignores attributes. However, in many practical scenarios we deal with data that come from numeric domains, such as real or natural numbers. Thus, it is natural to consider conjunctive queries expanded with attribute value comparisons and study basic static analysis problems such as satisfiability and containment. Such an expansion has been considered for Tree Patterns in [1], where a Π P2 -completeness result for the containment has been established. However, the hardness proof relies on the construct that allows comparisons of attributes of two different nodes, a feature that is not expressible in Core XPath. As a positive counterpart, a CONP upper bound for containment was shown in the case when comparisons are restricted to either so-called left semi-interval or right
2
M. Marx, E. Sherkhonov / Information Systems 58 (2016) 1–13
semi-interval attribute constraints. For an attribute a and constant c, an attribute constraint (@a opc) is left semiinterval if op A f o; r; ¼ g. This article is an extension of [23], where it was shown that the complexity of containment does not increase for tree patterns expanded with both left and right semiintervals constraints together with inequality constraint. Here we show that essentially the complexity does not change in cases of positive XPath and conjunctive queries over trees. Furthermore, the same upper bounds hold for the cases when we make certain assumptions on the underlying attribute domain D. That is, we show that all the complexity results still hold for the cases when D is a dense or discrete infinite linear order, with or without endpoints, or a finite linear order. As another result, we show that by requiring at least one attribute to be defined in every node of a tree, the complexity of containment over such trees rises to PSPACE. If, on the other hand, we require attributes to be defined only at nodes with a certain label (which can be expressed in DTDs) the complexity remains in CONP. All the upper bound results for both PosXPath and CQ are obtained from a suitable polynomial reduction to the s s containment problem in PosXPath: and UCQ: (PosXPath and CQ expanded with safe label negation and union) over trees in which nodes may have multiple labels, respectively. Safe label negation is the construct p⧹fq1 ; …; qn g which denotes p-labelled nodes that are not labelled with any of thelabels q1 ; …; qn . Table 1 summarizes our results. The paper is organized as follows. In Section 2 we briefly mention related work. Section 3 contains all the necessary preliminary notions. Section 4 contains the main results. In particular, in Section 4.1 we show that cons s tainment for UCQ: and PosXPath: is in Π P2 and CONP respectively. Next in Section 4.2 we consider containment for CQ@ and PosXPath@ and show the same upper bounds by reducing to the previous problem. Then in Section 4.3 we show that the upper bounds of containment do not change in case of some natural restrictions on the attribute domain. Section 4.4 contains lower bounds: containment of tree patterns without wildcard rises from PTIME to CONP when we add equality and inequality comparisons; containment of tree patterns rises from CONP to PSPACE when we add equality and inequality comparisons and interpret them on trees in which at least one attribute is defined at each node (a so-called required attribute). We finish with conclusions and future work.
Table 1 Complexity results for containment of Positive XPath and CQ with attribute value comparisons. PosXPath@
CQ@
No attributes
CONP
[6]
Π P2 [6]
Optional attributes
CONP
(Theorem 2)
Required attributes
PSPACE-hard (Theorem 3)
Π P2 (Theorem 2) PSPACE-hard (Theorem 3)
2. Related work Containment of Conjunctive Queries (CQ) with arithmetic comparisons. The classical result on containment of conjunctive queries over relational databases is its NP-completeness [7]. Later, containment for conjunctive queries expanded with arithmetics comparisons was shown to be Π P2 -complete [17,26]. In [2], Afrati et al. consider various restrictions on type of comparison operations on either of the two input conjunctive queries with comparisons, as well as on interaction between the comparisons, so that the containment is in NP (cf. Table 1 in [2]). However, it was left open what the exact complexity of containment for CQ with comparisons of type Xopc is, where c is a constant and op A f ¼ ; a; r; Z; o; 4 g, i.e., the type of comparisons that we consider in this paper. Note that the Π P2 -lower bound proof in [26] uses disequation of variables, i.e., the construct X aY for variables X and Y. Nevertheless, adding comparisons of the form Xopc to conjunctive queries does change the complexity of containment, which is in contrast with the result of the current paper for PosXPath and CQ over trees. This is argued in [13], where Π P2 -hardness of containment for CQ with comparisons was shown, using comparisons of the form X ac. This proof can also be adapted to use comparisons of the form both X r c and X 4 c [21]. Relational conjunctive queries with negated atoms were also studied previously. It is known that containment for CQ with negated atoms is Π P2 -complete [25]. The analog of safe negation that we consider here was also considered in the context of relational CQ [27]. In this case, negation in a conjunctive query is safe if every variable appearing in a negated atom also occurs in a positive atom of the query. Interestingly, the lower bound proof from [13] can be adapted to show Π P2 -hardness of CQ with safe negation [21]. Thus, adding safe negation to relational conjunctive queries does change the complexity of containment (from NP to Π P2 ), which is in contrast with the result of the current paper where safe negation does not change the complexity of containment for queries over trees. Containment for queries interpreted over trees. The containment problem for various XPath fragments has been a topic of wide interest for the past several years. A polynomial time algorithm for tree patterns without the wildcard based on homomorphism between queries was given in [3]. The main result of Miklau and Suciu [19] is the CONP-completeness of containment of tree patterns with the wildcard. Almost a complete picture of the containment problem for the XPath fragments with disjunction, in the presence of DTDs and variables was given in [20]. Notably, it was shown that with a finite alphabet the containment problem rises to PSPACE. [28] gives decidability results for various fragments with DTDs and a class of integrity constraints. XPath containment in the presence of dependency constraints was studied in [10,11]. All these complexity results are given for forward fragments of XPath. In this paper we consider all the backward axes (parent and ancestor) together with the document order axis (next sibling, following sibling, and following axes and their inverses). Note that in [22] it was shown that every
M. Marx, E. Sherkhonov / Information Systems 58 (2016) 1–13
XPath expression has an equivalent expression without backward axes. However, this translation may result in an expression of exponential size. A closely related problem is XPath satisfiability [16,4]. [4] contains almost a complete picture of the satisfiability problem with or without the presence of constraints for various fragments of XPath. Query containment reduces to XPath satisfiability in fragments with enough expressive power (e.g., with negation and filter expressions). Recently the containment of Boolean combinations of tree patterns interpreted over data trees was studied in [9], where Π P2 -completeness was shown. Their results are incomparable with our results since tree patterns used in [9] output a tuple of data values of nodes, while our tree patterns output nodes. A closely related work is by Afrati et al. [1]. Consider the containment problem for tree patterns with general arithmetic comparisons. They add the ability to compare the value of an attribute in two different nodes (note that this is not expressible in Core XPath) and show that containment for this fragment is Π P2 -complete. As mentioned in the introduction, we extend their CONP result for tree patterns with attribute value comparisons. A systematic study of conjunctive queries interpreted over trees started in [15], where the central problem was the evaluation problem. The authors established a PTIME and NP dichotomy of the problem. The containment problem for this language was considered in [6], where it was shown to be Π P2 -complete. The Π P2 upper bound was shown via the small counterexample property, similar to the one in [19]. On the other hand, the Π P2 lower bound proof heavily relies on the DAG structure of conjunctive queries. In fact, if one disallows path intersections and allows disjunction, the same “small counterexample” technique will yield a CONP algorithm. Since XPath expressions with backward axes can be expressed in this language, this implies the CONP upper bound for positive XPath. Containment of conjunctive queries under schema constraints was studied in [5], where 2EXPTIME-completeness of the problem was established. We end with some results on tractable (PTIME) containment. As mentioned above, [3] provides a PTIME algorithm for containment of tree patterns without the wildcard. PTIME containment for acyclic conjunctive queries implies tractability for containment of tree patterns without descendant. Moreover, containment for tree patterns without filters is in PTIME as well [19]. However adding attribute value comparisons may raise the complexity. For instance, as shown below in Proposition 5, containment for tree patterns without the wildcard together with equality and inequality attribute comparisons is CONP-hard. As for conjunctive queries interpreted over trees, very limited fragments have PTIME containment: those that use one of Child or NextSibling relation only [6].
3. Preliminaries We work with node-labelled ordered unranked finite trees, where the nodes are labeled by finite subsets of the infinite set of labels Σ. Formally, a tree over Σ is a tuple
3
ðN; E; o ; r; ρÞ, where N, the set of nodes of the tree, is a prefix closed set of finite sequences of natural numbers, E ¼ fð〈n1 ; …; nk 〉; 〈n1 ; …; nk ; nk þ 1 〉Þj〈n1 ; …; nk þ 1 〉 A Ng is the child relation, the sibling relation o is defined as fð〈n1 ; …; nk 〉; 〈n1 ; …; nk þ 1〉Þj〈n1 ; …; nk 〉; 〈n1 ; …; nk þ1〉 A Ng, r ¼ 〈〉 is the root of the tree, and ρ is the function assigning to each node in N a finite subset of Σ. If for every node n of a tree ρðnÞ is singleton, we call such a tree as a singlelabeled tree. Otherwise, it is multi-labeled. A pointed tree is a pair T; n, where n is a node in T. Let A be a set of attribute names and ðD; o Þ a dense linear order without endpoints. Then a tree with attributes from A over Σ is a tuple ðN; E; o; r; ρ; attÞ such that ðN; E; o ; r; ρÞ is a tree over Σ and att: N A-D is a partial function. By E þ and o þ we denote the descendant and the following sibling relations which are transitive closures of the child and sibling relations respectively. We will also use o f for the following relation, i.e., the abbreviation for ðE 1 Þ ○ o þ ○E . For x; y A N and R A fE; E þ ; o ; o þ ; o f g, by T F xRy we denote the fact that ðx; yÞ A R. Positive XPath with attribute value comparisons. We define the syntax of Positive XPath (denoted as PosXPath@ ) node and path formulas with attribute value comparisons with the following grammar. step: ≔↓j↑j’j-; φ: ≔pj >j@a opcjφ 4 φjφ 3 φj〈α〉φ; α: ≔stepj?φjα; αjα [ αjstep þ j-f j’p ; where p A Σ; a A A, op A f r ; Z ; o; 4; ¼ ; a g, and c A D. The semantics of PosXPath@ path formulas α and node formulas φ is defined as follows. Let T ¼ ðN; E; o ; r; ρ; attÞ be a tree over Σ with attribute names from A. In a mutual induction we define the relation ½½αT D N N and the satisfaction relation T; n F φ.
½½↓T ¼ E, ½½↑T ¼ E 1 , ½½-T ¼ o , ½½’T ¼ o 1 , ½½-f T ¼ o f , ½½’p T ¼ ð o f Þ 1 , ½½?φT ¼ fðn; nÞ A N Nj T; n F φg, ½½α; βT ¼ ½½αT ○½½βT , ½½α [ βT ¼ ½½αT [ ½½βT , ½½α þ T ¼ ð½½αT Þ þ for α A f↓; ↑; -; ’g,
and
T; n F >, T; n F p iff p A ρðnÞ, T; n F @a opc iff ðD; oÞ F attðn; aÞ op c, T; n F φ 4 ψ iff T; n F φ and T; n F ψ, T; n F φ 3 ψ iff T; n F φ or T; n F ψ, T; n F 〈α〉φ iff there is a node m with ðn; mÞ A ½½αT and T; m F φ.
The step axes select a pair of nodes that are in the child, parent, next-sibling or previous-sibling relations in the tree. Furthermore, the -f and ’p axes select nodes that
4
M. Marx, E. Sherkhonov / Information Systems 58 (2016) 1–13
are in the following and the preceding relations in the tree respectively. Note that > is the same as the wildcard axis. Sometimes we will write T F φ to denote T; r F φ. Conjunctive queries with attribute value comparisons. Let Var be a set of variables, A a set of attribute names and ðD; oÞ the attribute domain, which is a dense linear order without endpoints. A conjunctive query with attribute value comparisons (CQ@ ) over Σ, A and D is a positive existential first-order formula without disjunction in prenex normal form over a set of unary predicates p(x) and @a ðxÞopc, where p A Σ, x A Var; c A D and op A f r; Z; o; 4; ¼ ; a g; and the binary predicates Child, Descendant, NextSibling, NextSibling þ and Following. If Q is a CQ@ , by Var(Q) we denote the set of variables occurring in Q. By FVar(Q) we denote the set of free variables in Q. If jFVarðQ Þj ¼ k 4 0, we call Q a k-ary conjunctive query. If jFVarðQ Þj ¼ 0, we call Q a Boolean conjunctive query. Let Q be a conjunctive query and T ¼ ðN; E; o ; r; ρ; attÞ a tree over Σ and attributes from A. A valuation of Q on T is a total function θ: VarðQ Þ-N. A valuation is a satisfaction if it satisfies the query, that is, every atom of Q is satisfied by the valuation. Satisfaction of an atom in T, given a valuation θ, is defined as follows.
T; θ F pðxÞ iff p A ρðθðxÞÞ, T; θ F @a ðxÞopc iff ðD; oÞ F attðθðxÞ; aÞ op c, T; θ F Childðx; yÞ iff T F θðxÞEθðyÞ, T; θ F Descendantðx; yÞ iff T F θðxÞE þ θðyÞ, T; θ F NextSiblingðx; yÞ iff T F θðxÞ oθðyÞ, þ T; θ F NextSibling ðx; yÞ iff T F θðxÞ o þ θðyÞ, T; θ F Followingðx; yÞ iff T F θðxÞ o f θðyÞ:
A tree T models Q, denoted as T F Q if there is a satisfaction of Q on T. If ðx1 ; …; xk Þ is the tuple of free variables in Q, then the answer of Q over T is the set answer ðQ ; TÞ ¼ fðθðx1 Þ; …; θðxk ÞÞjθ is a satisfaction of Q on Tg. Note that tuples can be nullary as well. Thus, for a Boolean query Q, answerðQ ; TÞ ¼ f〈〉g (and we say Q is true on T) if there is a satisfaction of Q on T and answerðQ ; TÞ ¼ ∅ (and we say Q is false on T) otherwise. We also consider unions of conjunctive queries with attribute value comparisons, denoted as UCQ@ . These are formulas of the form ⋁ni¼ 1 Q i , where Q i A CQ@ . The semantics of these formulas is defined in the obvious way. @ PosXPath formulas as CQ @ formulas with disjunction. Every PosXPath@ formula can be translated into an equivalent CQ@ formula with disjunction in linear time. The translation is a standard translation of XPath into firstorder logic language. It is defined by induction on the complexity of path and node formulas of PosXPath@ as follows. Note that the translation can be easily modified to yield a translation into the three variable fragment of first order logic. TRxy ð↓Þ TRxy ð↑Þ TRxy ð-Þ TRxy ð’Þ TRxy ð?φÞ TRxy ðα1 ; α2 Þ
¼ ¼ ¼ ¼ ¼ ¼
TRxy ðα1 [ α2 Þ
¼
Childðx; yÞ Childðy; xÞ NextSiblingðx; yÞ NextSiblingðy; xÞ x ¼ y 4TRx ðφÞ ( z:ðTRxz ðα1 Þ 4 TRzy ðα2 ÞÞ where z is a fresh variable. TRxy ðα1 Þ 3 TRxy ðα2 Þ
TRxy ð↓ þ Þ TRxy ð↑ þ Þ TRxy ð- þ Þ
¼ ¼ ¼
TRxy ð’ þ Þ TRxy ð-f Þ TRxy ð’p Þ TRx(p) TRx ð@a opcÞ TRx ð > Þ TRx ðφ1 4 φ2 Þ TRx ðφ1 3 φ2 Þ TRx ð〈α〉φÞ
¼ ¼ ¼ ¼ ¼ ¼ ¼ ¼ ¼
Descendantðx; yÞ Descendantðy; xÞ þ
NextSibling ðx; yÞ þ
NextSibling ðy; xÞ Followingðx; yÞ Followingðy; xÞ p(x) @a ðxÞopc > TRx ðφ1 Þ4 TRx ðφ2 Þ TRx ðφ1 Þ3 TRx ðφ2 Þ ( y:ðTRxy ðαÞ 4 TRy ðφÞÞ, where y is a fresh variable.
Query graphs and embeddings. It is convenient to consider CQ@ and PosXPath@ without path union and disjunction in the node formulas as graphs [15]. By ΣA we denote the attribute labels of the form @a opc, where a A A; c A D and op A f r ; Z; o; 4; ¼ ; a g. Definition 1 (Graph query). Let Q be a CQ@ . Then GQ ¼ ðV; E; E þ ; o; o þ ; o f ; ρ; ρatt Þ, where V is the set of nodes, RD V V for RA fE; E þ ; o; o þ ; o f g, ρ: V-2Σ , ρatt : V-2Σ A , is a graph query of Q if the following holds.
V ¼ VarðQ Þ, p A ρðxÞ iff p(x) occurs as a conjunct in Q, @a opc A ρatt ðxÞ iff @a ðxÞopc occurs as a conjunct in Q, ðx; yÞ A E iff Childðx; yÞ occurs as a conjunct in Q, ðx; yÞ A E þ iff Descendantðx; yÞ occurs as a conjunct in Q, ðx; yÞ A o iff NextSiblingðx; yÞ occurs as a conjunct in Q, þ ðx; yÞ A o þ iff NextSibling ðx; yÞ occurs as a conjunct in Q, ðx; yÞ A o f iff Followingðx; yÞ occurs as a conjunct in Q.
By Nodes(G) we denote the set of nodes V of G. We write GQ F u1 Ru2 , to specify that ðu1 ; u2 Þ A R for R A fE; E þ ; o ; o þ ; o f g. Note that for fragments without attribute value comparisons, the value of the labeling function ρatt is always the empty set. In these cases we omit ρatt in query graphs. The semantics of query graphs is given in terms of embeddings, which are essentially valuations for conjunctive queries. Definition 2 (Embedding). Let T ¼ ðN; E; o; r; ρ; attÞ be a tree over Σ with attributes from A and G ¼ ðV; E; E þ ; o ; o þ ; o f ; ρ; ρatt Þ a graph query. A function g: V-N is called an embedding of G into T if the following conditions are satisfied.
Edge preserving. For every u1 ; u2 A V, if G F u1 Ru2 then
T F gðu1 ÞRgðu2 Þ, for any of the edge relations R A fE; E þ ; o ; o þ ; o f g, Label preserving. For every u A V, ρðuÞ D ρðgðuÞÞ. Attribute comparison preserving. For every u A V, if @a opc A ρatt ðuÞ, then ðD; o Þ F attðgðuÞ; aÞ op c.
Proposition 1. Let T be a tree, Q a CQ@ query, GQ its graph query, and θ a function from NodesðGQ Þ to T. Then T; θ F Q iff θ is an embedding of GQ into T: Containment. Let Q and P be two k-ary conjunctive queries. We say that P is contained in Q, denoted as P D Q , if for every single-labeled tree T, it holds that
M. Marx, E. Sherkhonov / Information Systems 58 (2016) 1–13
answerðP; TÞ D answerðQ ; TÞ. We also say that P is contained in Q over multi-labeled trees and denote it by P D ML Q if answerðP; TÞ D answerðQ ; TÞ for every multi-labeled tree T. In this paper, the central problem is the following decision problem.
Given two conjunctive queries P and Q, Decide: is P DQ ? As pointed out in [6], the containment of k-ary queries can be PTIME reduced to the containment of Boolean conjunctive queries, i.e., queries without free variables. The same reduction works for positive XPath and for containment over multi-labeled trees. Thus, in the remainder of this paper we concentrate on Boolean query contai nment only. Removing the attribute value comparisons. In our upper bound proofs we will treat the attribute value comparisons as ordinary labels, whose interpretation will be restricted by adding constraints. We make that precise ~ c to a new using the translation ð~ Þ which maps each @a op label p@a op c . This tranlation can then be homomorphically extended to the translation ð~ Þ from formulas in PosXPath@ and CQ@ over Σ; A and D to formulas without attribute value comparisons in respectively PosXPath and CQ over the alphabet Σ [ fp@a op c jop A f ¼ ; a ; o ; 4; r; Zg; a A A; c A Dg. PosXPath and CQ with safe negation We define an expansion of the languages PosXPath@ and CQ@ (UCQ@ ) with a restricted form of negation. That s is, we define formulas of PosXPath@;: as formulas of @ PosXPath with the additional node formulas p 4 :q1 4 …4 :qk , whenever p; q1 ; …; qk are labels from Σ. We define T; n F p 4 :q1 4 … 4 :qk iff p A ρðnÞ and qi 2 = ρðnÞ; 1 ri rk. s s Similarly, formulas of CQ@;: (UCQ@;: ) are formulas of @ @ CQ (UCQ ) expanded with the construct pðxÞ 4 : q1 ðxÞ 4 …4 :qk ðxÞ, where x A Var and p; q1 ; …; qk A Σ with semantics: T; θ F pðxÞ 4 :q1 ðxÞ 4 :qk ðxÞ iff p A ρðθðxÞÞ and qi 2 = ρðθðxÞÞ, for every 1 r ir k. s For a formula from CQ@;: its corresponding graph query is defined in the same way as in Definition 1 with the addition that nodes can have negative labels. The s notion of an embedding can also be extended for CQ@;: . The additional clause that has to be added to Definition 2 requires preservation of negated labels:
For every u A V, if :p A ρðuÞ then p2= ρðgðuÞÞ. :s
:s
:s
By PosXPath , CQ and UCQ we denote the frags s s ments of PosXPath@;: , CQ@;: and UCQ@;: without attribute value comparisons respectively.
@
4. Containment of PosXPath
and CQ@
This section contains the main result of this article. First, in Section 4.1 we show that containment for
5
PosXPath and CQ expanded with safe negation are in CONP and Π P2 respectively. Next we show that containment for these fragments expanded with attribute value comparisons remains the same by a polynomial reduction to the corresponding fragments without attribute value comparisons. This result holds under the assumption that attribute values come from a dense linear order without endpoints. In Section 4.3 we show that imposing different constraints on the linear domain of attribute values does not impact the complexity. However, making attributes required everywhere in a tree increases the complexity of containment, as shown in Section 4.4. 4.1. Containment of Positive Xpath and CQs with safe negation In Section 4.2 we will reduce the containment problem s s for PosXPath@ and CQ@ to that of PosXPath: and UCQ: . The next theorem shows that adding safe negation to PosXPath and UCQ does not make the containment problem harder. The argument is similar to the one in [6], but additional care needs to be taken when we deal with negation. Theorem 1. The containment problem over multi-labeled s s trees for PosXPath: and UCQ: is in CONP and Π P2 respectively. Proof. In both cases the proof strategy is the same. Throughout the proof we assume that we deal with multilabeled trees without attributes. Our goal is to show that whenever φ⊈ψ, there is a small (polynomial in φ and ψ) counterexample witnessing this fact. In the proof, we start with an arbitrary counterexample T, and shrink it in two steps: in the first step (creating Tn), we roughly restrict T to the image of φ and intermediate nodes. This can still be too large. In the second step we shrink long paths between image nodes. s Let φ ¼ ⋁i φi and ψ ¼ ⋁j ψ j be UCQ: formulas. Let T ¼ ðN; E; o ; r; ρÞ be a tree such that T F φ and T j ψ. Then there exist i and an embedding e: NodesðGφi Þ-T, where Gφi is the query graph of φi. By eðGφi Þ we denote the image of NodesðGφi Þ. If Gφi F u1 o f u2 , then there must exist nodes x1 and x2 such that eðu1 ÞðE 1 Þ x1 o þ x2 E eðu2 Þ in T. We callsuch x1 and x2 knee-nodes for G. Our aim is to create a small tree out of T which is still a counterexample. For the first “shrinking step”, we color nodes that we must keep. We use three colors: fI; V; Hg.
Mark the root r with I, If x A eðGφ Þ, mark x with I (”image” nodes), If Gφ F u1 o f u2 , then there must exist knee-nodes x1 i
i
and x2. Mark x1 and x2 by I too,
If there exist two nodes x and y marked by I such that
T F xE þ y and there is no node z marked by I with T F xE þ z 4 zE þ y, then mark all the nodes on the path from x to y by V (”vertical” nodes), If there exist two nodes x and y marked by I or V such that T F x o þ y and there is no node z marked by I or V with T F x o þ z 4 z o þ y, then mark all the sibling nodes between x and y by H (”horizontal” nodes),
6
M. Marx, E. Sherkhonov / Information Systems 58 (2016) 1–13
the empty label, and a query Q with T F Q , then the path can be extended even more while preserving the fact that Q is true in the tree. We use the contrapositive of the lemma to shrink such long paths while keeping the query ψ false in the smaller tree. The same reasoning applies for horizontal paths.
Fig. 1. The tree T and the query graph corresponding to Q from Example 1.
Let T ¼ ðN ; E ; o ; r Þ be the substructure of T restricted to the nodes marked by I, H or V.
Let ρ ðnÞ ¼ ρðnÞ for n A I and ρ ðnÞ ¼ ∅ otherwise. Example 1. Let T be a tree as in Fig. 1 and Q the Boolean conjunctive query ( xyzwðaðxÞ 4 Descendantðx; yÞ 4 bðyÞ 4 þ Childðx; zÞ 4 cðzÞ 4 NextSibling ðz; wÞ 4 dðwÞÞ. The corresponding query graph GQ is depicted in Fig. 1, where the downward and horizontal double line arrows denote E þ and o þ respectively, and the single line arrow denotes E. The embedding e is defined by the dashed arrows. The marking of nodes of T with the colors fI; V; Hg is depicted in Fig. 1. Claim 1. T ¼ ðN ; E ; o ; r ; ρ Þ is a tree and T F φ and T j ψ. Proof of Claim 1. It is easy to check that adding the V and H nodes to I is the minimum needed to ensure that Tn is a tree. First, we argue that T F φi . Since we maintained the image of Gφi (nodes labeled by I), we have that e is a mapping from NodesðGφi Þ to Nn. The node labels are preserved under e since we did not change the labeling of I nodes. Let 〈x; y〉 be an edge in Gφi . If Gφi F xEy, or Gφi F x oy then e(x) and e(y) are in respectively child or next sibling relation in Tn since both nodes are labeled with I and they were in that relation in T. If Gφi F xE þ y or Gφi F x o þ y, then e(x) and e(y) are in the corresponding relations in Tn since the intermediate vertical (V) and horizontal (H) nodes were kept. In case Gφi F x o f y we have T F eðxÞ o f eðyÞ since we kept the knee-nodes which witness the following relation in T. Thus, we obtain T F φ. Now we show T jψ. Suppose to the contrary that T F ψ. Then there exists an embedding g of Gψ j into Tn for some j. Because Tn is a substructure of T, g is also a mapping of NodesðGψ j Þ into Nodes(T) that preserves the edge relation. We show that g also preserves the labels. Note that by definition of Tn, the label ρ ðnÞ is either equal to ρðnÞ, when n A I, or empty otherwise. Positive labels are always preserved: ρj ðuÞ D ρ ðgðuÞÞ DρðgðuÞÞ for every node u A NodesðGψ j Þ, where ρj is the labeling function of Gψ j . We show that negative labels are preserved too. Let = ρ ðgðuÞÞ, since g u A NodesðGψ j Þ. If :p A ρj ðuÞ, we have that p2 preserves negative labels. Since negation is safe, there must exist a label q A ρj ðuÞ, which implies q A ρ ðgðuÞÞ, and, thus, ρ ðgðuÞÞ is not empty. In this case ρ ðgðuÞÞ ¼ ρðgðuÞÞ, and thus p2 = ρðgðuÞÞ as required. Thus, T F ψ which is a contradiction. □ Next, we prove two crucial lemmas. In particular, the following lemma claims that if we have a tree T with a long enough non-branching vertical path, where each node has
Lemma 1 (V-path). Let G be a query graph with labels from Σ and T ¼ ðN; E; o ; ρ; rÞ a tree such that there is an embedding of G into T. Suppose u1 Eu2 E…Eun is a path in T, such that
ρðui Þ ¼ ∅, for every i A f1; …; ng, If T F ui Ex, then x ¼ ui þ 1 for io n, n 4 jNodesðGÞj. Let T^ be the tree obtained from T by inserting a node with the empty label in the middle of the path, i.e., by making um the parent and um þ 1 a child of the new node, where n ¼ 2 m (when n is even) or n ¼ 2 m 1 (when n is odd). Then there exists an embedding from G into T^ . Proof. Let G ¼ ðV; E; E þ ; o ; o þ ; o f ; ρÞ be the given query graph and g an embedding of G into T. Since the length n of the path is strictly greater than the number of nodes in G, = gðVÞ; there must exist an index k r n such that uk 2 k A f1; …; ng. Let T 0 ¼ ðN 0 ; E0 ; o 0 ; ρ0 ; r 0 Þ be the tree defined as follows:
r 0 ¼ r, N 0 ¼ N [ fu0k g; u0k 2 = N, E0 ¼ ðE⧹fðuk ; xÞ A Ejx A NgÞ [ fðuk ; u0k Þg [ fðu0k ; xÞjT F uk Exg, o0 ¼ o, For every node v A N, ρ0 ðvÞ ¼ ρðvÞ, and ρ0 ðu0k Þ ¼ ∅.
We prove that in fact the same g is an embedding of G into T 0 1. First, from the definition of T 0 we obtain the following properties. Claim 2. Let T be from the statement of Lemma 1 and T 0 as defined above. Then (i) If T F xE þ y, then T 0 F xE0 þ y, (ii) If x a uk and T F xEy, then T 0 F xE0 y, (iii) If T F x oy (resp. T F x o þ y and T F x o f y), then T 0 F x o 0 y (resp. T 0 F x o 0 þ y and T 0 F x o 0f y). Proof of Claim 2. All items except (i) are immediate by the definition of E0 . For ðiÞ, let T F xE þ y. We then consider two cases: First suppose T F uk Ey. Then T F xE uk and thus T 0 F xE0 uk . Since T 0 F uk E0 u0k and T 0 F u0k E0 y, we have T 0 F xE0 þ y. In the case that T j uk Ey, we obtain T 0 F xE0 þ y by the definition of E0 . □ We prove that g: V-N 0 is an embedding. Preservation of labels follows from the fact that the image of g is in N and g is an embedding of G into T and thus preserves labels. We show that g still preserves the edge relations. Let xEy hold in G. Then it holds that 1 Note that the defined T 0 is isomorphic to the “real” intended tree T 0 where the nodes are sequences of natural numbers. Here, we treat g as the old g composed with the isomorphism.
M. Marx, E. Sherkhonov / Information Systems 58 (2016) 1–13
gðxÞ a uk as uk is not in the image of g. Since g is an embedding of G into T, it holds T F gðxÞEgðyÞ. Then by Claim 2(ii), it holds T 0 F gðxÞE0 gðyÞ. Let G F xE þ y. Since g is an embedding of G into T, we have T F gðxÞE þ gðyÞ. By Claim 2 (i), it follows that T 0 F gðxÞE0 þ gðyÞ. Preservation of the relations o, o þ and o f under g follows from Claim 2 (iii). Now let T^ be the tree defined in the statement of the ^ E; ^ o ^ ; ρ; Lemma. Formally, T^ ¼ ðN; ^ r^ Þ is defined as follows.
r^ ¼ r, = N, N^ ¼ N [ fu0m g; u0m 2 E^ ¼ ðE⧹fðum ; xÞ A Ejx A NgÞ [ fðum ; u0m Þg [ fðu0m ; xÞjT F um Exg, ^ ¼ o, o For every node v A N, ρðvÞ ^ ¼ ρðvÞ, and ρðu ^ 0m Þ ¼ ∅.
The trees T^ and T 0 are isomorphic. Recall the indexes m and k from the definitions of T^ and T 0 . We define a mapping f : N0 -N^ as follows.
If m r k, then f ðvÞ ¼
8 v > > > > 0 < um
ui 1 > > > > : uk
if v A N⧹fum þ 1 ; …; uk g; if v ¼ um þ 1 ; if v ¼ ui ; m þ1 oi r k; if v ¼ u0k :
If m 4 k, then f ðvÞ ¼
8 v > > > > < uk þ 1 ui þ 1 > > > > : u0 m
if v A N⧹fuk þ 1 ; …; um g; if v ¼ u0k ; if v ¼ ui ; k þ 1 ri o m; if v ¼ um þ 1 :
The function f is onto and 1–1. We show that the V-paths in T 0 and T^ are isomorphic. We consider the case m r k, the other case is similar. Let T 0 F uE0 v for u; v A fu1 ; …; uk ; u0k ; uk þ 1 ; uk þ 2 ; …; un g. We need to show that T 0 F uE0 v iff ^ ðvÞ. There are the following possible cases. T^ F f ðuÞEf
u ¼ ui and v ¼ ui þ 1 with 1 r i om or k oi o n. In this
case f ðuj Þ ¼ uj ; jA fi; i þ 1g. By definition of T 0 and T^ it ^ i þ 1 . Thus, T 0 F uE0 v holds that T 0 F ui E0 ui þ 1 and T^ F ui Eu ^ ðvÞ. iff T^ F f ðuÞEf u ¼ um and v ¼ um þ 1 . In this case f ðum Þ ¼ um and f ðum þ 1 Þ ¼ u0m . By definition, it holds that T 0 F um E0 um þ 1 ^ ðvÞ. ^ 0 . Thus, T 0 F uE0 v iff T^ F f ðuÞEf and T^ F um Eu m u ¼ um þ 1 and v ¼ um þ 2 . In this case f ðum þ 1 Þ ¼ u0m and f ðum þ 2 Þ ¼ um þ 1 . By definition, it holds that ^ m þ 1 . Thus, T 0 F uE0 v iff T 0 F um þ 1 E0 um þ 2 and T^ F u0m Eu ^ ðvÞ. T^ F f ðuÞEf u ¼ ui and v ¼ ui þ 1 with m þ 1 o io k. In this case, f ðui Þ ¼ ui 1 and f ðui þ 1 Þ ¼ ui . By definition, it holds that ^ i . Thus, T 0 F uE0 v iff T 0 F ui E0 ui þ 1 and T^ F ui 1 Eu ^ ðvÞ. T^ F f ðuÞEf u ¼ uk and v ¼ u0k . In this case, f ðuk Þ ¼ uk 1 and f ðu0k Þ ¼ uk . By definition, it holds that T 0 F uk E0 u0k and ^ k . Thus, T 0 F uE0 v iff T^ F f ðuÞEf ^ ðvÞ. T^ F uk 1 Eu
7
u ¼ u0k and v ¼ uk þ 1 . In this case, f ðu0k Þ ¼ uk and f ðuk þ 1 Þ ¼ uk þ 1 . By definition, it holds that T 0 F u0k E0 uk þ 1 ^ k þ 1 . Thus, T 0 F uE0 v iff T^ F f ðuÞEf ^ ðvÞ. and T^ F uk Eu
Since f ðvÞ ¼ v for every v A N⧹fu1 ; …; un ; u0k ; u0m g and ρðvÞ ¼ ∅ for every v A fu1 ; …; un ; u0k ; u0m g, the labels are preserved as well. Thus, the mapping f ○g is an embedding of G into T^ . □ Analogous to the above lemma for V-paths, we formalize one for H-paths. The crucial properties of H-paths are that their labels are empty and that all nodes in the path are leafs. We omit the proof. Lemma 2 (H-path). Let G be a query graph with labels from Σ and T ¼ ðN; E; o ; ρ; rÞ an ordered tree such that there is an embedding of G into T. Suppose T has a horizontal path v1 o v2 o… ovn and v is their parent in T, where
ρðvi Þ ¼ ∅ for every i A f1; …; ng, V i ¼ fujT F vi Eug ¼ ∅ for every i A f1; …; ng, n 4 jNodesðGÞj. Let T^ be the tree obtained from T by inserting a node with the empty label in the middle of the horizontal path, i.e., by making vm the predecessor and vm þ 1 the successor of the new node, where n ¼ 2 m (when n is even) or n ¼ 2 m-1 (when n is odd). Then there exists an embedding from G into T^ . The proof of Theorem 1 relies on the small tree property which follows from the two lemmas above. We first show how, using Lemma 1, we can reduce the number of V-nodes. Let Gψ j be the query graph of maximal number of nodes among all Gψ i . Let u1 Eu2 …Eun be a V-path in Tn of length greater than jNodesðGψ j Þj þ1. Then we remove the node um, where n ¼ 2 m (i.e., if n is even) or n ¼ 2 m þ 1 (i.e., if n is odd), from Tn, and make um þ 1 to be the child of um 1 . Let T be the resulting tree. We claim that T F φ and T jψ. The former follows from the fact that we did not change I-nodes in T . For the latter, suppose T F ψ. Then there exists an embedding g: Gψ i -T for some i. Since n 1 4jNodesðGψ j Þj ZjNodesðGψ i Þj, we can apply Lemma 1 to show that there is an embedding of Gψ i to Tn, which contradicts to the fact T jψ. Thus, we can iteratively apply the same argument to make long V-paths shorter and while preserving the fact that T j ψ and T F φ. Similar for H-paths, if they are longer than jNodesðGψ j Þj þ1, we can apply Lemma 2 to shorten them. Let us find out how the size of the small tree is bounded. The number of I nodes in Tn is bounded by jNodesðGφi Þj. Each I node has at most one V path above it, one H path to its right, and one H path through its children. The number of nodes in all these paths is, by the argument above, maximally jNodesðGψ j Þj þ1. Thus after repeated application of the Lemmas to Tn the resulting size is bounded by Oðjφj jψjÞ. s A Π P2 algorithm for deciding the UCQ: containment then works as follows. It first guesses a tree T of size Oðjφj jψjÞ and then checks in NP if T F φ and in CONP if T j ψ. The :s CONP algorithm for PosXPath works similarly. It also
8
M. Marx, E. Sherkhonov / Information Systems 58 (2016) 1–13
guesses a tree T of polynomial size and checks if T F φ and T j ψ which can be done in PTIME [14]. □ Note that the safeness condition for negation turns out to be crucial. Indeed, in [12] it was shown that containment for tree patterns with unrestricted label negation is already PSPACE-complete. 4.2. Adding attributes
ðGEQ3Þ
〈↓ 〉ðp@a o c 4 :p@a a c Þ;
ðLNEQ Þ
〈↓ 〉ðp@a 4 c 4 :p@a a c Þ;
ðGNEQ Þ
〈↓ 〉ðp@a a c 4 :p@a o c 4 :p@a 4 c Þ;
ðTRIÞ
〈↓ 〉ðp@a Z c 4 p@a r c 4 :p@a ¼ c Þ;
Now we are ready to provide upper bounds for our fragments with attribute value comparisons. Theorem 2. The containment problem over trees with attributes is
in CONP for PosXPath in Π P2 for UCQ@;: .
@;:s
s
〈↓ 〉ðp@a 4 c 4 :p@a Z c Þ;
,
Given the containment problem φ Dψ for s s φ; ψ A PosXPath@;: (UCQ@;: ), we reduce it to the cons s tainment problem φ0 D ML ψ 0 in PosXPath: (UCQ: ), which is known to be in CONP (Π P2 ) by Theorem 1. Thus Theorem 2 is a consequence of the following lemma. Lemma 3. Let φ and ψ be PosXPath@;: (UCQ@;: ) formulas. s s Then there exist PTIME computable PosXPath: (UCQ: ) 0 0 formulas φ and ψ such that s
s
φ D ψ iff φ0 D ML ψ 0 : This holds for both single-labeled and multi-labeled trees. Proof. The idea behind the proof is as follows. We abstract away from arithmetic comparisons by replacing each of them with a new label. These labels have to obey certain constraints, like comparisons do. To this purpose, we define a list of axioms that faithfully encode these constraints. For every pi ; pj A Σ p , pi a pj :
〈↓ 〉ðpi 4 pj Þ;
ðLabelÞ
For every a A Σ a ; c; c1 ; c2 A Σ c , c1 ac2 〈↓ 〉ðp@a ¼ c1 4 p@a ¼ c2 Þ;
ðSNameÞ
〈↓ 〉ðp@a ¼ c 4 p@a a c Þ;
ðEqÞ
For every a A Σ a ; c A Σ c and R; S in f o ; ¼ ; 4g with R a S, 〈↓ 〉ðp@a Rc 4 p@a Sc Þ;
ðMExclÞ
For every a A Σ a ; c; c1 A Σ c and R A f a ; r ; Z ; o ; 4 g,
ðLEQGEQ Þ
For every c1 o c2 ; c1 ; c2 A Σ c , add the disjuncts, 〈↓ 〉ðp@a o c1 4 :p@a o c2 Þ;
ðOrder1Þ
〈↓ 〉ðp@a 4 c2 4 :p@a 4 c1 Þ;
ðOrder2Þ
〈↓ 〉ðp@a ¼ c1 4 :p@a o c2 Þ;
ðOrder3Þ
〈↓ 〉ðp@a ¼ c2 4 :p@a 4 c1 Þ: @;:s
ðOrder4Þ 0
0
we define φ ≔φ~ and ψ ≔ψ~ 3 Ax, In case of PosXPath ~ replaces comparisons with labels (definition is in where ðÞ Section 3) and Ax is the disjunction of the formulas mentioned above. In the definition of Ax, Σp, Σa and Σc are respectively the sets of labels, attributes and constants appearing in φ or ψ. We use the abbreviation 〈↓ 〉θ ¼ θ 3 〈↓ þ 〉θ. Note that the formula Ax is in s s PosXPath: . In case of UCQ@;: the translation ðÞ0 is defined essentially the same. The only difference is that we take (x:TRx ðAxÞ instead of Ax. Notice that the resulting s formulas φ0 and ψ 0 are in UCQ: . We first argue that the size of Ax is Oððjφjþ jψjÞ3 Þ. Since the sets Σp, Σa and Σc are respectively the sets of labels, attributes and constants appearing in φ or ψ, their sizes are bounded by the combined size jφjþ jψj. The axioms in Ax are in fact axiom schemas. Each schema has at most 3 parameters from Σp, Σa and Σc and 1 parameter from the set of possible operators from f ¼ ; a ; o ; 4 ; r ; Z g. Thus each schema stands for at most 6 ðjφjþ jψjÞ3 disjuncts. The number of axioms and their size does not depend on φ and ψ. Whence the size of Ax is bounded by Oððjφjþ jψjÞ3 Þ. We give some intuition behind Ax. In order to prove this lemma, we need to show that there is a counterexample for φ D ψ iff there is a counterexample for φ0 D ML ψ 0 . Note that every counterexample tree T for φ0 D ML ψ 0 must refute every disjunct (axiom) in Ax. Intuitively, the axioms enforce the following properties of T:
(Label): each node has at most one label from Σp, (SName): each attribute of a node can take only at most one value,
〈↓ 〉ðp@a Rc1 4 :p@a ¼ c 4 :p@a 4 c 4 :p@a o c Þ;
ðDNegÞ
〈↓ 〉ðp@a r c 4 :p@a ¼ c 4 :p@a o c Þ;
(MExcl), (Eq): there is no inconsistent comparison, (DNeg): if a node contains a comparison with a con-
ðLEQ1Þ
〈↓ 〉ðp@a Z c 4 :p@a ¼ c 4 :p@a 4 c Þ;
ðGEQ1Þ
〈↓ 〉ðp@a ¼ c 4 :p@a r c Þ;
ðLEQ2Þ
stant, then it must contain a comparison with all other constants from Σc, (LEQ1)–(LEQGEQ): the natural interaction between the comparisons with a constant, (Order1)–(Order4): the order is preserved.
〈↓ 〉ðp@a ¼ c 4 :p@a Z c Þ;
ðGEQ2Þ
〈↓ 〉ðp@a o c 4 :p@a r c Þ;
ðLEQ3Þ
The following claim is crucial for constructing a counterexample tree for φ Dψ from a counterexample for φ0 D ML ψ 0 .
M. Marx, E. Sherkhonov / Information Systems 58 (2016) 1–13
Claim 3. Let T ¼ ðN; E; o; r; ρÞ be a multi-labeled tree over Σ 0 such that T; r j Ax. Then for every a A Σ a ; c A Σ c , node n A N, exactly one of the following holds. (i) there is no p@a opc A ρðnÞ for every op A f ¼ ; a ; Z; r; o; 4g, (ii) there is exactly one p@a ¼ c A ρðnÞ and for every c1 A Σ c it holds that p@a opc1 A ρðnÞ iff D F copc1 , (iii) there is no p@a opc A ρðnÞ and there exists c0 A D⧹Σ c such that for every c1 A Σ c it holds that p@a opc1 A ρðnÞ iff D F c0 opc1 . Proof of Claim. Let T be as stated in the Claim, a A Σ a an attribute name, c A Σ c a constant, n A N a node in T. Assume that there exists p@a opc in ρðnÞ. Otherwise, item (i) holds. Assume that op is in fact ”¼”. Because T; r j Ax, the formula (SName) is false and thus there cannot be another p@a ¼ c1 in ρðnÞ. We show, for every c1 A Σ c and op A f ¼ ; a ; 4 ; o; Z; rg, that p@a opc1 A ρðnÞ iff D F copc1 . (1) op is ¼. Assume p@a ¼ c1 A ρðnÞ, then we have c ¼ c1 by (SName). The converse implication holds since p@a ¼ c A ρðnÞ by the assumption. (2) op is a . Assume p@a a c1 A ρðnÞ. By (Eq), it follows that c1 a c. Thus, D F c a c1 . Conversely, assume D F c a c1 . It means that either c 4c1 or c o c1 . First assume that c 4 c1 . Since p@a ¼ c A ρðnÞ and c 4 c1 , by (Order4) we obtain p@a 4 c1 A ρðnÞ. Then, by (GNEQ), it follows that p@a a c1 A ρðnÞ, as desired. Similarly for the case c o c1 , using (Order3) and (LNEQ), we can show p@a a c1 A ρðnÞ. (3) op is 4 . Assume p@a 4 c1 A ρðnÞ. We show that D F c 4 c1 . Suppose the opposite, i.e., either c ¼ c1 or c1 4 c. In the first case, it would mean that both p@a ¼ c and p@a 4 c occur in ρðnÞ, which is a contradiction with (MExcl). In the second case, by (Order3), both p@a o c1 and p@a 4 c are in ρðnÞ, which is again a contradiction 1 with (MExcl). Now suppose D F c 4 c1 . Then by (Order4), it follows that p@a 4 c1 A ρðnÞ, as needed. (4) op is o. Similar to the previous case. (5) op is Z. Assume p@a Z c1 A ρðnÞ. If c1 ¼ c, then we immediately obtain D F c Z c1 . Now suppose c ac1 and we show that D F c Zc1 . Suppose the opposite, i.e., D F c oc1 . Then by (Order3), we have p@a o c1 A ρðnÞ. By (LEQ3), it implies that p@a r c1 A ρðnÞ, which in turn by (LEQGEQ) implies that p@a ¼ c1 A ρðnÞ. The latter is a contradiction with (SName). Now assume D F c Zc1 . This means that either c ¼ c1 or c 4 c1 in D. In the first case, we have p@a ¼ c A ρðnÞ by the assumption. Thus by (GEQ2), we have that p@a Z c A ρðnÞ. In the second case, similarly to the case when op is 4 , we can show that p@a 4 c1 A ρðnÞ. Then by (GEQ3), we have p@a Z c1 A ρðnÞ, as needed. (6) op is r. Similar to the previous case. Thus we have proved item (ii). Let us consider (iii). Now there is no p@a ¼ c A ρðnÞ for any c A D. We define c1 ¼ maxfcjp@a 4 c A ρðnÞg and c2 ¼ minfcjp@a o c A ρðnÞg. If the former set is empty, we let c1 ¼ 1, and if the latter set is empty, we let c2 ¼ þ 1. We claim that at least one of c1 and c2 is finite. Indeed,
9
there must be p@a Rc in ρðnÞ for some R A f a; o; 4; r; Zg since otherwise item ðiÞ would hold. By DNeg it follows that either p@a o c or p@a 4 c is in ρðnÞ, which means that c1 or c2 is finite. We also claim that c1 o c2 . It is trivially true if one of c1 and c2 is infinity, thus assume both are finite. If c1 ¼ c2 , then both p@a 4 c1 and p@a o c1 appear in ρðnÞ at the same time, which is forbidden due to (MExcl). If c1 4c2 , then by (Order1), both p@a 4 c1 and p@a o c1 are in ρðnÞ, which is again forbidden by (MExcl). Now, since c1 o c2 and the assumption that D is a dense order, there exists c0 A D such that c1 o c0 o c2 . We claim that c0 2 = Σ c . Suppose the opposite. Then since = ρðnÞ by the assumption and the fact that p@a ¼ c0 2 p@a Rc″ A ρðnÞ for some R and c″ (otherwise we would be in case (i)), we obtain either p@a o c0 A ρðnÞ or p@a 4 c0 A ρðnÞ, by (DNeg). If p@a o c0 A ρðnÞ, then D F c0 Zc2 which contradicts to the fact that D F c0 o c2 . Similarly, if p@a 4 c0 A ρðnÞ, then D F c0 rc1 which contradicts with D F c0 4 c1 . We now show that for every c A Σ c and op A f ¼ ; a ; 4 ; o ; Z ; r g, p@a opc A ρðnÞ iff D F c0 op c. (1) op is ¼. The equivalence holds since for every c A Σ c , there is no p@a ¼ c in ρðnÞ and D j c0 ¼ c since c0 2 = Σc. (2) op is a . Assume p@a a c A ρðnÞ. Then we have that D F c0 ac because c0 is not in Σc. Conversely, assume D F c0 ac. By (DNeg), since there is no p@a ¼ c in ρðnÞ for every c A Σ c and there is p@a Rc1 for some c1, it follows that either p@a o c A ρðnÞ or p@a 4 c A ρðnÞ. Applying (LNEQ) or (GNEQ) respectively, we obtain p@a a c A ρðnÞ, as desired. (3) op is 4 . Assume p@a 4 c A ρðnÞ. Then DF c0 4 c by definition of c0 . Conversely, assume D F c0 4 c. We show that p@a 4 c A ρðnÞ. Since there is no p@a ¼ c A ρðnÞ and there exists p@a Rc1 A ρðnÞ, we obtain either p@a o c or p@a 4 c in ρðnÞ, by (DNeg). The first case is impossible since it would imply c0 o c which contradicts the assumption. Thus we have p@a 4 c A ρðnÞ, as desired. (4) op is o. Similar to the previous case. (5) op is Z . If p@a Z c A ρðnÞ, then by (GEQ1) either p@a ¼ c A ρðnÞ or p@a 4 c A ρðnÞ. The first case is impossible by the assumption. In the second case, we obtain that D F c0 4 c by definition of c0 . Thus, D F c0 Zc. Now assume D F c0 Z c. This means that either c0 ¼ c or = Σ c . In c0 4 c in D. The first case is impossible, since c0 2 the second case, as with the case op ¼ ” 4 ”, we can show that p@a 4 c A ρðnÞ. Then by (GEQ3), it holds that p@a Z c A ρðnÞ. (6) op is r. Similar to the previous case. This concludes the proof of the claim. □ We now prove that φ D ψ iff φ0 D ML ψ 0 , ()) Let T ¼ ðN; E; o; r; ρÞ be a multi-labeled tree such that T; r F φ0 and T; r j ψ 0 . Note that then T; r j Ax. Then we define a single-labeled tree T 0 ≔ðN; E; o ; r; ρ0 ; attÞ, where att is a partial function assigning a value in D to a given node and an attribute name, as follows:
For p A Σ p , ρ0 ðnÞ ¼ p iff p A ρðnÞ. If there is no p A Σ p such that p A ρðnÞ, we set ρ0 ðnÞ ¼ z for a fresh symbol z.
10
M. Marx, E. Sherkhonov / Information Systems 58 (2016) 1–13
8 > < undefined attðn; aÞ ¼ c > : c0
from Claim3; ðiiiÞ; otherwise:
We claim that T 0 is well defined. Indeed, (Label) ensures that every node is labeled by exactly one label from Σp or by z. Morever, the function att is well defined since exactly one of the conditions in the definition of att is fulfilled, according to Claim 3. By induction, using Claim 3, we can show that for every θ, T; n F θ~ iff T 0 ; n F θ. Thus, it follows T 0 ; r F φ and T 0 ; r jψ which was desired. ( ( ) Let T ¼ ðN; E; o ; r; ρ; attÞ be a single-labeled tree such that T F φ and T j ψ. We define the tree T 0 ≔ðN; E; o ; r; ρ0 Þ, where ρ0 is defined as follows:
For p A Σ p , p A ρ0 ðnÞ iff ρðnÞ ¼ p, p@ ¼ c A ρ0 ðnÞ iff attðn; aÞ ¼ c, p@ opc A ρ0 ðnÞ iff D F attðn; aÞopc for op A f a ; r ; Z ; o ; a a
4g, c A Σ c .
It is straightforward to check that T 0 does not satisfy any of the disjuncts in Ax. Thus, we obtain T 0 F φ0 and T 0 jψ 0 .□ The same argument goes through for multi-labeled trees, except that we must not include formulas (Label) juncts of Ax. 4.3. Restricting the attribute domain We now show the same complexity results for various restrictions on the domain of attribute values. A linear order D has a smallest (largest) element if there exists c0 A D such that c0 r c (c Z c0 ) for every c A D. We say D has an endpoint if there exists a smallest or a largest element in D. D is discrete if any point which has a successor also has an immediate successor. D is dense linear order if for every x o y in D there exists z A D such that x o z o y. Proposition 2. Let D be one of the following linear orders: (i) finite, (ii) discrete, (iii) dense or discrete with one or two endpoints. Then the containment problem for PosXPath@;: and s UCQ@;: over single-labeled trees with the domain of attribute values D is in CONP and Π P2 respectively. s
Proof. Let φ and ψ be PosXPath@;: (UCQ@;: ) formulas over D and Σ c D D, Σa and Σp the sets of constants, attribute names and labels in Σ appearing in φ or ψ. We then construct in PTIME formulas φ0 and ψ 0 over Σ 0 ¼ Σ p [ fp@a opc ja A Σ a ; c A Σ c ; op A f ¼ ; a; o; 4 ; r ; Z gg such that s
φ D ψ if and only if φ0 D ML ψ 0 :
s
ð1Þ
~ is Namely, we take φ ≔φ~ and ψ ≔ψ~ 3 Ax 3 Axk , where ðÞ defined in Section 3, Ax is from the proof of Lemma 3 and Axk ; k A fðFinÞ; ðDiscrÞ; ðEndÞg is constructed according to the cases (i), (ii) and (iii) of the Proposition. Note that the s formulas φ0 and ψ 0 in all the cases are in fact PosXPath: 0
formulas. In case of UCQ@;: , the translation ðÞ0 is defined essentially the same. The difference is that we use (x:TRx ðAxÞ and ( y:TRy ðAxk Þ instead. Note that the result of s ðÞ0 is a union of CQ: formulas. The upper bounds then follow from Theorem 1. s
if there is no p@a opc1 in ρðnÞ; if p@a ¼ c A ρðnÞ;
0
Now we construct the formulas Axk ; k A fðFinÞ; ðDiscrÞ; ðEndÞg. (i). Assume D ¼ fc1 oc2 o … ock g is a finite linear order. We then write down the formulas of AxðFinÞ . It is the disjunction of the following formulas. For every a A Σ a , c A Σ c and op A f ¼ ; a; o; 4; r; Z g: 〈↓ 〉ðp@a opc 4 :p@a ¼ c1 4 …4 :p@a ¼ ck Þ:
ðFinÞ
This axiom enforces that whenever an attribute is defined, its value equals one of ci ; 1 ri r k. The following claim, which is easy to verify using (Fin), is crucial. Claim 4. Let T ¼ ðN; E; o ; r; ρÞ be a multi-labeled tree over Σ 0 such that T; r j Ax 3 AxðFinÞ . Then for every a A Σ a ; c A Σ c , node n A N and op A f ¼ ; a ; Z ; r ; o ; 4 g, exactly one of the following holds: (i) there is no p@a ¼ c A ρðnÞ, (ii) there is exactly one p@a ¼ c A ρðnÞ and for every c1 A Σ c it holds that p@a opc1 A ρðnÞ iff D F copc1 . Now we prove the equivalence (1). For the direction from left to right, given a multi-labeled tree T over Σ 0 such that T F φ0 and T j ψ 0 , we construct a single-labeled tree with attributes T 0 as it was done in Lemma 3. The only difference is in the definition of the attribute function att. In our case we take 8 undefined if there is no p@a opc in ρðnÞ; > < op A f ¼ ; a ; o ; 4 ; Z ; r g; cA Σ c attðn; aÞ ¼ > :c if p A ρðnÞ: @a ¼ c
Using Claim 4 we can show that for every n A T, θ over Σ; A and D, T; n F θ~ iff T 0 ; n F θ. The direction from right to left of (1) can be proved exactly as in Lemma 3. (ii). D is a discrete linear order. We assume that D is infinite, as the finite case is covered by the case (i). We take AxðDiscrÞ as the disjunction of the following formulas. For every a A Σ; c1 ; c2 A Σ c such that c1 oc2 in D and there is no c0 in D with c1 o c0 o c2 , 〈↓ 〉ðp@a 4 c1 4 p@a o c2 Þ:
ðDiscrÞ
This axiom enforces the requirement that a value for aattribute cannot be between an element in D and its immediate successor. Similarly to Lemma 3 we can show that the reduction is correct. To this purpose we need the claim which is the exact reformulation of Claim 3 where instead of Ax we take Ax 3 AxðDiscrÞ and D is the discrete linear order. We highlight the difference with the proof of Claim 3. The only nontrivial difference is item (iii). Assume the conditions (i) and (ii) of Claim 3 do not hold for a A A and n A T. We define c1 ¼ maxfcjp@a 4 c A ρðnÞg and c2 ¼ minfcjp@a o c A ρðnÞg. As in Claim 3 we can show that D F c1 oc2 . Having that, there exists c0 such that c1 o c0 o c2 . Indeed, suppose the opposite. Then both
M. Marx, E. Sherkhonov / Information Systems 58 (2016) 1–13
p@a 4 c1 and p@a o c2 are in ρðnÞ and c2 is the immediate successor of c1 in D, which is a contradiction with (Discr). It = Σ c . Moreover, for every c″ A Σ c , follows from (DNeg) that c0 2 p@a opc″ A ρðnÞ iff D F c0 opc″ . This can be verified as it was done in Claim 3. Thus we have proved the claim. Having this claim at hand, we can prove the equivalence (1) in the same way as in Lemma 3. (iii). D is dense or discrete linear order with one or two endpoints. If D is dense, take AxðEndÞ as the disjunction ofthe following formulas: If D has the least endpoint cl, for every a A Σ a : 〈↓ 〉p@a o c1 :
ðLEndÞ
If D has the greatest endpoint cg, for every a A Σ a : 〈↓ 〉p@a 4 cg :
ðREndÞ
In case D is discrete linear order, AxðEndÞ additionally has (Discr) as a disjunct. The axioms (LEnd) and (REnd) enforce the requirement that attributes cannot take their values outside of the bounds in D. As in the previous case, we can prove the variant of Claim 3, where we consider AxðEndÞ and D a dense or discrete linear order with one or two endpoints. We do not spell out the proof, but the crucial difference is that in item (iii) axioms (LEnd) and (REnd) ensure the fact that c0 is chosen within the interval ½cl ; cg . Having this claim, we can prove the equivalence (1) in the same way as in Lemma 3. Clearly, the constructed φ0 and ψ 0 are PTIME computable from φ and ψ. 4.4. Lower bounds In this section we show a number of lower bounds on containment for CQ@ and PosXPath@ . The following lower bound was shown in [6]. for Proposition 3 ([6]). Containment is Π P2 -hard CQðChild; DescendantÞ, i.e., conjunctive queries that use only the predicates Child and Descendant. For PosXPath@ , the CONP lower bound for containment follows from hardness of containment for tree patterns [19], which is a fragment of PosXPath@ . In order to compare our results to those in [19], we follow their notation. Let XPf½ ;;==g denote the fragment of PosXPath without union and disjunction, only the ↓ step, and no occurence of the following and preceding axes. These are called tree patterns in the literature. Let XPf½ ;==g denote XPf½ ;;==g in which no wildcard (denoted by > in PosXPath) occurs. Containment of XPf½ ;==g and XPf½ ;;==g patterns is in f½ ;;==g PTIME and CONP-complete, respectively. Let XP ¼ ; a and f½ ;==g f½ ;;==g and XPf½ ;==g XP ¼ ; a denote the expansions of XP with equality and inequality attribute value comparisons, f½ ;==g respectively. We show that containment of XP ¼ ; a patf½ ;;==g terns becomes CONP hard. Containment of XP ¼ ; a patterns becomes PSPACE hard when interpreted over trees with at least one required attribute. The following property is used in our lower bound arguments. The proof can be found in [19, Lemma 3].
11 f½;;==g
f½ ;==g
Proposition 4. Let L be XP ¼ ; a or XP ¼ ; a . Let φ be an L formula and Δ a finite set of L formulas. Then there are PTIME computable L formulas φ0 and ψ 0 such that φ D ⋁Δ iff φ0 D ψ 0 : The same holds for the case of multi-labeled trees. f½ ;==g
Proposition 5. The containment problem for XP ¼ ; a is CONP-hard. Proof. We reduce the 3SAT problem to the nonf½ ;==g containment problem in XP ¼ ; a . Firstly, we can use disjunction of tree patterns on the right side of the containment problem, due to Proposition 4. Let Q be the conjunction of clauses C i ¼ ðX i1 3 i X 2 3 X i3 Þ; 1 r ir k over the variables fx1 ; …; xn g, where Xij are literals. From Q, we construct in PTIME two formulas over the signature Σ ¼ fr; bg, attribute names A ¼ fa1 ; …; an g and an attribute domain D containing values f0; 1; 2g as follows. We define φ≔r 4 〈↓〉ðb4 @a1 a2 4 … 4 @an a 2Þ2 and ψ≔⋁ki ¼ 1 〈↓〉ðb4 Bi1 4 Bi2 4 Bi3 Þ, where Bij ¼ ð@al ¼ 0Þ iff X ij ¼ xl in Ci and Bij ¼ ð@al a0Þ iff X ij ¼ :xl in Ci. We claim that Q is satisfiable if and only if φ⊈ψ. First assume that Q is satisfiable, i.e., there is a variable assignment V: fx1 ; …; xn g-f0; 1g such that V F Q . We then define the following tree T ¼ ðfv1 ; v2 g; fðv1 ; v2 Þg; v1 ; ρ; attÞ , where the labeling ρ is defined as ρðv1 Þ ¼ frg, ρðv2 Þ ¼ fbg and attðv2 ; al Þ ¼ 1 iff Vðxl Þ ¼ 1 and attðv2 ; al Þ ¼ 0 iff Vðxl Þ ¼ 0 for every l; 1 r l r n. Clearly, T satisfies φ. Suppose T; v1 F ψ. This means there exists an index i such that T; v1 F 〈↓〉ðb4 Bi1 4 Bi2 4 Bi3 Þ, which implies T; v2 F Bij ; j ¼ 1; 2; 3. Hence, by the definition of the attribute function we obtain that if Bij ¼ ð@al ¼ 0Þ, then VðX ij Þ ¼ Vðxl Þ ¼ 0 and, similarly, if Bij ¼ ð@al a 0Þ, then VðX ij Þ ¼ Vð:xl Þ ¼ 0. Thus, we obtain V jC i , which is a contradiction. Thus, T jψ. We now prove the converse. Assume there is a tree T with T F φ and T j ψ. The former implies that there exists a child of the root of T, v such that T; v F b and the attributes a1 ; …; an are defined at v. Moreover since T j ψ, for every i; 1 ri rn it holds that T; v jb 4 Bi1 4 Bi2 4 Bi3 . We define the variable assignment V: fx1 ; …; xn g-f0; 1g as follows: Vðxl Þ≔0 iff attðv; al Þ ¼ 0 and Vðxl Þ≔1 iff attðv; al Þ a 0. We claim that V F Q . Assume the opposite, i.e., there exists a clause Cj which is mapped to 0 under V. By definition of V, it follows that T; v F Bj1 4 Bj2 4 Bj3 and therefore, T; v F b 4 Bj1 4 Bj2 4 Bj3 which is a contradiction. 4.4.1. Required attributes In Section 4.2 we dealt with the case when attributes are optional. We now consider the case when some attributes are required. We say that an attribute a A A is required in a tree T with domain N if the function att: N fag-D is total. We show that when at least one attribute is required, containment of tree patterns with equality and inequality comparisons rises to PSPACE. 2 The purpose of the inequalities @ai a 2 is to guarantee that the attribute ai is defined in the b-node of a model of φ. We could express the same with the comparison @ai r 1 or @ai Z 0.
12
M. Marx, E. Sherkhonov / Information Systems 58 (2016) 1–13 f½ ;;==g
Theorem 3. The containment problem for XP ¼ ; a interpreted over trees with at least one required attribute is PSPACE-complete. f½ ;;==g
Proof. We show the upper bound for XP ¼ ; a expanded with the other equality operators (i.e., o ; 4 ; r and Z ). For that, we reduce the containment problem in this fragment to containment for unions of XPf½;;==;:g (tree pattern formulas with unrestricted label negation) similar to Lemma 3. The additional axiom in Ax is 〈↓ 〉ð:p@a ¼ c 4 :p@a a c Þ for every required a A A, where c is a constant (note that this axiom contains unsafe negation). This axiom enforces that the attribute a is defined everywhere in the tree. In [12] it is shown that containment for unions of XPf½;;==;:g is solvable in PSPACE. For proving the lower bound we encode the corridor tiling problem, which is known to be hard for PSPACE [8]. Our lower bound proof uses the construction from the PSPACE-hardness proof for the containment problem in tree patterns with disjunction over a finite alphabet in [20]. The corridor tiling problem is formalized as follows. Let be a tiling system, where Til ¼ ðD; H; V; b; t ; nÞ D ¼ fd1 ; …; dm g is a finite set of tiles, H; V D D2 are horizontal and vertical constraints, n is a natural number in unary notation, b and t are tuples over D of length n. Given such a tiling system, the goal is to construct a tiling of the corridor of width n using the tiles from D so that the constraints H and V are satisfied. Moreover, the bottom and the top row must be tiled by b and t respectively. Let a A A be a required attribute. Now we construct two f½;;==g XP ¼ ; a expressions φ and ψ such that φ⊈ψ over trees with a required attribute a iff there exists a tiling for Til. To this purpose, we use a string representation of a tiling. Each row of the considered tiling is represented by the tiles it consists of. If the tiling of a corridor of width n has k rows, it is represented by its rows separated by the special symbol ♯. Thus, a tiling is a word of the form u1 ♯u2 ♯⋯♯uk $, where each ui is the word of length n corresponding to the i-th row in the tiling, and $ denotes the end of tiling. Note u1 ¼ b and uk ¼ t . For the sake of readability, for expression r, we use the abbreviation ri to denote the path formula ?r; ↓; ?r; …; ↓; ?r with i occurrences of r. We then define the formulas over attributes fag and attribute domain containing D [ f♯g. Define φ0 as 〈?ð@a ¼ b1 Þ; ↓; ?ð@a ¼ b2 Þ; …; ↓; ?ð@a ¼ bn Þ; ↓; ?ð@a ¼ ♯Þ; ↓ þ : ?ð@a ¼ t 1 Þ; ↓; …↓; ?ð@a ¼ t n Þ; ↓〉$: Intuitively, this expression enforces a tiling to start with a path starting with b and finishing with t . Now the formula ψ 0 defines all incorrect tilings and additional conf½;;==g straints. It is the disjunction of the following XP ¼ ; a formulas. (1) Incorrect length of a row. (1a) ⋁ni ¼ 10 〈↓ þ ; ?ð@a ¼ ♯Þ; ↓; > i ; ↓〉ð@a ¼ ♯Þ, a row is too short, (1b) 〈↓ þ ; ð@a a ♯Þn þ 1 〉> , a row is too long.
(2) 〈↓ þ ; ?ð@a ad1 4 … 4 @a a dm 4 @a a♯Þ; ↓ þ 〉$, neither the delimiter or a tile on a position, (3) Horizontal or vertical constraints are violated. (3a) ⋁ðd1 ;d2 Þ 2= H 〈↓ þ ; ?ð@a ¼ d1 Þ; ↓; ?ð@a ¼ d2 Þ〉 > , a horizontal constraint is violated, (3b) ⋁ðd1 ;d2 Þ 2= V 〈↓ þ ; ?ð@a ¼ d1 Þ; ↓; > n ; ↓; ?ð@a ¼ d2 Þ〉 > , a vertical constraint is violated. We show that there exists a tree with a required attribute a such that T F φ0 and T jψ 0 iff there exists a tiling for Til. ð(Þ. Assume that there exists a tiling of the corridor. Let s be the string representation of it. Then, s ¼ u1 ♯u2 ♯:::♯uk $ , where jui j ¼ n; ui A Dn ; u1 ¼ b , and uk ¼ t . Moreover, on the one hand if x y, is an infix of some ui , then ðx; yÞ A H, and on the other hand for every infix x u0 y of length n þ 1 of ui ♯ ui þ 1 , it holds that ðx; yÞ A V. Let T s be the corresponding tree, i.e., a single path of jsj nodes fv1 ; …; vjsj g where the label of each node vi ; i ojsj is z , the label of vjsj is $ and attribute function is defined according to s, i.e., attðvi ; aÞ ¼ si . Clearly, Ts is a model of φ0 and not of ψ 0 . ð)Þ. Let T be a tree such that T; r F φ0 , T; r j ψ 0 and attðn; aÞ is defined for every n A NodesðTÞ. Since T; r F φ0 , there must exist a path r ¼ v1 ; …; vm in T such that attðvi ; aÞ ¼ bi ; 1 r ir n and attðvm n þ i ; aÞ ¼ t j ; 1 r jr n. Moreover, either ♯ or a symbol from D is in the attribute of every node vi ; 1 ri o m, according to (2). We define a tiling function g: f0; …; n 1g N-D assigning a tile to every position in the corridor as follows: gði; jÞ ¼ attðvðn þ 1Þj þ i þ 1 ; aÞ; 1 r i rn. Indeed, this function is well defined, as (1) ensures the correct counting. By formulas (3a) and (3b) the tiling defined by g satisfies the horizontal and vertical constraints. We then apply Proposition 4 to remove the outermost disjunction in ψ 0 to obtain the equivalent containment f½ ;;==g problem φ D ψ in XP ¼ ; a □. Theorem 3 provides a lower bound for the containment s s problem for PosXPath@;: and UCQ@;: over trees with required attributes. Only for tree patterns we know that the problem is PSPACE-complete. Using the same reduction as in the proof of the upper bound in Theorem 3, and the results on containment for XPath [18] and XPath with path intersection [24], we obtain EXPTIME and 2EXPTIME upper s s bounds for containment for PosXPath@;: and UCQ@;: over trees with required attributes, respectively. However, if we restrict attributes to be required at nodes labeled with a certain symbol, then the containment is still in P CONP and Π 2 . Let p A Σ be a label and a A A an attribute name. We say that a is required at label element p if attðn; aÞ is defined whenever p A ρðnÞ for every tree T and node n A NodesðTÞ. Proposition 6. The containment problem for PosXPath@;: s and UCQ@;: with required attributes at certain labeled nodes is in CONP and Π P2 respectively. s
Proof. As before, we can prove a variant of Lemma 3. Let c be a constant name. Whenever attribute a is required at nodes labelled by p we add the axiom 〈↓ 〉ðp 4 : p@a ¼ c 4 :p@a a c Þ to the set Ax. Note that the negation is safe. This axiom is obviously sound, and it enforces that whenever p holds, at least one p@a opc label holds as well.
M. Marx, E. Sherkhonov / Information Systems 58 (2016) 1–13
This ensures that in the construction of the tree with attribues a is defined at each p node. □
13
This research was supported by the Netherlands Organization for Scientific Research (NWO) under project number 612.001.012 (DEX).
4.5. Tractable cases In this section we consider fragments of PosXPath@ where the containment problem remains in PTIME. It is known that containment in XPf½;==g and XPf½;g is decidable in PTIME, [3,19]. X
Proposition 7. Let XP be any fragment whose containment problem over multiple-labeled trees is in PTIME. Then the containment problem in XP@;X ¼ over multi-labeled trees with attributes is also in PTIME. Proof. Let φ and ψ be formulas in XP@;X ¼ . Our algorithm first checks (in PTIME) if φ is consistent, i.e., if it contains both @a ¼ c and @a ¼ d in the label of a node in φ for some a A A; c; d A D. If φ is inconsistent, we output φ D ψ. Otherwise, we proceed as in the proof of Lemma 3 by reduction to a containment of attribute-free formulas using ~ and the formula (Label) only.□ the translation ðÞ
5. Conclusion We considered the containment problem for positive XPath and conjunctive queries over trees expanded with attribute value comparisons. We showed that in general attribute value comparisons do not increase the complexity of containment. The main idea behind the upper bound was to extend the small counterexample technique to positive XPath and conjunctive queries expanded with a restricted form of negation. Then by axiomatizing the needed constraints in the corresponding expanded fragment, we could abstract away the attribute value comparisons. The complexity, however, does increase from PTIME to CONP for the fragment XPf==;½ g of XPath which uses child, descendant and filter expressions when we add equality and inequality comparisons. Another parameter which affects the complexity is optionality of attributes. If we restrict our trees to have at least one required attribute in every node, then the complexity rises to PSPACE. If, however, attributes are required at elements with specific labels only, the complexity of containment remains the same: CONP for positive XPath and Π P2 for conjunctive queries. We end with listing some open problems. Proposition 7 shows that adding equality comparison only does not affect the PTIME complexity of containment for fragments XPf==;½ g and XPf½ ;g . We do not know what happens when only inequality comparison is added. For conjunctive queries over trees, it is known that the fragments CQðChildÞ and CQðNextSiblingÞ have PTIME containment. It is open whether the complexity increases if we add attribute value comparisons.
Acknowledgements We thank the anonymous referees for their helpful comments.
References [1] F.N. Afrati, S. Cohen, G.M. Kuper, On the complexity of tree pattern containment with arithmetic comparisons, Inf. Process. Lett. 111 (15) (2011) 754–760. [2] F.N. Afrati, C. Li, P. Mitra, On containment of conjunctive queries with arithmetic comparisons, in: Proceedings of the 9th International Conference on Extending Database Technology Advances in Database Technology - EDBT 2004, Heraklion, Crete, Greece, March 1418, 2004, pp. 459–476. [3] S. Amer-Yahia, S. Cho, L. Lakshmanan, D. Srivastava, Tree pattern query minimization, VLDB J. 11 (2002) 315–331. [4] M. Benedikt, W. Fan, F. Geerts, XPath satisfiability in the presence of DTDs, J. ACM, 55(2), 2008. [5] H. Björklund, W. Martens, T. Schwentick, Optimizing conjunctive queries over trees using schema information, MFCS (2008) 132–143. [6] H. Björklund, W. Martens, T. Schwentick, Conjunctive query containment over trees, J. Comput. Syst. Sci. 77 (3) (2011) 450–472. [7] A.K. Chandra and P.M. Merlin, Optimal implementation of conjunctive queries in relational data bases, in: Proceedings of the 9th Annual ACM Symposium on Theory of Computing, May 4-6, 1977, Boulder, Colorado, USA, 1977; pp. 77–90. [8] B.S. Chlebus, Domino-tiling games, J. Comput. Syst. Sci. 32 (3) (1986) 374–392. [9] C. David, A. Gheerbrant, L. Libkin, W. Martens, Containment of pattern-based queries over data trees, ICDT, 2013. [10] A. Deutsch, V. Tannen, Containment and integrity constraints for XPath, in: M. Lenzerini, D. Nardi, W. Nutt, D. Suciu (Eds.), Proceedings of CEUR Workshop, KRDB, vol. 45, 2001, 〈CEUR-WS.org〉. [11] A. Deutsch, V. Tannen, XML queries and constraints, containment and reformulation, Theor. Comput. Sci. 336 (1) (2005) 57–87. [12] A. Facchini, Y. Hirai, M. Marx, E. Sherkhonov, Containment for conditional tree patterns, Logical Methods in Computer Science 11 (2) 2015. [13] C. Farré, W. Nutt, E. Teniente, T. Urpí, Containment of conjunctive queries over databases with null values, in: Proceedings of the 11th International Conference, Database Theory - ICDT 2007, Barcelona, Spain, January 10-12, 2007, pp. 389–403. [14] G. Gottlob, C. Koch, R. Pichler, Efficient algorithms for processing XPath queries, ACM Trans. Database Syst. 30 (2) (2005) 444–491. [15] G. Gottlob, C. Koch, K.U. Schulz, Conjunctive queries over trees, J. ACM, 53 , 2006, (2):238–272. [16] J. Hidders, Satisfiability of XPath expressions, in: G. Lausen, D. Suciu (Eds.), DBPL, of Lecture Notes in Computer Science, vol. 2921, Springer, 2003, pp. 21–36. [17] A.C. Klug, On conjunctive queries containing inequalities, J. ACM, 35, 1988, (1):146–160. [18] M. Marx, Conditional Xpath, ACM Trans. Database Syst. 30 (4) (2005) 929–959. [19] G. Miklau, D. Suciu, Containment and equivalence for a fragment of Xpath, J. ACM, 51 , 2004, (1):2–45. [20] F. Neven, T. Schwentick, On the complexity of Xpath containment in the presence of disjunction, DTDs, and variables, Log. Methods Comput. Sci. 2 (3) 2006. [21] W. Nutt, Ontology and database systems: foundations of database systems, 2013. Teaching material. 〈http://www.inf.unibz.it/ nutt/ Teaching/ODBS1314/ODBSSlides/3-conjQueries.pdf〉. [22] D. Olteanu, H. Meuss, T. Furche, F. Bry, Xpath:looking forward, EDBT, 2002, pp. 109–127. [23] E. Sherkhonov M. Marx, Containment for tree patterns with attribute value comparisons, WebDB, 2013. [24] B. ten Cate, C. Lutz, The complexity of query containment in expressive fragments of XPath 2.0, J. ACM, 56(6), 2009. [25] J.D. Ullman, Information integration using logical views, Theor. Comput. Sci. 239 (2) (2000) 189–210. [26] R. van der Meyden, The complexity of querying indefinite data about linearly ordered domains, J. Comput. Syst. Sci. 54 (1) (1997) 113–135. [27] F. Wei, G. Lausen, Containment of conjunctive queries with safe negation, ICDT 2003, 2003, pages 343–357. [28] P.T. Wood, Containment for XPath fragments under DTD constraints, in: ICDT, 2003, pp. 297–311.