On the data complexity of consistent query answering over graph databases

Areas in which graph databases are applied - such as the semantic web, social networks and scientific databases - are prone to inconsistency, mainly due to interoperability issues. This raises the need for understanding query answering over inconsistent graph databases in a framework that is simple yet general enough to accommodate many of its applications. We follow the well-known approach of consistent query answering (CQA), and study the data complexity of CQA over graph databases for regular path queries (RPQs) and regular path constraints (RPCs), which are frequently used. We concentrate on subset, superset and symmetric difference repairs. Without further restrictions, CQA is undecidable for the semantics based on superset and symmetric difference repairs, and Pi_2^P-complete for subset repairs. However, we provide several tractable restrictions on both RPCs and the structure of graph databases that lead to decidability, and even tractability of CQA. We also compare our results with those obtained for CQA in the context of relational databases.

section_content: Query languages for graph databases are typically navigational, in the sense that they allow for recursively traversing the labeled edges while checking for the existence of a path whose label satisfies a particular regular condition (see, e. g., [39, 5] ). The basic building block for navigational languages over graph databases is the class of regular path queries, or RPQs [14]. Each RPQ is a regular expression L, and its evaluation L(G) over a graph database G corresponds to a binary relation that contains all pairs of nodes in G that are linked by some path whose label matches L. The evaluation problem for RPQs can be solved in NLogspace in data complexity; that is, when the RPQ is fixed (cf., [5] ). 

Although graph databases are schema-less, it is possible to enforce data consistency over them using path constraints [1, 9]. These constraints have been used in several scenarios that are based on the graph database paradigm, e. g., to express local knowledge about semi-structured data [1] ; to enforce restrictions over object-oriented databases, XML and RDF [36, 12, 22, 3, 30] ; and to capture ontological hierarchies in the context of description logics (DLs) [16, 17]. Here we concentrate on a simple class of path constraints based on RPQs that was introduced by Abiteboul and Vianu; namely, the regular path constraints, or RPCs [1]. An RPC is an expression of the form L 1 L 2, where L 1 and L 2 are RPQs. In the graph database and DL contexts, a graph database G satisfies L 1 L 2 if and only if L 1 (G) ⊆ L 2 (G) [26, 16, 17] (but we also consider a more restrictive semantics for RPCs, motivated by their application over semi-structured data, following the original proposal of Abiteboul and Vianu). RPCs are a constituent part of the semantics of graph data and can also be used in the optimization process for RPQ evaluation [1]. 

An important problem when dealing with dependencies is that databases might be inconsistent, i. e., the databases might fail to satisfy the integrity constraints. In the case of graph database applications, high levels of inconsistency appear due to interoperability and distribution (e. g., in RDF and social/scientific networks [27, 40] ). As an example, inconsistency might arise while integrating several sources into a single RDF graph, or while performing statistical inference on a scientific or social network. This raises the need for developing an inconsistency-tolerant semantics for graph databases in a simple yet general framework that abstracts away from its many implementations. In order to tackle this problem, we use the widespread approach of consistent query answering (as first introduced in the seminal work of Arenas, Bertossi and Chomicki [2] ), which we now describe. 

The approach is based on the notion of repair, which represents a possible minimal way in which consistency over the data could be restored. More formally, a repair is a database that satisfies the constraints and "minimally differs" from the original database. In general, a database does not admit a unique repair. This leads to an inconsistency-intolerant semantics based on the consistent answers of a query, i. e., the answers that hold in every possible repair. The problem of computing consistent answers to a query is known as consistent query answering (CQA). 

Here we study the data complexity of CQA over graph databases in the scenario in which queries are RPQs and constraints are RPCs. That is, we study the complexity of evaluating consistent answers over an inconsistent graph database G for a fixed RPQ L under a fixed set Γ of RPCs. We explain next the context and main contributions of our work. 

The context. The complexity of CQA has received considerable attention over different data models, notions of repairs and classes of constraints. Under the relational model, for instance, this problem has been studied for set-based [2, 18, 24], cardinality-based [29], and attributebased repairs [37] ; for constraints expressed as traditional functional dependencies, inclusion dependencies and denial constraints (see, e. g., [11, 19, 25, 38, 28, 24] ); and for constraints expressed as tuple-generating dependencies (tgds) and equality-generating dependencies (egds) that arise in the context of data integration and data exchange [18]. 

CQA has also been studied in depth in the DL context, starting from the work of Lembo and Ruzzi [31]. The DL semantics is open-world in nature, meaning that the non-presence of a fact is not sufficient to ensure that the negation of the fact holds. This implies that in the DL context the only meaningful set-based repairs are the subset repairs; i. e., those that allow to restore consistency with respect to the DL constraints (i. e., the ones in the TBox) only by deleting facts from the database (i. e., the ABox). It is worth mentioning that the notion of DL repair is slightly different to its relational counterpart: A DL repair is not a subinstance that satisfies the constraints in the TBox, but one that does not lead to a contradiction in conjunction with those constraints [31, 32]. Some applications of graph databases, such as RDF, are open-world in nature. However, graph databases are not tied to this interpretation and may also accommodate closed-world applications. Therefore, there should be no a priori restriction on the class of set-based repairs one allows in this context. We thus study CQA for graph databases under the three usual notions of set-based repairs: subset, superset, and symmetric difference repairs [18].
section_name: Introduction

section_content: We first look at the data complexity of CQA over graph databases under subset repairs. The problem is in Π P 2, and we prove that it is complete for this class in restricted cases. Moreover, it remains intractable even under an approximation semantics (based on the intersection of all subset repairs) that is motivated by the DL context [32]. 

