On The Complexity Of Xpath Containment In The Presence Of Disjunction, Dtds, And Variables

. XPath is a simple language for navigating an XML-tree and returning a set of answer nodes. The focus in this paper is on the complexity of the containment problem for various fragments of XPath. We restrict attention to the most common XPath expressions which navigate along the child and/or descendant axis. In addition to basic expressions using only node tests and simple predicates, we also consider disjunction and variables (ranging over nodes). Further, we investigate the containment problem relative to a given DTD. With respect to variables we study two semantics, (1) the original semantics of XPath, where the values of variables are given by an outer context, and (2) an existential semantics introduced by Deutsch and Tannen, in which the values of variables are existentially quantiﬁed. In this framework, we establish an exact classiﬁcation of the complexity of the containment problem for many XPath fragments.


Introduction
XPath is a simple language for navigating an XML document and selecting a set of element nodes [9].At the same time it is also the main XML selection language.Indeed, XPath expressions are used, for instance, as basic patterns in several XML query languages like XQuery [5] and XSLT [3,10]; they are used in XML Schema to define keys [11], and in XLink [13] and XPointer [12] to reference elements in external documents.In every such context an instance of the containment problem is present: optimizing XPath expressions can be accomplished by an algorithm for containment, and XSLT rule selection and inference of keys based on XPath expressions again reduces to containment.In this article we focus on the complexity of the containment problem of various fragments of XPath 1.0 using only the most common axes, / and //, and extensions in which variables can refer to data values.Furthermore, the containment problem relative to a given DTD is investigated.In all cases, we only consider the Boolean containment problem.Here, given two XPath expressions p and q, the problem asks whether the fact that p selects some path from the root to a vertex implies that also q selects some path from the root to a vertex.This restriction is justified as all complexity results we obtain easily transfer to unary and binary containment in the spirit of Proposition 1 in [27].
The XPath containment problem already attracted quite some attention [14,27,28,36,37,24].We next discuss the known results together with our own contributions.
A general result establishing a strong upper bound for a large fragment of XPath is due to Marx presented in [24].It is shown there that the containment problem for navigational XPath, allowing navigation along all axes, even relative to a DTD, is in exptime.
Other work has concentrated, like this article, on XPath expressions that can only navigate downwards in an XML tree and do not use the order between siblings, i.e., the fragment using only the / and // axis.Different fragments can be defined by allowing or disallowing the use of the wild-card * in node tests, and filter predicates in location steps.In the spirit of the abbreviated syntax of XPath we use / to indicate the use of the child axis, // for the descendant axis, * for the wild-card and [ ] for filter predicates.We denote XPath fragments by listing the allowed operators.For instance, XP(/,//,[ ]) denotes the XPath fragment with the child and descendant axes in which the use of filter predicates is allowed, but no wild-cards in node tests.
Contributions.The first family of fragments we consider is obtained by allowing disjunction (|) in filter predicates and in location steps.We show that, in principle, adding disjunction to XP(/,//, [ ], * ) does not make the containment problem harder.Surprisingly, when the set of allowed element names (labels) in XML documents is restricted, and given as part of the input then the containment problem becomes much harder: complete for pspace.The results on fragments with disjunction are shown in  1: The complexity of containment for expressions with disjunction.Square brackets refer to the references, parentheses to results of this article.
Deutsch and Tannen [14] consider XPath containment in the presence of DTDs and Simple XPath Integrity Constraints (SXICs) [14].Here, the input to the containment problem consists of two XPath expressions p, q, a DTD and/or a set of integrity constraints and it is asked whether p selects a subset of the elements that q selects, in all documents respecting the DTD and/or the constraints.They show that this problem is undecidable in general and in the presence of bounded SXICs and DTDs.When only DTDs are present they have a pspace lower bound and leave the exact complexity as an open question.
We indicate the presence of a DTD by XP(DTD,...).We give a simple proof that containment testing for XP(DTD,/,//,[ ], * ,|) is in exptime (although this result is covered by the above mentioned result of Marx [24]) and obtain that containment for XP(DTD,/,//,|) and for XP(DTD,/,//,[ ], * ) are hard for exptime.We also study the complexity of more restrictive fragments in the presence of DTDs.It turns out that containment of XP(DTD,/,//) is in PTime.On the other hand, containment of XP(DTD,/,[ ]) is conp-complete and containment of XP(DTD,//,[ ]) is conp-hard.It is not clear whether or how the upper bound proof in the former case can be extended to include, for instance, the descendant operator.The results about the containment problem in the presence of DTDs are summarized in Table 2 Table 2: The complexity of containment in the presence of DTDs.
The XPath recommendation allows variables to be used in XPath expressions on which equality tests can be performed.For instance, //a[$x = @b][$y = @c] selects all adescendants whose b-attribute equals the value of variable $x and whose c-attribute differs from the value of variable $y.However, under the XPath semantics the value of all variables should be specified by the outer context (e.g., in the XSLT template in which the pattern is issued).We indicate the use of variables with XPath semantics by XP(...,xvars,...).So the semantics of an XPath expression is defined with respect to a variable mapping.We show that the complexity of containment is pspace-complete under this semantics.For the lower bound, it suffices to observe that with variables a finite alphabet can be simulated.We obtain the upper bound by reducing the containment problem to the containment of several expressions without variables.
In addition to the XPath semantics, Deutsch and Tannen [14] considered an existential semantics for variables: an expression matches a document if there exists a suitable assignment for the variables.We denote variables with existential semantics by XP(...,evars,...).In [14] it is shown that containment of XP(/,//,[ ], * ,evars) and XP(/,//,[ ],|,evars) is Π P 2hard, and that containment of XP(/,//, [ ],|,evars) under fixed bounded SXICs is in Π P 2 .We extend their result by showing that containment of XP(/,//,[ ],|,evars, =), that is, inequality tests on variables and attribute values are allowed, remains in Π P 2 .Surprisingly, the further addition of * to this fragment makes the containment problem undecidable.The results about XPath containment for fragments with variables are indicated in Table 3 Further related work.In [37], Wood shows that containment of XP(/,//,[ ], * ) in the presence of DTDs is decidable.He also studies conditions for which containment under DTDs is in ptime.Benedikt, Fan, and Kuper study the expressive power and closure properties of fragments of XPath [2].They also consider sound and complete axiom systems and normal forms for some of these fragments.Hidders, and Benedikt, Fan, and Geerts considered the complexity of satisfiability of XPath expressions [18,1,15].The complexity of XPath evaluation has been studied by Gottlob, Koch, and Pichler in [16,17], while its expressive power has been addressed by Marx in [26] and [25].This article is based on [30].Organization.This article is organized as follows.In Section 2, we define DTDs and the basic XPath fragments.We also introduce the necessary machinery w.r.t.unranked tree automata.In Section 3, 4, and 5 we consider disjunction, DTDs, and variables, respectively.We conclude in Section 6.

Preliminaries
In this section, we define the tree abstraction of XML documents, DTDs and the fragments of XPath that we consider.
2.1.XML-trees.For the rest of this paper, we fix an infinite set Σ of labels and an infinite set D of data values.Only in Section 3.2, we consider XPath expressions over a finite alphabet.The set A is always a finite set of attributes.An XML document is faithfully modeled by a finite unranked tree with labels from Σ in which the attributes of the nodes have D-values and in which the children of each node are ordered.
It is common to model the underlying tree as a tree domain.To this end, the edges connecting a node with its children are numbered from 1 to n, according to the ordering of its children.Each path from the root to a node then corresponds to a sequence of numbers.Finally, each node is identified with this sequence.In particular, the root, which corresponds to the document node [9], is represented by the empty string denoted by ε.
More formally, a tree domain D is a finite subset of N * with the following closure properties: We also say that v is an ancestor of vu.Definition 2.1.An XML-tree (tree for short) is a triple t = (dom(t), lab t , λ t ), where dom(t) is a tree domain over N, and lab t : dom(t) → Σ and, for each a ∈ A, λ a t : dom(t) → D are partial functions.Intuitively, lab t (v) is the label of v, while λ a t (v) is the value of v's a-attribute, if it has one.
Of course, in real XML documents there can be vertices with mixed content, but these can easily be modeled by using auxiliary intermediate nodes as explained in [3].We consider attributes only in Section 5.
For a vertex v ∈ dom(t), we denote by t v the sub-tree of dom(t) rooted at v. As a tree domain in itself, this is the set {w | vw ∈ dom(t)}.
2.2.DTDs.We formalize Document Type Definitions (DTDs) as context-free grammars with regular expressions on the right-hand side of rules.As usual, we denote by L(r) the language defined by the regular expression r.
. We denote by L(d) the set of all trees that match d.
Note that DTDs do not constrain the value of attributes in any way.We usually refer to a DTD by d rather than by (d, S d , Σ d ).

2.3.
XPath.We next define the core fragment of XPath that we will consider in Sections 3 and 4. In our definition we follow Marx [23].In Section 5, we consider a larger fragment which allows the use of attribute values.We write |p| for the size of an XPath expression, which is the total number of occurrences in p of axes child and descendant (including those in filter expressions).
We use to denote a big disjunction of expressions.Note that, as we only consider expressions which navigate downwards in the tree, we do not allow absolute location paths, i.e., paths requiring to be evaluated from the root.For convenience, we further assume that location steps with the self-axis only occur at the top-level.This is no loss of generality, as one can always translate a location path of the form axis :: Of course, when σ = σ ′ are two labels in the above expression, then it is unsatisfiable.
For the definition of the semantics of XPath expressions we again basically follow [23].
Definition 2.4.For each tree t, each location path p induces a binary relation [[p]] t which is inductively defined as follows: • [[a :: ] t is the set of all pairs (u, v) for which all the following conditions hold: ] t (where • denotes the composition of binary relations); and, So, the semantics definition associates with every tree t and every expression p a binary relation.When the context vertex, i.e., the first vertex in pairs, is fixed to be the root then every expression defines the set {v | (ε, v) ∈ [[p]] t }.Recall that ε denotes the root of a tree.We say a tree t matches an expression p (written: t |= p) if there is some vertex v in t such that (ε, v) ∈ [[p]] t .In the latter case we interpret an expression p as a Boolean query.We denote sub-fragments of the above defined XPath fragment using the abbreviated syntax.We use the notations explained in Table 4.If filter expressions are not allowed, location steps are only of the form axis :: node-test.Disjunction is allowed in location paths and in filter expressions.If wild-cards are not allowed, every node-test has to be a label.

Symbol
We denote XPath fragments by XP(...) where inside the brackets the allowed features are listed.For instance, we write XP(/,[ ],|) for the fragment, where the wild-card is not allowed and the descendant axis can not be used.
In some proofs, we view expressions p from XP(/,//,[ ], * ) as tree patterns as described by Miklau and Suciu [27].For example, the expression a/b//c[d][ * /e] corresponds to the tree pattern in Figure 1.Single edge and double edge correspond to the child and descendant axis, respectively.We denote the tree pattern associated with an expression p by τ (p).
From this point of view, t |= p if and only if there is a homomorphism h from τ (p) to t, i.e., h maps the nodes of h(p) to the nodes of t such that (1) h(v) has the same label as v unless v carries a wild-card, (2) h(v) is a child (descendant) of h(u) if and only if v is a child (descendant) of u.So, h respects labels, child and descendant, and does not care about * .
Every tree pattern has one selecting node: all pairs (u, v) of nodes of the input tree are selected, for which the root of the tree pattern can be mapped to u and the selecting node to v.In Figure 1, the selecting node is labeled by x.We will frequently make use of the fact that every expression p from XP(/,//,[ ], * ,|) can be written in disjunctive normal form, i.e., in the form where each p i is an expression from XP(/,//,[ ], * ).It should be noted that n can be exponential in |p|.

Containment.
Corresponding to the three different interpretations of an XPath expression as a binary, unary or Boolean query, there are three different notions of query containment.
Definition 2.5.For two XPath expressions p and q, • p is contained as a binary query in q, denoted by p ⊆ 2 q, if [[p]] t ⊆ [[q]] t , for every tree t; • p is contained as a unary query in q, denoted by p ⊆ 1 q if, for each tree t and each vertex v of t, ] t ; and • p is contained as a Boolean query in q, denoted p ⊆ q, if, for every tree t, t |= p implies t |= q.
Definition 2.6.XContainment is the algorithmic problem to decide for two XPath expressions p and q, whether p ⊆ q.
For a DTD d and two XPath expressions p and q, by p ⊆ d q, we denote that t |= p implies t |= q, for all trees t that match d.Definition 2.7.XDContainment is the algorithmic problem to decide for two XPath expressions p and q and a DTD, whether p ⊆ d q.
The restriction to Boolean containment is justified: it is shown in [27] that for XP(/,//,[ ], * ) the complexity of deciding binary (or k-ary, for any k) containment is the same as the complexity of deciding Boolean containment.For binary queries, this result can be generalized to all fragments we consider in this article.More precisely: all complexity results stated in this article hold also for unary and binary containment.First of all, binary and unary containment are computationally equivalent in our framework as from a node v expressions can only navigate inside the subtree induced by v. Furthermore, to get from unary to Boolean containment, it is easy to see that the result in [27] only requires the child axes, i.e., only one node is added as a child of the selecting node of the tree pattern.It is straightforward to get the same statement also in the presence of a DTD.For the fragment XP(//,|) a similar approach works: for the label a of the selecting node a new label a ′ is introduced and every reference of a not-selecting node to a is replaced by a|a ′ .The lower bound we prove for XP(//,[ ]) also goes through for the binary and unary case.
2.5.Unranked tree automata.We recall the definition of non-deterministic tree automata over unranked trees from [4].These are used in the proofs of Theorem 4.1 and Theorem 4.4.We refer the unfamiliar reader to [29] for a gentle introduction.The alternating automata of Section 3.2 operate over ranked trees.
A run is accepting iff the root is labeled with an accepting state, that is, λ(ε) ∈ F .A tree is accepted if there is an accepting run.The set of all accepted trees is denoted by L(A).
The regular languages encoding the transition function of an NTA are represented by NFAs.The size of an NTA is then |Q| + |∆| plus the sizes of the NFAs.
A deterministic tree automaton (DTA) is an NTA where δ(q, a) ∩ δ(q ′ , a) = ∅ for all a ∈ ∆ and q = q ′ ∈ Q.The transition function of a DTA is represented by DFAs.
The following is well known.

Containment in the presence of disjunction
Miklau and Suciu showed that XContainment for XP(/,//,[ ], * ) is conp-complete [27].In this section, we consider the addition of disjunction to this fragment and show that XContainment remains in conp.The problem remains hard for conp even if only the child or only the descendant axis is allowed together with disjunction.Miklau and Suciu already mention these results but do not provide full proofs [27] (with exception of the lower bound for XP(/,|)).Therefore, we decided to include the proofs in this paper.
We were surprised by the fact that the conp upper bound strongly depends on the fact that the alphabet Σ is infinite.Let XFContainment be the containment problem, where additionally a finite set of labels is given as input and the containment only has to hold for documents with labels from this set.In Theorem 3.3, we show that even for XP(/,//,|) the problem XFContainment is hard for pspace.Proof.We develop a criterion which allows to check in np whether, for given expressions p and q, p ⊆ q.Let p and q be fixed and let p 1 | . . .|p l and q 1 | . . .|q l ′ be the disjunctive normal forms (DNFs) of p and q, respectively.Hence, each p i and q j is an expression from XP(/, //, [ ], * ).Let n and m denote the maximum number of nodes in an expression p i and q j , respectively.Let T (n, m) be the set of trees with at most 2n(m + 2) nodes that are labeled with symbols that occur in p and with the new symbol # not occurring in p nor in q.We prove the following claim: Clearly "⇐" holds.For the other direction we assume that there is a tree s matching p but not q.Then s has to match one of the p i .Hence, there is a homomorphism f from p i to s. i.e., h maps the nodes of the tree pattern of p i to the nodes of s such that (1) h(v) has the same label as v unless v carries a wildcard, ( 2 We construct t by transforming s in several steps.Let V denote the set of nodes of s in the image of f .We delete all nodes in s that are neither in V nor an ancestor of a node in V .The resulting tree, t 1 , has at most as many leaves as p i .We replace the labels of those nodes of t 1 which are not in V by # and obtain t 2 .Let V ′ be the set of branching nodes of t 2 , i.e., those nodes that have more than one child.The set V ′ contains at most n vertices.Let a pure path of t 2 be a path without nodes from V ∪ V ′ .In particular, the nodes of a pure path are all labeled with #.We get t by replacing in t 2 each maximal pure path with > m + 1 inner nodes by a path with m + 1 #-labeled inner nodes.We refer to the nodes of t which are inserted in this last step as special nodes.Clearly, there is a one-to-one correspondence between non-special nodes in t 2 and t.For a non-special node u in t, the corresponding node in t 2 is denoted by ũ. It is easy to see that t ∈ T (n, m), that t |= p i and that t contains at most m + 2 times We have to show that t |= q.Towards a contradiction assume that t |= q j , for some j.Hence, there is a homomorphism h : q j → t.Next, we show that h can be modified to obtain a homomorphism from q j to s which leads to the desired contradiction.We first define a homomorphism h 2 from q j to t 2 as follows.Whenever h(v) is a non-special node then h 2 (v) = h(v).
Let v 1 , . . ., v k be nodes of q j such that h(v 1 ), . . ., h(v k ) are special nodes which lie on some path of t 2 which consists entirely of special nodes, ordered from the root to the leaves.By the choice of m it holds that k ≤ m, therefore there must be an i such that h(v i+1 ) is not a child of h(v i ) or h(v 1 ) is not the first node of the path or h(v k ) is not the last node of the path.
In either case, we can define h 2 for nodes from {v 1 , . . ., v k } such that the child and descendant relations are respected.In this way, we get a homomorphism h 2 from q j to t 2 .
Clearly, all nodes of q j which are not mapped to nodes in V must be labeled with a * .Thus, h 2 also defines a homomorphism from q j to t 1 and to s, the desired contradiction.This completes the proof of the claim.
It remains to show how the criterion of the above claim can be used for an np-algorithm that checks whether p ⊆ q.The algorithm simply guesses an expression p i from the DNF of p (by non-deterministically choosing one alternative for each | in p) and a t ∈ T (n, m).Then it checks that t |= p i and t |= q.The latter can be done in polynomial time as shown in [17].
Proof.(a) The hardness proof is the same proof that shows that containment of regular expressions is conp-hard [20].We give it for completeness sake and because the next proof depends on it.We use a reduction from validity of propositional logic formulas in disjunctive normal form which is known to be complete for conp [20].Let ϕ = m i=1 C i be a propositional formula in disjunctive normal form over the variables x 1 , . . ., x n .Here, each C i is a conjunction of literals.For a disjunct C let C be the expression Let q be the disjunction of the expressions Ci , i = 1, . . ., m. Further, let p be the expression (0|1)/ • • • /(0|1) where (0|1) is repeated n times.Clearly, p ⊆ q iff ϕ is valid.(b) The reduction is similar to the one above except that we define C as a 1 //a 2 // • • • //a n , q as the disjunction of the expressions Ci , i = 1, . . ., m, and p as (0|1)// • • • //(0|1).We show that p ⊆ q ⇔ ϕ is valid.Suppose p ⊆ q, then in particular q matches every 0-1-string of length n, hence, ϕ is valid.To prove the converse direction, suppose ϕ is valid.If p matches a branch in a tree then there are in particular n positions with 0 or 1.The i-th such position can be seen as a truth assignment to x i .As ϕ is valid all possible assignments are accounted for by q, and q matches that branch.
3.2.Finite alphabet.As mentioned above, when the alphabet is finite, and given as part of the input, containment becomes much harder.In the rest of this section, Σ is therefore a finite alphabet.
Proof.We make use of a reduction from corridor tiling which is known to be hard for pspace [8].Let T = (D, H, V, b, t, n) be a tiling system.Here, D = {a 1 , . . ., a k } is a finite set of tiles; H, V ⊆ D × D are horizontal and vertical constraints, respectively; b = (b 1 , . . ., b n ) and t = (t 1 , . . ., t n ) are n-tuples of tiles; and, n is a natural number in unary notation.The question is whether there exists a number m and a valid tiling of a board with n columns and m rows.Here, a tiling is valid if the following conditions are fulfilled: • The bottom row is tiled with b.
• The top row is tiled with t.
• For each vertical pair (x, y) of tiles (y above x), (x, y) ∈ V .We use a string representation of the board where every row is delimited by # and the last symbol is $.The expression q selects all strings that do not encode a tiling.As Σ we take D ∪ {#, $}.For S = {c 1 , . . ., c n } ⊆ Σ, we abbreviate the expression (c For an expression r, r i denotes r/ • • • /r with i occurrences of r.The expression p is .//$assuring that the string contains the symbol $.The expression q is the disjunction of the following expressions.
• some row has the wrong format: -some inner row has too few tiles: n−1 i=0 .//#Di # -the first row has too few tiles: n−1 i=0 D i /# -the last row has not enough tiles: n−1 i=0 .//#Di /$ -some row has too many tiles: .//Dn+1 ; • $ occurs inside the string: .//$/(D∪ {$} ∪ {#}); • the string does not begin with b: Now, T has a solution iff p ⊆ q.Clearly, if T has a solution then we can take the string encoding of the tiling as a counter example for the containment of p and q.Conversely, if p ⊆ q then there is a, not necessarily unary, tree t with one branch s ending on a $ such that s |= p and s |= q.So, this branch encodes a solution for T .
Actually, in the proof of Theorem 3.3, the restriction to a finite alphabet is only used to express that a certain element name in the XML document does not occur in a certain set.Therefore, if we extended the formalism with an operator * ∈S for a finite set S, expressing that any symbol but one from S is allowed, then containment would also be hard for pspace.
For the upper bound we need the notion of alternating tree automata [33] which is defined next.These automata operate on trees where every node has rank at most k (for some fixed k).That is, every node has at most k children.
A configuration on a tree t is a tuple [u, q] where u ∈ dom(t) and q ∈ Q.An accepting run of A on t is a tree s where nodes are labeled with configurations such that the root of s is labeled with [ε, q 0 ], where ε is the root of t and, for every node u of s (including leaf nodes), the following local consistency condition holds.Let u be labeled with [v, q] with n children labeled [v 1 , q 1 ], . . ., [v n , q n ].Then it must hold that • each v i is a child of v or v itself; and, • δ(q, lab t (v), m) is satisfied by the truth assignment ρ, where m ≤ k is the number of children of v in t, and ρ((ℓ, q ′ )) is true if for some i, q i = q ′ and v i is the ℓ-th child of v (where we view v itself as the 0-th child).A tree is accepted by A if there is an accepting run.By L(A) we denote the set of trees accepted by A.
Note that ATAs as we defined them do not have final states.These are encoded by transitions of the form δ(q, σ, 0) = true.Proof.We show first that p ⊆ q implies that there is a counter example tree with small degree and only a few branching nodes.More precisely, we call a tree k-bounded if it has at most k non-unary nodes (that is, nodes with more than one child) and every node has rank at most k.For an XP(/, //, [ ], * , |) -expression p let f (p) be the maximum number of filter expressions in any disjunct of the DNF of p.We claim that p ⊆ q if and only if t |= p implies t |= q on the class of f (p)-bounded trees.
Indeed, suppose there is a t such that t |= p and t |= q.Let the DNF of p and q be p 1 | • • • |p n and q 1 | • • • |q m , respectively.Thus, for some i, t |= p i , but t |= q j , for all j.Let h be a homomorphism from p i to t and let s be the tree obtained from t by deleting all nodes that are neither in the image of h nor ancestors of such nodes.Clearly, s is f (p)-bounded, s |= p i and s |= q j for all j (otherwise, t |= q j ).
Next, we show that for every XP(/, //, [ ], * , |) expression p there is an ATA A p such that for every f (p)-bounded tree t, t |= p iff A p accepts t.Moreover, A p can be constructed in logspace.
To this end, let p be an XP(/, //, [ ], * , |) expression.As the alphabet is finite and fixed, we can replace every * with a disjunction of the alphabet symbols.Hence, we assume p does not contain * .Let k = f (p).We define A p = (k, Q, Σ, q 0 , δ) where q 0 = p and Q is the set of sub-expressions of p, all filter expressions of p and all node tests of p. Intuitively, a pair [v, q] in an accepting run of A p on a tree t means that q holds in the sub-tree of t rooted at v. For all m ≤ k, the transition function is inductively defined as follows: • δ(self :: The combinations δ(p, σ, m) that are not mentioned are false.For location paths of length 1, i.e., if in one of the first three transitions there is no p ′ , the atoms (0, p ′ ) or (j, p ′ ) are removed, respectively.It is straightforward to prove by a nested induction on the structure of the tree and the expression that the pairs [v, q] have the intended meaning.Therefore, a tree t has an accepting run of A p if and only if t |= p.
Thus, to decide p ⊆ q it is sufficient to test whether every f (p)-bounded tree accepted by A p is also accepted by A q .Note that f (p)-bounded trees can be easily encoded by strings.We say that a node is a fork if it has more than one child.As there are at most f (p) forks, every tree consists of at most k := f (p) × f (p) unary paths that are joined at the at most f (p) forks.To every path we associate its lower fork (or none if there is no such fork).Next, we assign a unique number to each path such that higher paths get lower numbers.Let s i be the concatenation of the labels on path i and let i 1 , . . ., i ℓ be the paths rooted at the fork below branch i.Let a i := s i i 1 • • • i ℓ #.Every f (p)-bounded tree t can then be encoded by the string a 1 • • • a m .Let A ′ p and A ′ q be the alternating string automata that simulate A p and A q on the string representations of bounded trees.Basically, whenever the automaton reaches the end of (the encoding of) a path, the numbers i 1 , . . ., i ℓ indicate the positions of the children paths and it can reach a path i j by skipping everything before its occurrence.This is possible as all paths are ordered and higher numbered paths occur to the right.Finally, let A be the automaton that checks whether the input string is a valid encoding of a bounded tree.The problem then reduces to testing whether A ∩ A ′ p ∩ ¬A ′ q is empty.The latter can be done in pspace [7].We arrive at the desired result.

Containment in the presence of DTDs
In this section we study the XDContainment problem, i.e., the containment problem relative to a DTD.Deutsch and Tannen [14] show a pspace lower bound for XDContainment for XP(/,//,[ ], * ,|).Marx [24] gives an exptime upper bound for a much larger fragment, including all axes and negation in filter expressions.
We show here that XDContainment for XP(/,//,[ ], * ,|) problem is actually exptimecomplete.We also exhibit a simple fragment with tractable XDContainment and a modest np-completeness result on the fragment using only / and [ ].We do not know how to extend the upper bound proof to include // or * .The results of this section are summarized in Table 2.
We illustrate by a simple example that the presence of a DTD can complicate matters.Consider the DTD and the expressions p = a/a and q = .//b/c.Although p and q are seemingly unrelated and, in particular, it is not the case that every path matching p also matches q, it holds that each tree which respects the DTD and matches p also matches q.
We remark that it can be tested in polynomial time whether, for a DTD d and a symbol a, there exists a tree t ∈ L(d) with a vertex labeled a.Therefore, we assume in the following that each input DTD contains only useful symbols.In particular, for each d and each symbol a ∈ Σ d , there is a tree valid with respect to (d, a, Σ d ).

4.1.
A tractable fragment.We start with a fragment in p. Proof.Let d be a DTD and p, q be expressions of XP(DT D, /, //).
We first show how to construct a non-deterministic top-down automaton A p which checks that, for a tree t, t |= p holds.To this end, let p = p 1 //p 2 // • • • //p k , where in each p i only the child axis is used.For each i, let p i contain i ℓ child-axis location steps.
Intuitively, A p guesses a path in t which matches p and, for each node v on this path it maintains the lexicographically maximal (i, j) such that the path from the root to v matches the expression p 1 // • • • //p i−1 //p j i , where p j i consists of the first j location steps of p i (along the child-axis).
It should be stressed here, that A p needs non-determinism only to guess the path.The computation of the pairs (i, j) is completely deterministic and similar to the case of the standard string pattern matching automata [32].The automaton, A p enters an accepting state on the leaf u of the distinguished (guessed) path if and only if the computed pair for u is (k, i k ).On all other leaves it takes an accepting state in any case.
An automaton A q which accepts all trees that do not match q can be constructed along the same lines.It computes a pair (i, j) with the same intended meaning as above, for every node v of the tree and takes an accepting state at all leaves that have not reached (k, i k ).This automaton is actually deterministic.
By combining A p with A q and the canonical non-deterministic automaton A d which tests t |= d, we obtain an automaton which accepts all counterexamples to p ⊆ d q.As this automaton is of polynomial size in p, q, d and testing emptiness of non-deterministic tree automata is in ptime (Lemma 2.9(1)), we obtain the stated upper bound.
It should be mentioned that in [30] we claimed that XDContainment of XP(DT D, /, //, * )-expressions is in p.Unfortunately, we were not able to extend the proof sketch given there into a complete proof.In fact, we conjecture that this problem is conp-hard.Proof.The obvious idea is to guess a tree t which matches P but not q.A complication arises from the fact that the smallest such tree t might be of exponential size due to the constraints from d.Thus, we give a non-deterministic algorithm CheckPnotq (d, a, P, q) which checks, given a DTD d, a non-terminal a of d, a set P = {p 1 , . . ., p n } of XP(/, [ ])expressions, and an XP(/, [ ])-expression q, whether there is a tree t with root symbol a which conforms to d, matches all expressions in P but does not match q.But it does not explicitly construct such a tree.Clearly, invoking this algorithm with d, q, P = {p} and a as the start symbol of d checks whether p ⊆ d q.We note that we allow a set P of expressions as input for CheckPnotq because the algorithm uses such sets for recursive calls.
Algorithm CheckPnotq makes use of two algorithms with slightly simpler tasks.Algorithm CheckP checks on input d, s, P whether there is a tree t with root s conforming to d which contains all the expressions from P .Algorithm Checknotq checks on input d, q whether there is a tree conforming to d with a root labelled by the root symbol of q which does not match q.
We assume in the following that all labels of P and q occur in d and that d only contains symbols from which a tree can be derived.By s(p) we denote the root symbol of an expression p, i.e., the label of the root of τ (p).A level 1 sub-expression of an expression p is an expression corresponding to a child of the root in τ (p).Let l denote the overall number of depth-1-nodes in expressions of P .
The algorithms are given in Figure 2. The algorithms follow a top-down approach and work recursively.The correctness can be shown by induction on the number of recursive calls.Checknotq and CheckP are quite straightforward.
An important point is that in CheckP it is sufficient to consider strings u of length at most (|d| + 1)(l + 2).It can be shown by a simple pumping argument that if a tree matching Checknotq(d, a, q) (Returns TRUE if there exists a tree with root a which does not match q) 1.If s(q) = a return TRUE. 2. If τ (q) has only one node return FALSE.3. Guess a string u ∈ d(a) of length ≤ |d| and a level 1 sub-expression q ′ of q. 4. If b := s(q ′ ) does not occur in u return TRUE. 5.Return Checknotq(d, b, q ′ ).
CheckP(d, a, P = {p 1 , . . ., p n }) (Returns TRUE if there exists a tree with root a matching all p i ) 1.If some expression in P does not have the root symbol a return FALSE.2. Guess a string u ∈ d(a) of length ≤ (|d| + 1)(l + 2). 3.For each i ∈ {1, . . ., n}, guess a mapping f i from the level 1 sub-expressions of p i to the positions of u. 4. For each position j of u, which is in the image of at least one of the mappings f i (a) Let P ′ be the set of level 1 sub-expressions p with f i (p) = j.(b) Call CheckP(d, u j , P ′ ). 5. Return TRUE iff all the recursive calls return TRUE.
CheckPnotq(d, a, P = {p 1 , . . ., p n }, q) (Returns TRUE if there exists a tree with root a matching all p i but not q) 1.If some expression in P does not have the root symbol a THEN return FALSE.2. If s(q) = a return CheckP(d, a, P ). 3. If τ (q) has only one node return FALSE.4. Guess a level 1 sub-expression q ′ of q. 5. Guess a string u ∈ d(a) of length ≤ (|d| + 1)(l + 2).6.If b := s(q ′ ) occurs in u call CheckPnotq(d, b, ∅, q ′ ). 7. For each i ∈ {1, . . ., n}, guess a mapping f i from the level 1 sub-expressions of p i to the positions of u. 8.For each position j of u, which is in the image of at least one of the mappings f i (a) Let P ′ be the set of level 1 sub-expressions p with f i (p) = j.(b) Call CheckPnotq(d, u j , P ′ , q ′ ). 9. Return TRUE iff all the recursive calls return TRUE.P has a level with more children then there is a sub-sequence of these children which is not in the image of any mapping and can be removed without leaving d(a).
CheckPnotq is basically a combination of Checknotq and CheckP.It has to check that there is a path in q which does not match any path in the counter-example tree.Step 6 is needed to verify that this also holds in those parts of the tree which are not needed to fulfil P .
For the case without a sub-expression p ′ the first three rules are adapted in the obvious way.
For each expression p, p ∈ D if p ∈ S i ∪ D i , for some i.
It remains to describe how a DFA B of exponential size can execute the above rules.There is a linear number of sub-expressions of p and self-closures of those.The DFA B keeps for each of them one bit in memory indicating whether the corresponding expression is in S or D. Initially none of them are.An expression is put in a set if one of the above rules fire.Every rule should be checked at every transition step.So, the size of each B is exponential in p.As A p contains an exponential number of such DFAs, its size is also exponential.
Let A d be the exponential size deterministic automaton accepting d (cf.Lemma 2.9(3)).Then deciding whether p ⊆ d q reduces to testing whether L(A d ) ∩ L(A p ) ⊆ L(A q ).By Lemma 2.9(2), the latter can be done in exptime.Proof.The proof makes use of a reduction from two-player corridor tiling.This is the extension of corridor tiling, used in the proof of Theorem 3.3, to two players.Let T = (D, H, V, b, t, n) be a tiling system.Again, D is a finite set of tiles; H, V ⊆ D × D are horizontal and vertical constraints, respectively; b and t are n-tuples of tiles; and n is a natural number.There are two players (I and II) that place tiles in turn on an n × N board.On this board the bottom row is tiled with b.Player I starts on the first square of the second row from the bottom.Each player in turn places a tile on the next free square going from left to right and from bottom to top.While player I tries to construct a corridor tiling from b to t, player II tries to prevent it.If player II places a tile which is not consistent with respect to the horizontal and vertical constraints then player I can answer with a special tile '!'.Player I wins if a tiling is constructed satisfying the horizontal and vertical constraints with the top row tiled with t, or if she answers an inconsistent tile placed by II with '!'.We say that player I has a winning strategy if she can always win no matter how II plays.It is well-known that it is exptime-complete to determine whether I has a winning strategy [8].This result even holds if the number of tiles in a row is forced to be even.Thus we assume in the following that n is even.
We encode strategies for player I as trees.For each position in the game in which II moves, the tree contains all possible moves of player II and, for each I-position, it contains only one move.Thus, such a tree encodes a winning strategy if and only if each path corresponds to a correct tiling or to a wrong move of II.
To this end, we use symbols of the form (a, i), where a ∈ D and i ∈ {1, 2} plus some additional auxiliary symbols: $ to indicate the borders between rows, # to mark the end of a tiling and the "protest symbol" '!'.Inner nodes of the tree correspond either to moves of I or II.Nodes corresponding to I are labeled (a, 1) where a is the tile chosen by I in this move.They have one child for every tile corresponding to the possible next moves of II.
Nodes corresponding to II are labeled (a, 2) and have only one child which is the unique answer move of I according to her strategy or one of $, # or '!'.Nodes with label $ have one child corresponding to a move of I. Nodes with label # or '!' are leaves.The root of the tree is labeled S and represents an empty (dummy) move which has to be answered by I.It has one child.On each path from the root, I-nodes and II-nodes alternate (when we ignore the intermediate $ nodes).Now we describe the reduction in more detail.Let D = {d 1 , . . ., d m }.We use the following DTD f which defines all possible strategy trees for player I: and for every d ∈ D, we have the rules Note that # and '!' are the only terminal symbols.Thus, each path in the tree either ends with # or '!'.
A derivation tree encodes a strategy tree (or game tree) for I.As the bottom and the row are fixed we do not represent them in these trees, i.e., only intermediate rows are represented.We assume that the tiling consisting only of the top and bottom row is not valid.Therefore any strategy tree has to represent at least one row.
We have to check whether there is a tree encoding a valid strategy tree for I.We will construct an expression q which selects a tree if and only if it does not encode a winning strategy for I. Thus, S ⊆ f q if and only if player I has no winning strategy.
We define q := q n tiles | q V | q H | q !, where the sub-expressions on the right hand side will be defined shortly.Intuitively, q n tiles expresses that some row has a wrong length (which can only be due to player I), q V and q H express that some vertical or horizontal constraint, respectively, is violated by I, and q !expresses that I used the protest symbol wrongly.Each of these sub-expressions identifies an error in the strategy tree.Hence, if every tree matches one of these expressions, every tree contains an error and no tree can be a valid strategy tree.
Note that, although the expressions under consideration do not have the wild-card available, the disjunction of all alphabet symbols defined by the grammar is a kind of wildcard as the DTD assures that no other symbols occur in the tree.We denote the set of all pairs (σ, i), where σ is a tile and i ∈ {1, 2} by Σ. Further, we denote by Σ $ the set Σ ∪ {$}.
Three types of errors can occur in a strategy tree: (1) the tree is of the wrong shape; (2) player I places an inconsistent tile, or (3) player I uses the symbol '!' although II placed a correct tile.
A row does not contain exactly n tiles.: Recall that we use D as a shortcut for Vertical Constraints are violated.: where checks the vertical constraints w.r.t.b, and .//(d, 1)/Σ n−i /#, checks the vertical constraints w.r.t.t.Horizontal Constraints are violated.: Wrong use of '!'.: This expression takes care of the case that player I uses the protest symbol '!' although the last tile placed by player II was consistent with the vertical and horizontal constraints.The second disjunct in this expression takes care of the first row of the game (i.e., the second row in the tiling).
By similar techniques, making use of the techniques of Lemma 3 in [27], it can be shown that XDContainment for XP(/, //, [ ], * ) is hard for exptime.
The outermost union can be handled as in Lemma 3 of [27].Of course, the DTD has to be adapted accordingly.

Containment in the presence of variables
In this section, we study Boolean containment of XPath expressions which allow the comparison of attribute values.More precisely, in this section we consider XPath expression generated by the following grammar.A variable x is denoted as $x, an attribute a as @a.In this section, fragments without filter expressions still allow sub-expressions of the type vexpr.Furthermore, fragments without filter but with disjunction allow disjunctions of sub-expressions of type vexpr (cf.Theorem 5.3(c)).
We consider two different semantics.The original XPath semantics and the existential semantics, introduced in [14].
In the XPath semantics, variable bindings are defined in an outer context.In particular, the value of an expression is defined with respect to a variable assignment ρ : X → D where X is the set of all variables.We denote the truth value of a filter expression e relative to a variable assignment ρ and a vertex v by E ρ t (v, e) and the semantics of an XPath expression p by [[p]] ρ t .Formally, we extend Definition 2.4 as follows.Given a tree t, a node v, an attribute a and an assignment ρ, t is then defined accordingly and we write t t .Deutsch and Tannen [14] consider a different semantics which does not assume an external variable binding but rather allows a choice of values for the variables that makes the expression match.More formally, t |= p under existential semantics, if there is a variable assignment ρ and a vertex v of t such that t |= ρ p.We will write this as t |= ∃ p.
We denote the allowance of variables under XPath semantics by xvars and under the existential semantics by evars; the presence of inequalities with variables is denoted by =.For instance, XP(/, //, xvars, =) denotes the XPath fragment with / and //, together with variable equality and inequality under the XPath semantics.
We define Boolean containment of XP-expressions with attribute values correspondingly.More precisely, under the XPath semantics, p ⊆ q holds, if for every tree t and every variable assignment ρ, t |= ρ p implies t |= ρ q.Under the existential semantics, p ⊆ q if for every tree t, if there is ρ such that t |= ρ p then there is also a variable assignment π such that t |= π q.
In the first subsection, we show that adding variables under XPath semantics to the basic XPath fragment with disjunction results in a XContainment problem with pspace complexity.
Adding variables with XPath semantics to the basic fragment with disjunction but without wild-card gives a Π P 2 -complete XContainment problem.Surprisingly, adding wildcard to this fragment ends up in an undecidable XContainment problem.
The results of this section are summarized in Table 3.
For a set X of variables an equality type e is an equivalence relation on X. Intuitively, e describes which variables have the same value.Proof.We basically show that the problem can be reduced to the case without variables.Let p and q be two expressions with variables {x 1 , . . ., x k } and let Σ ′ be the set of element and attribute names which appear in p or q (and which we assume to be disjoint).Let Σ = Σ ′ ⊎ {#}.Clearly, p ⊆ q holds in general if and only if it holds for trees with element names from Σ.For each equality type e of the variables x 1 , . . ., x k , we construct two expressions p e and q e in XP(/, //, [ ], |, * ).By construction it then follows that p ⊆ q if and only if, for every equality type e, p e ⊆ q e .As we can cycle through all equality types e and construct each p e and q e in pspace, and each single test will be doable in pspace, the complexity of the overall algorithm is pspace.
Let us first consider the equality type e where all variables are pairwise different.With every tree t and every variable assignment ρ of type e, we associate a tree t ρ over the alphabet Γ = Σ ∪ {x 1 , . . ., x k , none} as follows.We add, for each attribute a of a node v, a new child of v labeled by a which itself has a child which is labeled by one of x 1 , . . ., x k or with none depending on @a.More precisely, if @a equals some ρ(x i ) then the grandchild of v is labeled by x i otherwise by none.
Correspondingly, we construct p e by replacing in p each subexpression $x i = @a by ./a/xi and each $x i = @a by ./a/( We construct q e from q in the same way.It is easy to see that, for each t, and each variable assignment ρ of type e, t |= ρ p if and only if t ρ |= p e . Thus, it remains to test whether, for all trees of the form t ρ , t ρ |= p e implies t ρ |= q e .This can be done along the lines of the proof of Theorem 3.5.In particular, it is sufficient to consider only f (p e )-bounded trees.
This completes the description of the algorithm for equality type e. If, for some other equality type, two variables get the same value then we can replace one of them by the other in p and in q.Hence, we get possibly fewer variables which are again pairwise different.
We show that the pspace upper bound is tight in the general case and exhibit some lower bounds for restrictions of the formalism.Proof.The proofs of (a) and (b) are by reduction from the set of unsatisfiable 3SATformulas.To this end let ϕ = ϕ 1 ∧• • •∧ϕ k be a 3CNF formula where each ϕ i is a disjunction l i1 ∨ l i2 ∨ l i3 of 3 literals.Let x 1 , . . ., x m be the variables occurring in ϕ.In both cases, intuitively we construct from ϕ an expression p that, describes all (tree representations of) possible truth assignments to the literals of ϕ.The expression q selects a truth assignment if it leaves at least one clause unsatisfied.Thus, ϕ is unsatisfiable iff p ⊆ q.
More precisely, both reductions map ϕ to expressions with variables y and y 1 , . . ., y m .The value ρ(y) represents true, the other variables represent a truth assignment to x 1 , . . ., x m in the obvious way: x i is true iff ρ(y i ) = ρ(y).
In the trees we are interested in, the root a-attribute carries the data value corresponding to true and each literal l ij is represented by one node v ij with an attribute a and label b.Expression p tests that the attribute values of these nodes are consistent with the truth assignment induced by the y l : this is checked by variable expressions v(l ij ) which are $y l = @a if l ij = x l and $y l = @a if l ij = ¬x l .(a) In case of XP(/, [ ], xvars, =), the trees selected by p have one path of length 3, for each clause.To this end, let, for each i, p i be the sub-expression and let p be Thus, t |= ρ p guarantees that t has, for each clause ϕ i , a path in which the j-th node (j = 1, 2, 3) has an attribute value consistent with the truth value of l ij , as induced by ρ.
Thus, formula ϕ is unsatisfiable, if every tree which "passed" p has a path of length 3 in which all induced truth values are false.To this end, we define (b) Recall that in XP(/, //, vars, =) sub-expressions of the forms [$y = @a] and [$y = @a] are allowed.As XP(/, //, vars, =) can not refer to branches of a tree, in this case, the vertices v ij have to be organized in a linear fashion.Basically, in the construction of (a), we replace the general [ ] subexpressions in p by using // in q.To this end, the trees matched by p need to have a path of length 4k with label pattern (cbbb) * .The i-th subpath labeled cbbb corresponds to ϕ i .Thus, By a similar reasoning as in (a) it follows that ϕ is satisfiable if and only if p ⊆ q.(c) We use basically the same construction as in Theorem 3.3.Let D = {σ 1 , . . ., σ k } be the alphabet used in that construction and assume without loss of generality that k = 2 l , for some l.We use attributes a 1 , . . ., a l and one variable x to encode the symbols of D.More precisely, a 1 , . . ., a l and x represent σ b , if, the i-th digit of b is 1 exactly if x = a i .The remaining symbols $ and # are still represented by labels.In the expressions p and q the element tests are replaced by the wild-card symbol together with the respective attribute comparisons.
5.2.Existential semantics.Now we turn to XContainment in the context of existential semantics for variables.In some cases the complexity does not change as to compared with the XPath semantics, but in others it raises considerably, even leading to undecidability for XP(/,//, [ ], * ,|,evars, =).We first describe how we represent a relational database D by a tree t D .The root is labeled with S and for every relation R in D and every tuple (d 1 , . . ., d n ) in R it has a child labeled R with n attributes @1, . . ., @n, where, for each i, @i has the value d i .
A BCQ is a conjunction of relational atoms R(x 1 , . . ., x k ), and, in case of (b), inequalities x = y.Note that atoms of the form x = y can be eliminated as each variable must occur in a relational atom.An atom R(x 1 , . . ., x k ) can be represented by the subexpression We can not represent an inequality x = y by an expression [$x = $y], as variables can only be compared with attributes.Nevertheless, as x must occur as the i-th entry in a relational atom, we add [y = @i] to the expression for L.
We illustrate the construction with an example.For instance, if The proof of (c) is by a reduction from ∀∃-3SAT [31].Note that the fragment XP(/, |, evars) allows the use of disjunction of variable-attribute comparisons. Let with variables from {x 1 , . . ., x m , y 1 , . . ., y m }.Intuitively, the ∀∃-structure of a formula will be mimicked by a for all trees there is a variable assignment statement.Hence, the values for x 1 , . . ., x m will be encoded in the trees, the values for y 1 , . . ., y m will be given by the variable assignment.
Each tree satisfying p have two root attributes @T and @F which represent the truth values true and false, respectively.Note that, as there are no inequalities available, there will be no guarantee that the values of T and F are different.We only make use of the node label b.With every path of length m which starts immediately below the root we associate a (partial) truth assignment as follows: if the c-attribute of the i-th node equals the value of the attribute T , we set ρ( The expression p is designed to guarantee the existence of such a path.To this end, p is b[$z 1 = @T ][$z 0 = @F ]/p 1 / • • • /p m , where, for each i, p i = b[$z 1 = @c or $z 0 = @c].Intuitively, the variables z 0 and z 1 are used to transport the values true and false in the tree.
So far, each tree t with t |= ∃ p induces at least one truth assignment for x 1 , . . ., x m .Expression q checks that • z 1 and z 0 take the values @T and @F at the root, respectively, • each (XPath) variable x i has a truth value corresponding to the value of the i-th node of some path of the tree, • each (XPath) variable y i is either @T or @F, and • the induced truth assignment makes θ true.To this end, q where each e i is a variable expression corresponding to θ i .As an example, if Now it is easy to see that ϕ holds iff p ⊆ q with respect to the existential semantics.Note in particular that trees for which @T = @F at the root fulfill q whenever they fulfill p.Clearly, w is not syntactically correct or does not represent a solution if and only if one of the above conditions holds.
To get rid of the DTD, we add disjuncts to q ′ that capture violations of the DTD.However, to this end we need to express that children of a node cannot have a certain label.As we can not express this kind of negation directly, we encode labels of nodes by equality types of attribute values.So, let L := {ℓ 1 , . . ., ℓ m } be the set of all the labels we need.Every node now has m attributes a 1 , . . ., a m .If for a node, j ≥ 1 is the largest number such that the value of a 1 equals the value of a j then the node is considered as labeled with ℓ j .One can match a node labeled with ℓ j by checking the corresponding equality type: for instance, by an expression of the form * [$x 1 = @a 1 ][$x 2 = @a 1 ] • • • [$x j−1 = @a 1 ][$x j = @a 1 ].
Clearly, when using this approach we can express that a certain node is not labeled by a certain label.For every rule a → b 1 | • • • | b k in the DTD we add the disjunct //a/c to q ′ where c ∈ L \ {b 1 , . . ., b k }.When we write //a/c, we of course mean XPath expressions taking labels into account as specified in the manner above.Let q be obtained from q ′ by adding all the disjuncts from the DTD and replacing all references to labeling by references to encoding with attributes.Note that now we allow arbitrary trees as well.
It remains to argue that p ⊆ q iff the PCP instance has a solution.When there is a solution to the PCP then clearly the encoding of this string will match p but not q.Suppose that there is a tree that matches p but not q.This means that no error occurs on any path in the tree.Therefore, every path is an encoding of a solution to the PCP instance.

Discussion
The article studied the complexity of the containment problem for a large class of XPath expressions.In particular, we considered disjunction, DTDs and variables.Unfortunately, the complexity of almost all decidable fragments lies between conp and exptime.On the other hand, the size of XPath expressions is rather small.As pointed out, Deutsch and Tannen, and Moerkotte already obtained undecidability results for XPath containment.We added modest negation ( =) and variables with the existential semantics.In [30] a corresponding result is shown in the presence of node-set equality.However, the reduction employs XPath expressions with absolute filter expressions which fall outside the scope of the present paper.It would be interesting to have a precise classification of which combination of features makes the problem undecidable.
Although the complexity has been settled for a lot of fragments of XPath with child and descendant axes, the picture is by no means complete.A particular case that remains open is the case of XP(DTD, /, //, * ).
Corresponding results in the presence of other axes remain to be investigated.Besides the general upper bound of Marx [24] for navigational XPath with all axes, few precise results are known.Work on satisfiability of XPath with the sibling axis has been done by Fan and Geerts [15].

Table 3 :
The complexity of containment in the presence of variables.Note that xvars and evars refer to the original XPath semantics and to existential semantics, respectively.
Definition 2.2.A DTD is a tuple (d, S d , Σ d ) where Σ d is a finite subset of Σ, S d ∈ Σ d is the start symbol, and d is a mapping from Σ d to the set of regular expressions over Σ d .A tree t matches a DTD d iff lab t (ε) = S d and for every u ∈ dom(t) with n children, lab t otherwise n is * and the label of v can be arbitrary; and, -E t (v, e i ) is true, for each i ≤ k.Here, E t is defined as follows: * E t (v, p) is true for a vertex v and a location path p if and only if there is a vertex w such that (v, w) ∈ [[p]] t .* E t (v, e 1 or e 2 ) is true for a vertex v if and only if E t (v, e 1 ) or E

Table 4 :
Symbols used in the notation for XPath fragments.
Clearly, for a database D, D |= Q if and only if t D |= ∃ p Q .On the other hand, from each t (even if it is not of the intended form) we can define, in a straightforward manner, using all correctly encoded tuples, a database D(t) such that D(t) |= Q if and only if t |= ∃ p Q .Thus, for BCQs Q 1 and Q 2