In order to deal with this high complexity, we provide tractable cases by restricting the class of RPCs or the class of graph databases allowed. In the first case, we prove that the problem is tractable if RPCs are in LAV form, i. e., if they are of the form a L, where a is a single letter. This result is, in a sense, tight, since allowing a single RPC of the form ab c, for symbols a, b and c, leads to intractability. In the case of restrictions on graph databases, by applying a deep result of Courcelle [20] we obtain that the data complexity of CQA under subset repairs is tractable over graph databases of bounded treewidth. 

We then move to study CQA under superset and symmetric difference repairs, and prove that in both cases the problem is undecidable. However, we obtain decidability by either restricting the class of RPCs allowed or their semantics. Let us consider first the restrictions on RPCs. We prove that if RPCs are in LAV form then the data complexity of CQA is tractable when dealing with symmetric difference repairs. We leave open whether CQA is also decidable under the semantics of superset repairs, but prove that at least tractability in data complexity is not preserved. We then prove that if RPCs are in GAV form, i. e., if they are of the form L a, where a is a single letter, our CQA problem is tractable under the semantics of superset repairs, but intractable under symmetric difference repairs. With respect to restrictions on the semantics of RPCs, we prove that by forcing RPCs to be read from a particular node in the graph database, called the origin (which corresponds to the original semantics Abiteboul and Vianu defined for these constraints), the problem can be solved in coNP under superset repairs. 

Comparison with previous results. The main difference between the query and constraint languages we study here (RPQs and RPCs) and the ones studied in the relational context, is that our languages allow recursion while CQA has been studied in the relational world mostly in the absence of recursive features. Interestingly, our results show that recursion does not add to the complexity of the problems studied. In fact, almost all of our lower bounds hold in the restricted setting in which RPQs do not mention the Kleene-star and RPCs are word constraints of the form w 1 w 2, for words w 1 and w 2 [1]. 

If we interpret graph databases as relational databases, word constraints can be represented as tgds. The tgds corresponding to word constraints have a special restricted structure and are called chain tgds. On the other hand, CQA under tgds has been intensively studied [18], and it is tempting to think that lower bounds obtained in such setting could be adapted to work in our scenario. This is not the case, however, as those proofs do not apply to the class of chain tgds. Actually, the proofs of our lower bounds are considerably more involved than the ones for arbitrary tgds. As a side-effect, we obtain that several of our lower bounds extend to CQA in the relational case for queries defined as unions of CQs under chain tgds. 

DL databases are (essentially) graph databases. In such scenario, Π P 2 -hardness results have been obtained by Rosati for the data complexity of CQA under subset repairs, in particular, for the case when queries are unions of CQs and constraints are expressed in the logic ALC [35]. However, constraints in this logic cannot be directly expressed as RPCs due to the presence of negation. Furthermore, the notion of repair in [35] is different to ours. 

Organisation of the paper. Preliminaries are in Section 2. Results about the subset repair semantics are in Section 3, and those about the semantics of superset and symmetric difference repairs are in Section 4. Comparison with previous work is in Section 5 and conclusions in Section 6. Due to space constraints, complete proofs are in the appendix.
section_name: Our contributions.

section_content: Graph databases and regular path queries. As it is customary in the graph database literature [14, 15, 39, 5], we consider graph databases to be finite, edge-labeled and directed graphs. Formally, let Σ be a finite alphabet. A graph database G = (V, E) over Σ consists of a finite set V of nodes and a set of labeled edges E ⊆ V × Σ × V. We interpret each tuple (u, a, v) ∈ E, for u, v ∈ V and a ∈ Σ, as an edge from node u to node v whose label is a. If G = (V, E) and G = (V, E ) are graph databases over Σ, we write G ⊆ G to denote that V ⊆ V and E ⊆ E. If in addition it is not the case that G = G, we write G G. Navigational query languages for graph databases, such as the one of RPQs, express properties of paths. Formally, a path

The label of π, denoted λ(π), is the string a 1 a 2. . . a m ∈ Σ *. A path π of length 0 is simply a node v and its label λ(π) is the empty string ε. 

Here we concentrate on the simplest navigational language for graph databases, namely, regular path queries, or RPQs [14]. An RPQ is a regular expression L over Σ. The evaluation L(G) of L over a graph database G = (V, E) is the set of pairs (u, v) of nodes in V for which there is a path π in G from u to v such that λ(π) satisfies L. If L does not mention the Kleene-star (i. e., if L defines a finite language) then we say that L is non-recursive. It is well-known (cf., [5] ) that computing L(G), for an RPQ L and a graph database G, can be solved in polynomial time (and in NLogspace if L is fixed, that is, in data complexity).
section_name: Preliminaries

section_content: Graph database constraints based on the class of RPQs are known as regular path constraints [1, 26], or RPCs. Formally, an RPC over Σ is an expression of the form L 1 L 2, where L 1 and L 2 are RPQs over Σ. A word constraint is an RPC in which both L 1 and L 2 are words. 

An RPC L 1 L 2 expresses that the evaluation of the RPQ L 1 is contained in the evaluation of the RPQ L 2 [26]. Formally, a graph database G satisfies

If Γ is a finite set of constraints, we write G |= Γ to denote that for each RPC L 1 L 2 in Γ it is the case that G |= L 1 L 2. It follows from previous remarks that the problem of checking whether G |= Γ, for a fixed set Γ of RPCs, is in NLogspace. 

Example 1. Let Γ be the following set of RPCs:

The second and third RPCs express that if u is a brother (resp., sister) of v and v is a sibling of w, then v is a brother (resp., sister) of w. The forth RPC states that each child of a person v is the niece or nephew of every sibling of v.
section_name: Regular path constraints.

section_content: A repair of a database D under a set of constraints Γ is a database D that satisfies Γ but "minimally" differs from D [2]. We formalise this idea for graph databases and RPCs below, following closely its formalisation in the relational context [2]. 

The symmetric difference between two relational databases D and D is defined as a database D ⊕ D that contains those "facts" that belong to D but not to D or to D but not to D. We can analogously define the symmetric difference between two graph databases G = (V, E) and G = (V, E ) over the same alphabet Σ, as the graph database

That is, the nodes (resp., edges) of G ⊕ G are those nodes (resp., edges) that appear in either G or G but not in both. Notice that G ⊕ G is also a graph database over Σ. 

Three notions of set-based repairs have been studied in the literature [18] : the subset, superset and symmetric difference repairs (⊆-, ⊇-, and ⊕-repairs, respectively). We introduce them below in the context of graph databases. Let G = (V, E) and G = (V, E ) be two graph databases over Σ, and assume that Γ is a finite set of RPCs over Σ. Then:

Then G has two ⊆-repairs under Γ: {(b, sister_of, c)} and {(c, brother_of, d)}. On the other hand, G has eight ⊇-repairs under Γ. One of them is the one that extends G with edges:

Finally, G has seven ⊕-repairs under Γ that are neither ⊆-repairs nor ⊇-repairs. One of them is {(b, sister_of, c), (c, brother_of, d), (b, sister_of, d)}. 

Repairs might not exist in some situations. Consider an RPC of the form L ε, where ε is the empty word, and a graph database G that consists of nodes u and v linked by a path labeled in L. Assume that G has a ⊇-repair H. Then it must be the case that u = v in H, which is impossible. As the the next lemma shows, repairs exist in all other cases.
section_name: Repairs.

section_content: 1. There is a ⊆-repair and a ⊕-repair of G under Γ.
section_name: Lemma 3. Let G = (V, E) be a graph database and Γ a finite set of RPCs over Σ. Then:

section_content: Proof. Let G = (V, E) be a graph database and Γ a finite set of RPCs. The empty database G ∅ = (∅, ∅) satisfies Γ. Hence, there is an
section_name: If Γ contains no RPC of the form

section_content: We are now ready to define our most important notion, that of a consistent answer to an RPQ. The consistent answers are the pairs of nodes that belong to the evaluation of the RPQ over every single repair of the original graph database. Definition 4 (Consistent answers). Assume that ∈ {⊕, ⊆, ⊇}. Let G = (V, E) be a graph database, Γ a set of RPCs and L an RPQ, all of them over Σ. We define the set -Cons(G, L, Γ) of -consistent answers of L over G under Γ as: Here we study the data complexity of the problem of computing certain answers. We formalise this decision problem as follows. Assume that L is an RPQ and Γ is a finite set of RPCs over Σ. We denote by -CQA(L,Γ) the problem of, given a graph database G = (V, E) over Σ and a pair (u, v) of nodes in V, checking whether (u, v) ∈ -Cons(G, L, Γ).
section_name: Consistent query answering.

section_content: We start by proving that under the subset repair semantics our CQA problem is Π P 2 -complete. This holds even in the case in which all RPCs are word constraints and the RPQ is nonrecursive. Theorem 6. 1. For each RPQ L and finite set Γ of RPCs over the same alphabet Σ, it is the case that ⊆-CQA(L,Γ) is in Π P 2. 2. There exist a finite alphabet Σ, a non-recursive RPQ L and a finite set Γ of word constraints over Σ, such that ⊆-CQA(L,Γ) is Π P 2 -complete. 

Proof. We sketch the hardness proof, i. e., that there is a non-recursive RPQ L and a set Γ of word constraints such that ⊆-CQA(L,Γ) is Π P 2 -hard. We do so by providing a reduction from the quantified boolean satisfaction problem for Π P 2 to ⊆-CQA(L,Γ). Let φ be a quantified boolean formula of the form ∀X∃Y ψ, where X, Y are disjoint sets of variables and ψ is of the form (z

is of the form ¬u. Without loss of generality, we may assume that in each clause

We will define the RPQ L, the constraints Γ and associate a graph database G φ with φ in such a way that

where n s is a node of G φ. 1 Suppose for example that the clause C1 of ψ contains only variables in X. We construct a new formula ψ defined by (z11

It is convenient to start defining a graph database G φ over alphabet Σ = {t, f, t 0, f 0, a, y, z, w, d, s, e, r -,-, r -,+, r +,-, r +,+ }. 

The nodes of G φ are the following set:

With each variable u ij, we associate a node id n ij in V. Observe that even if u ij = u kl (with (i, j) = (k, l)), the associated nodes are distinct. We also have three special nodes n s, n t and n f. We let < be an arbitrary irreflexive partial order over {1,. . ., n} × {1, 2, 3} such that (a) for each 1 ≤ i, k ≤ n and 1 ≤ j, l ≤ 3, if u ij = u kl, then (i, j) < (k, l) or (k, l) < (i, j), and (b) for each (i, j), where 1 ≤ i ≤ n and 1 ≤ j ≤ 3, there is at most one pair (k, l) such that (k, l) is a "successor" of (i, j) with respect to < (where we say that (k, l) is a successor of (i, j) if (i, j) < (k, l) and there is no (k, l ) such that (i,

The set of edges of G φ is defined as the union of all the sets below:

where ∼, belong to {+, -} and +u := u, -u := ¬u. 

The intuition is as follows. There is no edge with label e and there is an edge with label s between any two nodes. For the labels t and f, each node n ij associated with a variable admits loops with labels t and f. The ⊆-repairs will be such that each such node admit at most one loop, either with label t or f. This allows us to define a partial map associating a truth value with each node n ij ( if the loop has label t and ⊥ if the loop has label f ). The special node n t has a loop with label t 0 and the special node n f has a loop with label f 0. 

The labels r ++, r -+, r +-and r --express which variables occur in the same clause and whether each variable occurs positively or negatively. The label d specifies which nodes corresponds to the same variable. The constraints will be such that in a ⊆-repair, two nodes linked by d (corresponding to the same variables) admit loops with the same label (t or f ). This implies that the partial mapping associating a truth value to each node ( if the loop has label t and ⊥ if the loop has label f ), corresponds to a partial valuation over the variables in X ∪ Y. 

The special node n s admits a loop with label y. That loop will act as a "witness". If that loop appears in a repair, we will say that the node n s gets activated. When n s is activated in a repair, the idea is that each node n ij associated with a variable in Y admits a loop with label t or f. That is, each such a node receives a truth value ( if the loop has label t and ⊥ otherwise). Conversely, if in a repair one node associated with a variable in Y admits a loop with label t or f, then the presence of that loop "activates" the node n s (i. e. n s admits a loop with label y). As a consequence, all the nodes associated with variables in Y will admit a loop. Basically, the node n s guarantees that either all the nodes associated with variables in Y admit a loop, or none of those nodes admits a loop. 

In order to encode in the graph database which variables belong to Y, we add an edge with label a between the source n s and each node of the form n ij with u ij ∈ Y. We also add an edge with label z from n ij to the special node n t and from n ij to n f. We use the nodes n t and n f in the following way. Recall that in a given ⊆-repair, the (possible) truth value of a node is given by the label (either t or f ) of the loop of the node. Now, for the nodes associated with variables in Y, we have an extra way of encoding the truth value. If the truth value of a node n ij (with u ij ∈ Y ) is true, this will also be witnessed by an arrow with label z from n ij to the special node n t (and the other arrow with label z from n ij to n f is deleted). If the truth value is false, this will be witnessed by an arrow with label z from n ij to n f. We now define the set Γ of constraints. We have six different sets of constraints (C1), (C2), (C3), (C4), (C5) and (C6) in Γ. The set (C2) contains the constraint tf e. 

Since e is empty, it says that a node cannot admit both a loop with label t and f. The set (C3) contains the two constraints

It expresses that if two nodes are linked by d (hence, they are associated with the same variable), then they must admit a loop with the same label (in case they admit a loop). This guarantees that the partial map associating a truth value to each node (depending on the label of the loop), can be transformed into a partial valuation over the variables. The set of constraints (C4) is given by

where j, k, l ∈ {+, -}, F (+) = f and F (-) = t. These constraints express that the formula ψ is not false under the partial valuation associated with the repair. 

The constraints (C5) are given by zt 0 tz zf 0 f z. 

They express that if a node associated with a variable in Y is linked to the node n t, then it admits a loop with label t. Similarly, if such a node is linked to the node n f, then it admits a node with label f. Indeed, let us look for example at the constraint zt 0 ⊆ tz. Suppose that there is a path with label zt 0 from a node u to a node v. By definition of t 0 and z, this can only happen if u is a node of the form n ij (with u ij ∈ Y ) and v is the node n t. Now since zt 0 ⊆ tz, this implies that n ij admits a loop with label t. 

The set (C6a) contains the two constraints ta ay f a ay while the constraint (C6b) is given by ay ⊆ zw. The constraints (C6a) express that if one node associated with a variable in Y admits a loop with label t or f, then the node n s is activated (i. e. admits a loop with label y). Indeed, if there is a path with label ta from a node u to a node v, then, u must be a node of the form n ij admitting a loop with label t and v is the node n s. Moreover, since n ij admits an outgoing edge with label a, n ij must be associated with a variable in Y. Since ta ⊆ ay, the presence of the loop with label t and the fact that u ij belongs to Y imply that there is an edge with label y. That is, n s is activated. 

The constraint (C6b) expresses that if the node n s is activated (admits a loop with label y), then each node n ij associated with a variable in Y is linked either to the node n t or to the node n f. Together with the contraints (C5), this means that if n s is activated, then each node n ij associated with a variable in Y admits a loop with label t or f. We define an RPQ L as sys. This RPQ evaluates to V × V in the ⊆-repairs admitting a y-labeled edge, i. e., the repairs in which n s is activated. Recall that this means that the partial valuation associated with the repair assigns a truth value to all the variables in Y. 

We would like to prove that φ is satisfiable iff (n s, n s ) belongs to ⊆-Cons(G φ, L, Γ). Now the implication from left to right is not true. The problem is that since we are allowed to delete edges in order to obtain a repair, we may loose some "relevant information". For example, in a repair, we may loose an edge with label a encoding the fact that a node is associated with a variable in Y. In such repairs, it might not be the case that (n s, n s ) belongs to the answer of L. 

The solution is to extend the graph database G φ with a set of extra edges E, define a new graph G φ, and add a set of constraints (C1). If in a repair H of G φ we lost some "relevant information", the constraints (C1) will be such that at least one extra edge in E occurs in H. We then modify the RPQ L into an RPQ L, in such a way that if a graph database contains a new edge in E, then the evaluation of L consists of all the pairs of nodes. Hence, in all the repairs in which we lose some relevant information, the answer of the RPQ contains any pair of nodes. 

As an example, we show how to modify the graph G φ into a graph G a, add new constraints (C1d) and modify the RPQ L into a RPQ L a in such a way that if in a repair H of G a, we "lost" an edge with label a, then H trivially satisfies 2 L d. We define G a by adding the following edges

That is, we add a loop with label a to all the nodes who must admit an outgoing edge with label a. We define (C1d) as the following constraint a a ⊆ e. 

Using the maximality property of the repairs, we can show that this constraint ensure that in each repair H, exactly one of the following properties holds: (a) we did not loose any edge with label a, and there is no edge with label a or e, (b) there is an edge with label a or e. Case (a) means that we did not lost any "relevant information" with respect to the label a. In case (b), the fact that we lost that information is witnessed by the fact that in the repair, there is an edge with label a or e. 

Finally we let L a be the RPQ s(y + a + e)s. That is, L a is equivalent to sys + s(a + e)s. There are two possibilities for a repair to be such that (n s, n s ) belongs to L a : either (n s, n s ) belongs to L or there is an edge with label a or e. Those two possibilities corresponds to cases (a) and (b) of the previous paragraph.
section_name: CQA under Subset Repairs

section_content: In order to obtain good complexity bounds for CQA in the DL context, Lembo et al. introduced a sound approximation of the CQA semantics based on the idea of evaluating queries over the intersection of all subset repairs [32]. This approximation leads to tractability for inconsistency-tolerant query answering over some DLs of interest (e. g., for DL-Lite A ). Although the repairs studied in the DL context are different to ours, it makes sense to study the pertinence of this semantics as a tool for establishing tractability results also in the graph database context. 

Formally, let L be an RPQ and Γ a finite set of RPCs over Σ. We define ∩-CQA(L,Γ) as the problem of, given a graph database G = (V, E) over Σ and a pair (u, v) of nodes in V, checking whether (u, v) belongs to the evaluation of L over the intersection of all ⊆-repairs of G under Γ. (The intersection of graph databases

We prove below that the approximation semantics is not easier to evaluate than the original one. Therefore, in order to obtain tractability for our CQA problem it is necessary to look for restrictions that are proper to the scenario of graph databases. Proposition 7. There exist a finite alphabet Σ, a non-recursive RPQ L and a finite set Γ of word constraints over Σ, such that ∩-CQA(L,Γ) is Π P 2 -hard.
section_name: Semantics based on the intersection of subset repairs.

section_content: Due to the inherent high complexity of our CQA problem under the subset repair semantics, it is important to look for meaningful restrictions leading to tractability. We provide two such restrictions in this section. The first one is based on the class of LAV RPCs, and the second one on the class of graph databases of bounded treewidth. 

Restricting RPCs. In the relational case, the data complexity of CQA for unions of CQs under the class of LAV tgds (i. e., tgds with a single atom in the left-hand side [33] ) is tractable. This actually holds for any of the three repair semantics [18]. The direct analogue of LAV tgds in our setting is the class of LAV RPCs, which are RPCs with a single symbol in the left-hand side. Formally, a LAV RPC over Σ is an RPC of the form a L, where a ∈ Σ and L is an RPQ over Σ. We can leverage the techniques used to study CQA under LAV tgds to prove tractability in data complexity for our CQA problem under LAV RPCs. 

Theorem 8. For each RPQ L and finite set Γ of LAV RPCs over the same alphabet Σ, it is the case that ⊆-CQA(L,Γ) is in NLogspace. 

It is interesting to also consider RPCs based on the class of GAV tgds [33], that only allow for one symbol on the right-hand side. That is, a GAV RPC over Σ is of the form L a, for L an RPQ over Σ and a ∈ Σ. While this restriction improves the complexity of the CQA problem, it does not lead to tractability. Note that in the setting of relational databases, the data complexity of consistent query answering for unions of conjunctive queries with respect to GAV constraints was also shown to be complete for the class coNP [18]. It is worth mentioning that we obtained the upper bound of Proposition 9 using techniques from the relational case. 

The second part of the previous proposition shows that, in a sense, the tractability result for LAV RPCs in Theorem 8 is optimal: Allowing two-letter words on the left-hand side of RPCs leads to intractability, even if the right-hand side consists of a single letter.
section_name: Tractable restrictions

section_content: Our CQA problem under the subset repair semantics can be reformulated as a monadic second-order logic (MSO) evaluation problem over a relational representation of graph databases. This allows us to apply results establishing the tractability of MSO over structures of bounded treewidth [20]. From those results, we obtain tractability for the CQA problem over graph databases of bounded treewidth. 

Formally, let G = (V, E) be a graph database. A tree decomposition of G is a pair (T, λ), where T is a tree and λ : T → 2 V maps each node t in T to a nonempty set λ(t) of nodes in V, that satisfies the following conditions:

The set {t ∈ T | v ∈ λ(t)} is a connected subset of T. 

For each edge (u, a, v) ∈ E, it is the case that {u, v} ⊆ λ(t), for some t ∈ T. The width of the tree decomposition (T, λ)

The treewidth of G is the minimum width of a tree decomposition of G. For instance, the treewidth of G is one if and only if the underlying undirected graph of G is a tree. 

We then obtain the following: Theorem 10. Let L be an RPQ and Γ a set of RPCs. Then ⊆-CQA(L,Γ) can be solved in linear time over graph databases of treewidth ≤ k, for each k ≥ 1.
section_name: Restricting graph databases.

section_content: We prove in this section that our CQA problem is undecidable under the semantics of ⊇and ⊕-repairs. This holds even if RPQs are non-recursive and RPCs are word constraints:

Theorem 11. Assume ∈ {⊇, ⊕}. There exist a finite alphabet Σ, a non-recursive RPQ L and a set Γ of word constraints over Σ, such that -CQA(L,Γ) is undecidable. 

In order to prove this theorem we establish a connection with the implication problem for RPCs [1, 26]. Recall that this is the problem of, given a finite set Γ of RPCs and an

, for every graph database G. Grahne and Thomo proved this problem to be undecidable, even for word constraints, using a reduction from the word rewriting problem [26]. We develop nontrivial adaptations of such reduction to prove Theorem 11. The reason why we have to develop such adaptations is that there exist differences in nature between CQA and the implication problem for constraints. First, in the CQA problem we do not reason about all graph databases that satisfy the constraints (as in the case of the implication problem), but only about those that minimally differ from the original graph database. Note that in the special case of the superset semantics, this first problem does not apply. Indeed, given a graph database G, the intersection of the answers of a monotone query L over all the ⊇-repairs is equal to the intersection of the answers of L over all the databases containing G and satisfying the constraints. 

Second, we study the data complexity of the CQA problem, and, therefore, our goal is to prove undecidability of CQA for a fixed set of RPCs and a fixed RPQ. This is different to the case of the implication problem in which RPCs and RPQs define the input, and, therefore, cannot be fixed. 

Proof of Theorem 11. We only prove the case when is ⊇. We start by recalling the basic notions of rewrite systems. Let ∆ be a finite alphabet. A semi-Thue rewrite system R over ∆ is a finite subset of ∆ * × ∆ *. A rewrite system R induces a single-step reduction relation → R over ∆ * defined as:

We let → * R be the reflexive transitive closure of → R. The problem of testing whether a pair (u, v) belongs to → * R is called the rewrite problem for R. It is well known that there is a semi-Thue rewrite system R 0 over ∆ such that the rewrite problem for R 0 is undecidable (see e. g., [8] ). 

We prove that ⊇-CQA(L,Γ) is undecidable using a reduction from the rewrite problem for R 0. Let ∆ = ∆ ∪ {â | a ∈ ∆} ∪ {$}, where the â's and $ are fresh symbols. We define a set Γ of RPCs and an RPQ L over ∆, such that there is an algorithm that takes as input two words w 1 and w 2 over ∆ and constructs a graph database G over ∆ with a node n 0 such that w 1 → * R0 w 2 iff (n 0, n 0 ) ∈ ⊇-Cons(G,L,Γ). The set Γ consists of all RPCs of the form:

for (u, v) ∈ R 0 and a ∈ ∆. We define the RPQ L as the letter $. 

Let w 1 and w 2 be two words in ∆ *. We assume that

where

, where E 1, E 2 and E 3 are as follows:

Notice that G consists of a path with label w 1 from n 0 to n k and a path with label ŵ2l ŵ2(l-1). . . ŵ21 from n k to n 0. The node n k admits a loop with label $. The intuition is as follows. We start with the path with label w 1 in G 0. The idea is that if w 1 → * R0 w 2, then applying the constraints of the form u v in Γ, we will construct a path with label w 2. The query is $, and thus we have to check whether n 0 admits a loop with label $ in every repair. 

Intuitively, the presence of a path with label w 2 from n 0 to n k is witnessed by a loop with label $ at n 0. This is due to the presence of the constraints of the form a$â $ in Γ. Indeed, suppose that s 0 w 21 s 1 w 22. . . s l is a path with label w 2 from n 0 to n k (where each s i is a node, and thus s 0 = n 0 and s l = n k ). Then, by induction on 0 ≤ i ≤ l, using the constraints a$â $ and the fact that n k admits a loop with label $, we can prove that there is an edge with label $ from s l-i to m l-i. In particular, there is an edge with label $ from s 0 to m 0. Since s 0 = m 0 = n 0, this implies that n 0 admits a loop with label $. 

We have to prove that w 1 → * R0 w 2 iff (n 0, n 0 ) ∈ ⊇-Cons(G,L,Γ). The proof of the implication from left to right follows basically from the intuition that we gave in the previous two paragraphs. For the implication from right to left, suppose that (n 0, n 0 ) ∈ ⊇-Cons(G,L,Γ). We have to prove that w 1 → * R0 w 2. The strategy is as follows. (a) We construct a graph database H such that G ⊆ H and H |= Γ. Moreover, if there is a path with label w 2 from n 0 to n k in H, then

As the consistent answer of L = $ contains the pair (n 0, n 0 ), this implies that n 0 admits a loop with label $ in H. In particular, n 0 admits a loop with label $ in H.
section_name: CQA under Superset and Symmetric Difference Repairs

section_content: We prove that if n 0 admits a loop with label $ in H, then there is a path with label w 2 from n 0 to n k in H. Together with (a), this finishes the proof that w 1 → * w 2. 

The construction of the graph database H uses ideas from the construction in the undecidability proof of [26]. In fact, H is an extension of the graph database used in such construction. Let k 0 be the maximum of {k, l}. We define the set of nodes V of H as:

We identify n 0 with [ ]. For all 1 ≤ i ≤ k, we identify n i with [w 11. . . w 1i ]. In particular, n k is [w 1 ]. Note that this implies that the set V of nodes of G is a subset of V. 

Let E 1 be the relation:

The graph H 0 := (V, E 1 ) is precisely the graph constructed in the undecidability proof of [26]. We now define H as the graph (V, E 1 ∪ E 2 ∪ E 3 ), where E 2 and E 3 are as follows:

If i = l, by convention, we define w 2(l-i+1). . . w 2l as the empty word. Notice that G ⊆ H. 

We skip the details of the proof that (a), (b) and (c) hold. An important part of this proof of is to show that if there is a path with label w 2 from n 0 to n k in H, then w 1 → * R0 w 2. This can be obtained as an immediate consequence of Lemma 2 in the proof of Theorem 2 in [26]. Notice that although it might be impossible to construct the graph database H (since E 1 is defined in terms of the rewrite problem for R 0 ), our proof only requires the existence of such graph database.
section_name: (c)

section_content: Since the CQA problem in this context is undecidable, it is crucial to look for decidable (and, ideally, tractable) restrictions of it. We provide three such restrictions in this section: The first one is based on the class of LAV RPCs, while the second one is based on the class of GAV RPCs. The third one is obtained by modifying RPC interpretation to be from the origin. It is worth noticing that the restriction to classes of graph databases of bounded treewidth, which leads to tractability under the semantics of subset repairs, is not useful in this context: The undecidability result in Theorem 11 holds even over graph databases of treewidth two. 

Restriction to the class of LAV RPCs. As mentioned before, in the relational scenario the CQA problem for unions of CQs under LAV tgds is tractable, no matter which repair semantics is used. We already stated a similar result for CQA over graph databases under LAV RPCs and the subset repair semantics (Theorem 8). We can further extend those techniques to obtain tractability for our CQA problem under the semantics of ⊕-repairs. Theorem 12. For each RPQ L and finite set Γ of LAV RPCs over the same alphabet Σ, it is the case that ⊕-CQA(L,Γ) is in NLogspace. Proposition 13. There exist a finite alphabet Σ, a non-recursive RPQ L, and a finite set Γ of LAV RPCs (without Kleene-star) over Σ, such that ⊇-CQA(L,Γ) is coNP-hard. 

Notice that, unlike all previous lower bounds, the one in Proposition 13 is not stated in terms of the class of word constraints. In fact, the techniques developed for studying CQA under tgds in the relational case [18] can be adapted to show that under a set Γ of LAV word constraints the problem ⊇-CQA(L,Γ) is tractable. 

Restriction to the class of GAV RPCs. In the case of the symmetric difference semantics, it is easy to adapt the proof of Proposition 9 in order to show that when restricting to GAV RPCs, our CQA problem is coNP-hard. Note that in the relational case, a similar result holds. Proposition 14. 1. For each RPQ L and finite set Γ of GAV RPCs over the same alphabet Σ, it is the case that ⊕-CQA(L,Γ) is in coNP. 2. There exist a finite alphabet Σ, a non-recursive RPQ L over Σ and a single GAV RPC of the form ab c, where a, b, c ∈ Σ, such that ⊕-CQA(L,Γ) is coNP-complete. 

In the case of the superset semantics, the restriction to GAV RPCs leads to tractability. Given a graph database G and a set of GAV RPCs Γ, using a classical chase argument, we can easily compute in Logspace the unique superset repair of G with respect to Γ. This is identical to what happens in the setting of relational databases. Proposition 15. For each RPQ L and finite set Γ of GAV RPCs over the same alphabet Σ, it is the case that ⊇-CQA(L,Γ) is in NLogspace. 

Modifying the interpretation of RPCs. In the original proposal of Abiteboul and Vianu, RPQs, and therefore RPCs, are only evaluated from a particular node called the origin. This is motivated by their application over semi-structured data. Formally, let o be a fixed node id that we identify as the origin. A graph database G

We can now modify the definition of repairs and consistent answers with respect to the restricted |= o interpretation of RPCs. Assume ∈ {⊆, ⊇, ⊕}. An {o, }-repair of a graph database G under a set of RPCs Γ is defined exactly as an -repair of G under Γ, except that now the satisfaction of the RPCs in Γ is defined with respect to the relation |= o. (For safety reasons, we assume that G contains the origin o in this case). For instance, G is a

an RPQ and Γ is a finite set of RPCs, we define {o, }-CQA(L,Γ) as the problem of, given a graph database G = (V, E) and a pair (u, v) of nodes in V, checking whether (u, v) is an {o, }-consistent answer of L over G under Γ, i. e., if (u, v) ∈ L(G ), for each {o, }-repair G of G under Γ. 

By interpreting RPCs under the relation |= o, we obtain decidability for our CQA problem under the semantics of ⊇-repairs. We do not know whether this can be extended to the semantics of ⊕-repairs. Notice the difference with the restriction to LAV RPCs we studied before: For the latter we could only obtain decidability under the ⊕-repairs semantics. 

where each R i is a relation symbol in σ [21]. That is, the underlying directed graph of a chain CQ is a path. A chain tgd is one of the form ∀x∀y(φ(x, y) → ψ(x, y)), where both φ(x, y) and ψ(x, y) are chain CQs. It is easy to see that each word constraint can be represented as a chain tgd over the standard relational representation of graph databases (in which, for each a ∈ Σ, there is a binary relation symbol E a that contains all pairs of nodes that are linked by an a-labeled edge in the graph database). Conversely, each chain tgd is the representation of a word constraint. 

This allows us to use our proof techniques to obtain lower bounds for CQA under the restricted class of chain tgds in the relational context:
section_name: Decidable restrictions

section_content: In this work we initiated the study of CQA over graph databases. The data complexity of the problem is in general undecidable or highly intractable, which motivated our search for decidable, and even tractable restrictions. In the case of subset repair semantics we obtain tractability by either restricting to the class of LAV RPCs or to the class of graph databases of bounded treewidth. The class of LAV RPCs also yields tractability for our problem under the semantics of ⊕-repairs. On the other hand, for the semantics of superset repairs we obtain decidability if RPCs are interpreted from the origin or if we restrict to the class of GAV RPCs. Several questions regarding CQA under the semantics of ⊇-and ⊕-repairs remain open. For instance, we do not know if CQA under ⊇-repairs is decidable when RPCs are in LAV form. Neither do we know whether CQA under ⊕-repairs is decidable when RPCs are interpreted from the origin. We plan to study this in the future. 

It would also be interesting to look for different kinds restrictions that yield decidability for our CQA problem. For instance, in the relational scenario it is possible to obtain tractability in data complexity for CQA under ⊇-and ⊕-repair semantics if the set Γ of tgds is weakly acyclic [18]. The reason is that in this case there is a polynomial that bounds the size of each repair of a database D under Γ. We would like to develop a meaningful adaptation of this notion to the scenario of RPCs in search for similar positive results. This is more difficult than in the relational case, however, since the notion of acyclicity will have to consider how regular expressions interact with each other. Another way in which positive results for our CQA problem under ⊇-and ⊕-repair semantics could be obtained, is by restricting to classes of RPCs for which the implication problem is decidable. This includes, for instance, classes of word constraints for which the associated rewrite problem is decidable [26]. 

While our work concentrates on queries defined as RPQs, all upper bounds presented in the paper continue to hold in the extended scenario in which queries are defined as conjunctive RPQs (CRPQs) [13]. In turn, CRPQs might lead to an expressive class of conjunctive RPCs, which are expressions of the form φ(x) ψ(x), for CRPQs φ and ψ. It is interesting to study how the positive results presented in this paper can be extended to be applied over this class of constraints.
section_name: Conclusions and Future Work

section_content: Acknowledgements. We are grateful to Aidan Hogan and Leonid Libkin for their helpful comments in earlier versions of the paper. Carsten Lutz and Meghyn Bienvenu also provided us with important insights on the nature of DL repairs. Barceló and Fontaine are funded by the Millennium Nucleus Center for Semantic Web Research under Grant NC120004. Fontaine is also funded by Fondecyt postdoctoral grant 3130491.

section_name: Comparison with CQA in the relational context

section_content: On the Data Complexity of Consistent Query Answering over Graph Databases Theorem 16. For each RPQ L and finite set Γ of RPCs over the same alphabet Σ, it is the case that {o, ⊇}-CQA(L,Γ) is in coNP. 

The difference here is that the implication problem for RPCs becomes decidable if RPCs are interpreted under the relation |= o [1]. We adapt the techniques used to prove this fact in order to obtain Theorem 16. 

We do not know whether the bound in Theorem 16 is tight. Interestingly, we can show that a slight extension on the query language leads to intractability. We reduce from the problem of 3-colorability. Assume we are given an undirected graph H. From H we construct a graph database G = (V, E), such that (1) V corresponds to the set of nodes of H plus the origin o, and (2) E contains edges (o, a, v), for each node v in H, and (u, e, v) and (v, e, u), for each edge {u, v} in H. Assume that Γ consists of the single constraint a c 1 ∪ c 2 ∪ c 3. Intuitively, this tells us that a ⊇-repair of G contains, for each node v = o, one, and only one, edge of the form (o, c i, v), for 1 ≤ i ≤ 3. This edge represents the color assigned to node v by an assignment of three colors to the nodes of H. 

It is not hard to prove that H is 3-colorable if and only if there exists a ⊇-repair G of G such that no two nodes linked by an edge labeled e in G are assigned the same color. This is equivalent to checking that it is not the case that there are paths labeled c i e and c i in G, for 1 ≤ i ≤ 3, that start in the origin o and reach the same node v. While this cannot be expressed as an RPQ, it can be easily expressed as an RPQ with inverses [14]. The query is Q := 1≤i≤3 c i ec - i, where c - i represents a backward traversal of an edge labeled c i. We then have that H is 3-colorable if and only if (o, o) is not an {o, ⊇}-consistent answer of Q over G under Γ. This query can also be expressed as a conjunction of two RPQs [13]. 

Remark. The restriction presented in this section does not help reducing the complexity under the semantics of ⊆-repairs. In fact, it can be proved that all lower bounds obtained in Section 3 continue to hold for the semantics of {o, ⊆}-repairs. This is done in the appendix.

section_content: We compare our results with previous results on CQA obtained in the relational context. We assume familiarity with relational schemas and CQs. Tuple-generating dependencies, or tgds, define one of the most important classes of relational database constraints. They subsume several other classes of interest, such as inclusion dependencies. In addition, they have important applications in data integration, data exchange and ontological query answering [33, 23, 10]. Formally, a tgd over a relational schema σ is a formula of the form ∀x(φ(x) → ψ(x)), where both φ(x) and ψ(x) are CQs over σ and each variable in x is mentioned in φ(x). A relational database D over σ satisfies this tgd if D |= φ(ā) implies D |= ψ(ā), for each tuple ā of elements in D of the same length than x. 

As mentioned in the introduction, each word constraint can be naturally seen as a tgd over the standard relational representation of graph databases. However, lower bounds for CQA under tgds in the relational setting, such as the ones obtained by ten Cate et al. [18], cannot be used to obtain lower bounds for CQA under word constraints (or even RPCs) in the graph database context. This is because word constraints correspond to a restricted class of tgds defined by chain CQs (which we call chain tgds). However, none of the lower bounds developed for the data complexity of CQA under tgds applies to this class. 

We formalise the class of chain tgds as follows. Let σ be a relational schema that contains only binary relation symbols. A chain CQ over σ is a CQ of the form φ(x, y) := ∃u 1 u 2. . . u m-1 R 1 (x, u 1 ) ∧ R 2 (u 1, u 2 ) ∧ • • • ∧ R m-1 (u m-1, y),
section_name: Comparison with CQA in the relational context