View-Based Query Determinacy for Walk-Based Semantics
Abstract
The view-based query determinacy problem asks, given a view and a query whether the information contained in always suffices to answer the query . It is a notoriously hard problem that is known to be undecidable even in very restricted settings. Here, we study it in the context of graph databases and regular path queries and views evaluated under several βwalk-based semanticsβ, that is, semantics in which queries and views return the matched walks in full as opposed to the classical βendpoint semanticsβ. Our main finding is that view-based query determinacy is decidable for regular path queries under both trail and shortest walk semantics.
Keywords and phrases:
graph databases, regular path queries, trail semantics, shortest walk semantics, view-based query determinacy2012 ACM Subject Classification:
Theory of computation Database theoryAcknowledgements:
I gratefully thank Yann Strozecki for reading early versions of this work and providing constructive feedback.Editors:
Balder ten Cate and Maurice FunkSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl β Leibniz-Zentrum fΓΌr Informatik
1 Introduction
The view-based query determinacy problem is a classical static analysis problem in database theory. It arises in many reasoning scenarios, including data exchange and integration, query optimization and data privacy. Given a set of queries called the view and a target query , one has to decide whether, for all databases , the answers to the queries in , denoted as always suffice to compute regardless of the underlying data that was used to compute . When this is the case, we say that determines . Formally, this means that there exists a functional dependency from to : for all databases and , if , then .
This problem is known to be computationally very hard in many settings, even for the most basic query and view languages. It is already undecidable for conjunctive queries and conjunctive views in relational databases [11, 12]. Some fragments and restrictions of the problem are known to be decidable, but the strength of the restrictions can be seen as a testimony to the original problemβs hardness. These include chain queries (that is, conjunctive queries whose underlying graph is a path) [2] with a narrow extension in [6] and the monotone determinacy setting, in which the functional dependencies from the view to the target query is furthermore assumed to be monotonic [19].
In the graph database setting, the problem turns out, perhaps unsurprisingly, to also be computationally hard. The building block for most query languages over graphs are regular path queries [18]: queries which look for walks in the graph whose label conforms to a given regular expression. Unfortunately, query determinacy is undecidable for regular path queries and views, even for a very restricted form of regular expression with no Kleene star [10]. As in the relational case, the monotone setting is decidable, as shown in [9] using techniques from [4]. However, these results do not tell the whole story: in existing work, regular path queries are evaluated under the so-called endpoint semantics, where queries only return the endpoints of walks in the database whose label conforms to the query. While theoretically very sound, the endpoint semantics do not capture the behavior of real-life systems, in which the matching walks are returned in full. To the best of our knowledge, there are no known results for query determinacy under walk-based semantics.
Moving from endpoint semantics to walk-based semantics leads to many complications. Indeed, since databases can contain cycles, it may happen that the set of walks to be returned by a given query is infinite. To address this issue, real-life systems evaluate queries under specific semantics, that is, criteria that ensure the finiteness of the output. The most common semantics are trail semantics, which filters out walks that contain repeated edges, and shortest walk semantics, which only returns the shortest witness for each fixed source and target vertex. These semantics come at a severe cost in complexity (testing emptiness for a given regular path query is NP-complete under trail semantics [17], which makes query evaluation intractable) and expressivity (by filtering out potentially interesting results). These semantics are nonetheless commonly seen in practice, which strongly implies that there is a real demand for walk-based semantics. Notable examples include Cypher, which is evaluated under trail semantics [8] and GSQL [21] and G-Core [3], which both use shortest walk semantics. Finally, the language GQL [5, 7], which has been designed as a standard for graph query languages, implements both trail and shortest walk semantics.
This article addresses the query determinacy problem in the graph database setting for regular path queries and views that are evaluated under walk-based semantics. In addition to the trail and shortest walk semantics, we also consider the all-walks semantics which simply returns all walks that match the query, even though the set of answers could be infinite. This is not only a theoretical consideration. We will see that in the context of query determinacy, the decision procedure for this semantics actually applies to all semantics that are βedge-coveringβ [16]: if an edge of the graph is useful to the query (it occurs in at least one matching walk), then this edge should appear in at least one walk of the answer.
Note that it is not immediately obvious whether query determinacy under walk-based semantics is harder than under endpoints semantics: we are assigned a harder task (computing the walks that match the query in full) but we are given a view that provides much more information. This is similar to the case of full conjunctive queries and views in the relational setting, where it is assumed that all variables in the body of the query are also output variables in the head. This setting is known to be decidable [2] with a simple criterion: full views determine the query if they cover all atoms of a specific canonical database. The graph database setting turns out to also be decidable under walk-based semantics but poses new challenges. First, regular path queries are essentially infinite (albeit regular) unions of conjunctive queries, which means that there would naively be infinitely many databases against which determinacy must be checked. Second, the semantics under which queries and views are evaluated might filter out necessary information, even though the walks containing said information do match the given regular languages.
Contributions.
We start by showing how the classical query determinacy problem translates to our setting. As a side result, we remark that the query rewriting problem using views [19] turns out to be trivial in our setting: the rewriting, when it exists, will simply be the original query itself. Then our main contribution is to prove upper and lower complexity bounds for the problem of deciding query determinacy under all-walks, trail and shortest walk semantics. First, we establish a lower bound that covers all three semantics:
Theorem 1.
Determinacy for regular path queries and views is PSpace-hard under all-walks, trail and shortest walk semantics, even if the automata that define the queries and views are deterministic.
In this work, we assume that the regular path queries are given as finite automata. Thus, it is a natural concern whether the complexity depends on the properties of the specific automaton that implements the query. Our result, however, shows that the lower bound holds even in the favorable case where the automaton is deterministic. Next, we prove a matching upper bound for all-walks and trail semantics, which makes the problem PSpace-complete:
Theorem 2.
Determinacy for regular path queries and views can be decided in PSpace under all-walks and trail semantics, even for nondeterministic query and view automata.
Finally, we prove a matching upper bound for shortest walk semantics, which turns out to be our most difficult result:
Theorem 3.
Determinacy for regular path queries and views can be decided in PSpace under shortest walk semantics, provided that the query is given as a deterministic automaton.
This upper bound only holds when the query is given as a deterministic automaton (the automata defining the view may be nondeterministic). One could always choose to determinize the input to use this decision algorithm, but then the upper bound becomes ExpSpace, and no longer matches the lower bound. Unfortunately, this gap remains as an open question: we neither have a better upper bound for the nondeterministic case, nor a tighter lower bound when the automaton can be nondeterministic.
Outline.
Section 2 defines the data and query models of our setting. Section 3 defines the view-based query determinacy problem and shows preliminary results that apply to all three semantics, including the PSpace lower bound. Section 4 proves the upper bound for the all-walks and trail semantics. While interesting in its own right, this section also serves as a warm-up for Section 5 where we prove the upper bound for the shortest walk semantics. Indeed, the techniques in Section 5 reuse and expand upon the core ideas of Section 4.
2 Preliminaries
In this section, we define the data and query models that are used throughout the article. Particular attention should be given to Section 2.3 that defines the walk-based semantics under which regular path queries are to be evaluated.
2.1 Graph databases
We represent graph databases as multi-edge multi-label graphs. All results naturally translate to the traditional theoretical model where databases are more simply represented as edge-labeled graphs [18]. Here, we chose to use a more general model that more closely resembles the property graph data model used in practice [5], where both vertices and edges are assumed to have a unique identifier. In particular, it is not enough to know that a vertex is connected to a vertex with an -labeled edge: we will also need the specific identifier of said edge.
Definition 4 (Database).
A database is a tuple where:
-
is a finite set of symbols, or labels;
-
is a finite set of vertices;
-
is a finite set of edges;
-
is the source function;
-
is the target function;
-
is the labeling function.
Definition 5 (Walk).
A walk in a database is a nonempty finite sequence of alternating vertices and edges of the form where , , , such that, .
We call the length of and denote it by . We extend the functions , and to the walks in as follows. For each walk in , , , and . Finally, we write to say that and .
We say that two walks and concatenate if , in which case we define their concatenation as
that is, we concatenate the two lists and remove one occurrence of the repeated vertex .
A walk is said to be simply labeled if each edge of the walk has at most one label.
Finally, a walk is called a trail if it contains no repeated edge. It is furthermore called a simple walk if it contains no repeated vertex.
When we are given a walk, typically as returned by a query, we assume that it is given together with all the data that occurs in the vertices and edges along the walk, namely their identifiers and labels. This is in line with real-life database systems, where a returned object can be subsequently inspected for any data it might contain. It will be useful to consider this data as its own database, as defined below.
Definition 6 (Data in a walk).
Let be a walk in a database . We define as the restriction of to the vertices and edges that occur in . Formally, is the database defined as:
-
-
-
, ,
2.2 Queries and Automata
A regular path query (RPQ) is defined by a regular language. In real-life systems, RPQs are typically input with a syntax that resembles regular expressions. Here, we define queries using finite state automata, which makes formal proofs easier and allows a finer complexity analysis depending on whether the given automaton is deterministic. This does not affect the applicability of our upper bounds, as regular expressions can be translated to nondeterministic automata in linear time (see for instance [20]). Note that the same does not hold for deterministic automata, which is why the deterministic case enjoys better bounds.
Formally, lower bounds do not immediately translate from one setting to the other. Fortunately the proof for regular expressions happens to be extremely similar (see Remark 22). In examples, we will informally use regular expressions, which are more human-readable.
Definition 7 (Automaton).
A nondeterministic automaton is a 5-tuple where is a finite set of symbols, is a finite set of states, is the set of initial states, is the set of transitions and is the set of final or accepting states. We denote as the set , and for a set , .
An automaton is deterministic if , and for all , . In that case, we will interpret as a partial function , written in lowercase to avoid confusion.
We denote by the language of , that is, the set of words such that .
A regular path query is defined by an automaton . We use and interchangeably. An RPQ matches walks which carry a label that belong to :
Definition 8 (Match).
Let be a database and be a walk in . We say that matches an RPQ if . We denote as the (possibly infinite) set of all walks of that match .
Warning.
For simplicity, we assume that languages never contain the empty word . This is without loss of generality: the corner case where can be solved separately (see Appendix A) and excluding it avoids special cases and technical overhead in subsequent statements and proofs. From now on, matched walks always contain at least one edge.
2.3 Walk-based Semantics
When a database contains cycles, it may happen that an RPQ matches infinitely many walks. While this is not an issue in a theoretical context, real-life systems impose criteria that guarantee finiteness, known as semantics. We say that a semantics is walk-based if it returns a subset of . Let be an RPQ and be a database. Let be a semantics. We denote as the set of answers to under . We focus on three specific walk-based semantics defined below:
-
All-walks semantics: .
-
Trail semantics: .
-
Shortest walk semantics: for each pair of vertices , we define the minimal match length as . Under shortest walk semantics, only returns the walks whose length is minimal between their endpoints: .
We will make use of some well-known properties of all-walks and trail semantics:
-
RPQ under are monotonic: if , then .
-
RPQ under (resp. ) are closed under homomorphism (resp. edge-injective homomorphism): if is a homomorphism (resp. edge-injective homomorphism) from to another database , and , then .
Indeed, , thus if , then . Additionally, if is a trail and is edge-injective, then is a trail.
Remark that neither property holds for shortest walk semantics: adding a new walk in can make previous query answers disappear, as they might no longer be the shortest walks.
Example 9.
Let be the database depicted below:
Let be the query defined by , that is, contains all words which start with a , end with another , and without two consecutive . Then we can evaluate over under the three semantics. For the sake of readability, only the edges are listed in the walks below. Vertices are implicitly defined by the adjacent edges.
-
-
-
is an infinite set. In addition to walks in and , it also contains walks described by the following regular expression: .
Remark that does not contain the βtopβ walk , because , as witnessed by the βbottomβ walk . Conversely, does not contain any of the βloopingβ walks, such as , because they repeat .
3 View-based Query Determinacy
This section defines the view-based query determinacy problem in our setting, and proves several useful preliminary results that are the foundations of the following sections. It concludes with the proof of Theorem 1 that provides a PSpace lower bound for all three semantics.
Definition 10 (View).
A view is a finite set of queries. If all queries in are regular path queries, we say that is a regular path view.
Definition 11 (View image under ).
Let be a regular path view. Let be an RPQ semantics and let be a database. The view image of through under is the tuple .
Β Remark 12.
The view image of a database is a tuple of sets, one set for each query in the view . These sets could be infinite if does not guarantee a finite output.
We now have all the tools to translate the classical definition of view-based query determinacy (see [19] for a reference) to our setting:
Definition 13 (Determinacy under X).
Let be a view and be a query. We say that determines under , and we write if the following holds:
Informally, this definition states that determines if and only if there is a functional dependency from view images to query answers: as soon as two databases have the same view image, they must also return the same answers to the query.
Our goal is to solve the view-based query determinacy problem defined as:
As in Definition 6, it will be useful to aggregate all data contained in a view image and consider it as a database:
Definition 14 (Data in a view under ).
Let be a database, be a regular path view and be an RPQ semantics. We extend Definition 6 to view images as follows:
Β Remark 15 (Edge-covering Semantics).
is a substructure of . As such, it is always finite, even if is not a semantics that guarantees a finite output.
This finite structure is what gives meaning to all-walks semantics beyond being just a theoretical curiosity. Indeed, in our setting, all-walks semantics captures the family of RPQ semantics that are βedge-coveringβ [16]. Intuitively, edge-covering semantics return all edges that are useful to the query at least once. Formally, a semantics is said to be βedge-coveringβ if and only if, for all queries and databases , for all edges in , if there exists a walk , then there exists a walk .
Let be an edge-covering semantics. Then, it is not hard to see that for all views , . We will see that the content of alone suffices to decide determinacy, without requiring the more precise information contained in . Thus, results for all-walks semantics naturally extend to edge-covering semantics.
An example of edge-covering semantics that has been studied in theoretical work is the βshortest witnessβ semantics [14]: for each vertices and edge , this semantics returns the shortest walks from to that contain . Though not commonly implemented in practice, a similar behavior can usually be achieved in real-life systems that allow performing multiple matches and joining the resulting walks, as in GQL or Neo4j.
Example 16.
Recall the database from Example 9 and query defined by . Let be the view that contains only . Then , as all edges of occur in some walk of . The case of trail and shortest walk semantics are given below:
-
=
-
=
As is depicted above, under both trail and shortest walk semantics, some part of the database is βhiddenβ to the view.
The following two lemmas hint at the fact that actually contains all relevant information for answering query determinacy:
Lemma 17 (No hidden walks).
Let , be a database, be a regular path view and be an RPQ. If there exists such that is not a walk in , then .
Proof.
Let everything be defined as in the statement of the lemma. Let such that is not a walk in . Then there exists an edge that occurs in but not in . Let be a copy of without this edge. Then one simply has to remark that , but .
Lemma 18 (View image from view data).
Let . Let be a database. Then .
Proof.
Let . We show that .
-
Let . Then, by definition, is a walk in . Thus, matches . Since is a substructure of , if is a trail in , it is also a trail in . Similarly, if is a shortest walk between its endpoints in , it is also a shortest walk in .
-
Let . As in the previous case, is a walk of that matches , and if is a trail in , then it is a trail in . The only interesting question is whether is a shortest walk in when . Assume for the sake of contradiction that there is a walk such that has the same endpoints as and is shorter than . Then, by definition, is a walk in . Thus , which is a contradiction.
Β Remark 19.
Lemma 18 means that under , only matters. We do not have to keep track of the specific view which returned each element of . Be careful that this property does not generally hold: one can easily design βexoticβ semantics that are specifically tailored to falsify this property, such as:
-
βSecond shortest walkβ: return if and only if its length is the second shortest length.
-
βShortest walk hybridβ: return if it is finite, otherwise return .
Lemma 17 and Lemma 18 imply that, in our setting, determinacy admits an alternate and much simpler definition:
Proposition 20 (Determinacy: alternate definition).
Let . Let be a regular path view and be an RPQ. Then if and only if for all databases , for all walks , is a walk in .
Proof.
-
This is immediately given as the contraposition of Lemma 17.
-
Assume that for all databases , for all walks , is a walk in .
Let and be two databases such that . Let . Then , which yields . If (resp. ), the result immediately follows: is then a walk (resp. trail) in that matches , thus , which means .
Assume now that . Since is a walk of that matches , there are two cases: either and there is nothing more to prove, or there exists a shorter walk in that has the same endpoints as . In that case, the assumption yields that is a walk in . Thus it is a walk in . This means that is not a shorter walk in either, which is a contradiction.
When the view determines the query, one may be interested in finding rewritings, that is, queries whose answer on the view image coincides with the answer to the original query on the original data [19]. This task may require additional techniques and ideas. In our setting, it turns out that the two tasks coincide. Indeed, Proposition 20 together with Lemma 18 lead to the corollary below, which states that when the view determines the query, a rewriting of the query is the query itself.
Corollary 21 (Rewriting).
Let . Let be a regular path view and be an RPQ such that . Let be a database. Then .
We are now ready to prove the first complexity result: deciding determinacy is PSpace-hard under all-walks, trail and shortest walk semantics.
Theorem 1. [Restated, see original statement.]
Determinacy for regular path queries and views is PSpace-hard under all-walks, trail and shortest walk semantics, even if the automata that define the queries and views are deterministic.
Proof.
Let . The proof is done by reduction from the Intersection Emptiness problem [15], which asks, given deterministic automata whether . Here, we will use the equivalent Union Universality problem: given deterministic automata , does ?
Let be two fresh symbols that do not occur in . We define as the usual 3-state deterministic automaton that accepts and we extend each automaton into a deterministic automaton with a new initial and final state such that .
Then it remains to remark that Proposition 20 implies that if and only if is universal.
Β Remark 22.
This lower bounds also holds when the input are given as regular expressions, with a very similar reduction from the Regular Expression Containment problem. [13]
4 All-walks and Trail Semantics
The goal of this section is to prove Theorem 2. To do so, we provide a decision procedure that works in PSpace. The main idea is to show that determinacy has the walk counterexample property: if there is a database that falsifies the alternate definition of determinacy provided by Proposition 20, then can be assumed to be a simply labeled simple walk.
Proposition 23 (Determinacy on simple walks).
Let . Let be a regular path view and be an RPQ. Then if and only if, for all databases that consist of only a simply labeled simple walk matching , .
Proof.
-
If , then Lemma 17 implies that is a walk in . Since is a substructure of ), this implies that .
-
Conversely, assume that for all databases that consist of only a simply labeled simple walk matching , . Let be an arbitrary database and be a (not necessarily simple) walk in .
Since matches , there exists such that . Let be an unfolding of that is simply labeled by . Formally, is a copy of in which each extra occurrence of a repeating edge or vertex of is replaced by a fresh copy. Additionally, only one label of each edge is kept, so that . Then, the assumption applied to the database that contains only yields .
Assume (resp. = trail). Let be the homomorphism (resp. edge-injective homomorphism) that folds into , that is, maps each vertex and edge of to the original object in . Since is closed under homomorphism (resp. edge-injective homomorphism), , which means .
Moreover, is monotone, thus . This implies that is a walk (resp. trail) in . Therefore, Proposition 20 implies that .
Proposition 23 leads to the definition of a counterexample, that is, a specific word in whose existence proves that .
Definition 24 (Counterexample under all-walks and trail semantics).
Let . Let be a regular path view and be an RPQ. A counterexample for and under is a word such that:
-
for some and ;
-
for all such that and , for all , .
Proposition 25 (Counterexample criterion).
Let . Let be a regular path view and be an RPQ. if and only if there exists a counterexample for and under .
Proof.
Proposition 25 is a simple consequence of Proposition 23. Indeed, if and only if there is a simply labeled simple walk that matches such that , that is, there is an edge of such that is not returned by any . It then remains to remark that a suitable counterexample is , with .
Example 26.
We present a few examples of determinacy under . Let as in Example 9.
-
1.
. Then . Indeed, words consist of concatenated blocks of the form , which are entirely βseenβ by the view:
While this example seems quite simple, it is interesting to remark that this is a case where does not determine under shortest walk semantics, as we will see in Example 29.
-
2.
. With the same argument, . Remark that, under trail semantics, parts of the database that would match the query might be hidden to the view due to repeated edges. However, these parts will also not be usable by the query.
In the example above, under , the -cycle is hidden to the view (no trail that matches contains the top vertex), but it is also not in any answer to . Under , the -cycle appears both in the view image and in the query answers. The fact that cycles are never an issue is a consequence of Proposition 23.
-
3.
. In this case, the view only βseesβ sequences of of odd length, but those can combine to cover any length, as shown below. Hence, .
However, for , . In the picture below, the word but the middle is βhiddenβ.
Remark that in all examples, contains a single query. This can actually be assumed without loss of generality, as a consequence of the proof of Theorem 2. Under , if and only if , where . We will see in Example 29 that this is not true under .
Proposition 25 is the main ingredient for proving Theorem 2: we show that the set of counterexamples is actually a regular language, whose emptiness can be checked in PSpace.
Theorem 2. [Restated, see original statement.]
Determinacy for regular path queries and views can be decided in PSpace under all-walks and trail semantics, even for nondeterministic query and view automata.
Proof.
Let . Let be a regular path view and be a regular path query. Let be the set of counterexamples for as defined in Definition 24. Let be any automaton for and be an automaton for . Our goal is to construct an automaton of at most exponential size such that , whose emptiness can then be checked in PSpace.
The existence of can be shown by using well-known closure properties of regular languages. We do this in Appendix B. Here, we will instead show a direct construction of . In addition to proving Theorem 2, this also serves as an introduction to the main result of Section 5, which expands upon the construction shown here.
Intuitively, runs on a word for which it nondeterministically guesses the factorization that yields the position that should be hidden to . Then runs in parallel on each possible starting position in , and checks that does not accept a factor of that contains .
Formally, is defined as follows:
-
-
-
-
For and , contains transitions of the following forms:
-
1.
-
2.
βif
-
3.
βif
-
1.
Claim 27.
.
Assume that . Then has an accepting run over that starts in some state and ends in . Remark that transitions of the form have to be used exactly once, as they are the only transitions that change the last component from to , and there is no transition that changes back to . This defines a unique factorization of as , where the transition is used when reading after having read .
Then, we prove by a straightforward induction that the state that is reached after reading the prefix of of length satisfies the following:
-
simulates a run of on .
-
If , then contains all states of that can be reached at position by starting on any position before . That is, if and only if there exists a suffix of such that .
-
If , then contains all states of that can be reached at the current position by starting on any position of . That is, if and only if if of the form , with and .
We conclude the proof by remarking that transitions of the form and enforce that . This means that for all factorizations of as with and , we have , which is precisely what Definition 24 requires. Thus .
The converse direction is proved in a very similar way. Assume that . Then and is of the form . We then exhibit an accepting run of on that uses the nondeterministic transition precisely when reading .
Claim 28.
Emptiness of can be checked in PSpace.
This is done by performing a reachability test from any initial state of to any accepting state of . As is a graph of exponential size, it is well known that this can be done in PSpace.
Therefore, emptiness of can be checked in PSpace. Proposition 25 states that if and only if for . This concludes the proof.
5 Shortest Walk Semantics
In this section, we prove Theorem 3. The proof reuses the ideas and the general approach of Section 4, which should be read first. However, the case of shortest walk semantics requires a much more careful and technical analysis. Section 5.1 presents the general idea and highlights what changes as compared to Section 4. Section 5.2 proves the main technical ingredient. Finally, Section 5.3 gives the PSpace decision procedure.
5.1 General Idea
As in Section 4, the starting point of our reasoning is Proposition 20: let be a regular path query and be a regular path view. Then if and only if, for each database and shortest walk of that matches , each edge of belongs to some walk in . What differs compared to Section 4 is that there are two cases that might cause an edge to be missing from the view image:
-
1.
Either does not belong to any walk that matches some , in which case the semantics under which is evaluated does not matter.
-
2.
Or does belong to some walk that matches , but all such walks are not shortest walks: one can always find a shorter walk with the same endpoints that also matches . Thus does not return under shortest walk semantics.
Case 2 hints at the fact that Proposition 23 is no longer true: under shortest walk semantics, determinacy does not have the walk counterexample property. There exists a regular path view and an RPQ such that , but all databases that witness this fact are not simple walks. This is shown in Example 29 below.
Example 29.
Recall and defined by and from Example 26. Let . Then , as witnessed by the following database :
Indeed, contains the βhorizontalβ walk labeled . However, the middle edge (highlighted in red) does not belong to . Indeed, despite belonging to the βhorizontalβ walks labeled , , and , none of these walks are shortest walks. For instance, the walk labeled is of length , but the βtopβ walk labeled is shorter, matches and has the same endpoints. However, we already know from Example 26 that does determine on databases that are simple walks.
Interestingly, this example only works when the matched walk contains a single sequence of . Indeed, when contains two sequences of , either the bottom or top βshortcutsβ make it so that the βhorizontalβ walk is no longer a shortest walk, and thus need not be returned.
As shown on the picture above, if one tries to βhideβ the red edge with the bottom βshortcutβ, then the blue walk becomes the shortest walk that matches from the leftmost vertex to the rightmost vertex. Therefore, the fact that the red edge is missing from the view is not an issue anymore. Thus, as counterintuitive as it may seem, .
Another important remark is that, contrary to what is explained in Example 26, under shortest walk semantics, we cannot assume that all queries of are grouped in a single query . Indeed, one can see that : in that case, a walk labeled can only be shortcut by a walk labeled , and not by a walk labeled .
As illustrated in Example 29, counterexamples in the case of shortest walk semantics are more involved than in the case of walk and trail semantics. Here, a counterexample is a pair , where is a walk that matches and is an edge of , such that, for each , for each factorization of as , one of the following holds. See the figure below to help visualize notations.
-
1.
.
-
2.
There is a such that , and .
As in the case of all-walks and trail semantics, it turns out that determinacy can be decided by only looking at the labels of counterexamples: we show in Section 5.2 how to prove a counterpart to Proposition 25 for shortest walk semantics. Then, we show in Section 5.3 that the set of these labels is a regular language. Thus, deciding determinacy amounts to checking the emptiness of this language. When is given as a deterministic automaton, we show that we can define an automaton of exponential size that precisely accepts this language and conclude that determinacy can be decided in PSpace.
5.2 Counterexample under Shortest Semantics
Definition 30 and Proposition 31 defined below are the key technical ingredients of Theorem 3.
Definition 30 (Counterexample under shortest semantics).
Let be a regular path view and be an RPQ. A counterexample for and under is a word , with and such that , and for all such that and , for all , one of the following holds:
-
;
-
there exists such that and .
Proposition 31.
Let be a regular path view and be an RPQ. if and only if there exists a counterexample for and under .
Proof.
Assume that there exists a counterexample . Then we build a database as follows:
-
1.
Add a simple walk with . Let and be the walks such that with , and .
-
2.
For each , for each factorization of as and as , with two vertices of :
-
If , there is nothing to do, and we continue with the next factorization.
-
If , we choose a word such that and . We know that such a word exists by definition of . Then we add to a simple walk using only fresh vertices from to with .
-
Then it is easy to check that is the shortest walk from its source to its target that matches . Thus . However, is not in . Indeed, for every , for every walk that contains , either the walk is not matched by , or contains a strictly shorter walk with the same endpoints that matches and does not contain .
Assume that . Proposition 20 implies that there exists a database and a walk in such that and is not a walk in . Since is not a walk in , at least one edge of does not belong to . Thus, is of the form .
Let , , and . Then . It remains to show that is a counterexample.
Let and be factorizations of and . Let be the corresponding factorization of , that is, and . Similarly, let be the corresponding factorization of .
Remark that is a walk from to . Let . Since does not belong to , then . There are two possibilities:
-
1.
does not match . This precisely means that , which satisfies the first requirement for counterexamples.
-
2.
matches but is not a shortest walk among walks from to that match . Thus contains a shorter walk from to such that . Let . Then and . Finally, remark that is shorter than and has the same endpoints. Thus does not match , otherwise . This implies that , which satisfies the second requirement for counterexamples.
5.3 Decision Procedure
We now have all ingredients to prove Theorem 3 below. This is done by showing that the set of counterexamples as defined in Definition 30 is actually a regular language, whose emptiness is equivalent to determinacy, as proved in Proposition 31. It now remains to give an automaton of at most exponential size that precisely accepts this language.
Theorem 3. [Restated, see original statement.]
Determinacy for regular path queries and views can be decided in PSpace under shortest walk semantics, provided that the query is given as a deterministic automaton.
Proof.
Let be a regular path view and be a regular path query. Let be the set of counterexamples for , as defined in Definition 30. For each , let be any automaton for and be a deterministic automaton for . The automaton for is a much more involved version of the automaton used in the proof of Theorem 2, which should be read first.
Intuitively, runs on a word for which it nondeterministically guesses the factorization and the position that should be hidden to . For each factor (denoted as in Definition 30) of that contains , for each , either does not belong to (as in Theorem 2) or nondeterministically guesses a βshortcutβ for : a word such that , and maintains information to ensure that using this βshortcutβ (ie, replacing with in ) does not create an accepting run of .
Instead of giving an explicit transition table for , which would be very technical and not very informative, we give a high-level description of the information that are maintained and propagated throughout a computation of on . At step of the computation, a state of encodes the following information:
-
The state of the computation of at step on .
-
A bit that nondeterministically flips to to say when has been read.
-
For each , an array that maps each and integer to the states of that are reachable after a run of on a factor of that started before Mid flipped, at step , with the added information that . Note that, thanks to standard pumping lemma techniques, we only count up to , as will be explained below.
This is a major difference with the proof of Theorem 2. Knowing when accepts a factor that contains is not enough: we also need to know the length of said factor (in order to find a shorter βshortcutβ) and the state of at the beginning of said factor (to ensure that using the βshortcutβ does not yield an accepting run of ).
-
A set that contains βerrorβ states of , that is, states that can be reached at step by taking one of the βshortcutsβ. Err must contain no accepting state at the end of the computation. is populated as follows:
-
(a)
If , . There are no βshortcutsβ before .
-
(b)
Otherwise, , where is the th symbol in . We propagate the states in Err according to the transition function of .
-
(c)
Then, if , this means that the suffix of length at step would reveal through . Nondeterministically guess a word such that and add to : using this βshortcutβ brings to at step .
-
(a)
Item is the most critical part. Its correctness hinges on the following key remarks:
-
If no suitable exists, the run aborts and rejects . This corresponds to the case where there is no way to prevent from revealing .
-
When , we no longer need to know the precise value of . Indeed, due to standard pumping lemma techniques, if there exists a word of length such that , then there exists a similar with .
-
being deterministic is crucial here. It ensures that at step , is in a unique state . Keeping track of all possible runs of a nondeterministic automaton would require to be of exponential size.
Figure 1 provides a visual help for notations and update rules on a step that occurs after the hidden edge, shown in red. Remark that each state only stores a polynomial amount of information, which means that is of exponential size in the size of and . Thus, checking its emptiness can be done in PSpace.
It remains to show that . As in the proof of Theorem 2, this is done by a technical but not very informative induction that shows that the invariants on Figure 1 are maintained. The precise update rules for are given in Appendix C, along with the induction hypotheses. This concludes the proof.
6 Conclusion
We have shown that the view-based query determinacy problem is decidable for regular path queries and views under three walk-based semantics: all-walks, trail and shortest walk semantics. We focused on trail and shortest walk semantics due to their prevalence in real-life systems, but our techniques naturally extend to other semantics. On the one hand, our analysis of trail semantics naturally extends to semantics that filter out results based on topological constraints (called restrictors in GQL [5], or filter-based in [16]), such as acyclic or simple walk semantics. On the other hand, the general idea for shortest walk semantics most likely111This claim is more prudent than for restrictors due to the wide variety of imaginable ranking criteria! applies to other ranking semantics (called selectors in GQL, or order-based in [16]), which return the βbestβ results according to some criterion, such as k-shortest or cheapest.
Complexity-wise, we proved that the problem is PSpace-hard under all three semantics, and provided a matching upper bound under all-walks and trail semantics. The case of shortest walk semantics is not entirely solved: our results only show that the problem is PSpace-complete when the query is given as a deterministic automaton. Determinizing the input in order to apply our decision procedure would yield an ExpSpace upper bound, which does not match the known lower bound. We leave the search for a tighter lower bound or a more efficient upper bound for future work.
Note that we have only considered the static analysis version of the problem. Another interesting direction for future work is the study of view-based query processing tasks where the view image is given as input, such as computing certain answers and non-answers [1].
References
- [1] Serge Abiteboul and Oliver M. Duschka. Complexity of answering queries using materialized views. In Proceedings of the Seventeenth ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems, PODS β98, pages 254β263, New York, NY, USA, 1998. Association for Computing Machinery. doi:10.1145/275487.275516.
- [2] Foto N. Afrati. Determinacy and query rewriting for conjunctive queries and views. Theoretical Computer Science, 412(11):1005β1021, 2011. doi:10.1016/j.tcs.2010.12.031.
- [3] Renzo Angles, Marcelo Arenas, Pablo BarcelΓ³, Peter A. Boncz, George H. L. Fletcher, Claudio Gutierrez, Tobias Lindaaker, Marcus Paradies, Stefan Plantikow, Juan F. Sequeda, Oskar van Rest, and Hannes Voigt. G-CORE: A core for future graph query languages. In SIGMOD, pages 1421β1432. ACM, 2018. doi:10.1145/3183713.3190654.
- [4] Diego Calvanese, Giuseppe De Giacomo, Maurizio Lenzerini, and Moshe Y. Vardi. Lossless regular views. In Proceedings of the Twenty-First ACM SIGMOD-SIGACT-SIGART Symposium on Principles of Database Systems, PODS β02, pages 247β258, New York, NY, USA, 2002. Association for Computing Machinery. doi:10.1145/543613.543646.
- [5] Alin Deutsch, Nadime Francis, Alastair Green, Keith Hare, Bei Li, Leonid Libkin, Tobias Lindaaker, Victor Marsault, Wim Martens, Jan Michels, Filip Murlak, Stefan Plantikow, Petra Selmer, Hannes Voigt, Oskar van Rest, Domagoj VrgoΔ, Mingxi Wu, and Fred Zemke. Graph pattern matching in GQL and SQL/PGQ. In SIGMODβ22. ACM, 2022.
- [6] Nadime Francis. Asymptotic Determinacy of Path Queries using Union-of-Paths Views. Theory of Computing Systems, 61(1):156β190, July 2017. doi:10.1007/s00224-016-9697-x.
- [7] Nadime Francis, AmΓ©lie Gheerbrant, Paolo Guagliardo, Leonid Libkin, Victor Marsault, Wim Martens, Filip Murlak, Liat Peterfreund, Alexandra Rogova, and Domagoj VrgoΔ. A Researcherβs Digest of GQL. In Floris Geerts and Brecht Vandevoort, editors, ICDTβ23, volume 255 of LIPIcs. Schloss Dagstuhl β Leibniz-Zentrum fΓΌr Informatik, 2023. doi:10.4230/LIPIcs.ICDT.2023.1.
- [8] Nadime Francis, Alastair Green, Paolo Guagliardo, Leonid Libkin, Tobias Lindaaker, Victor Marsault, Stefan Plantikow, Mats Rydberg, Petra Selmer, and AndrΓ©s Taylor. Cypher: An evolving query language for property graphs. In Proceedings of the 2018 International Conference on Management of Data, SIGMOD β18, pages 1433β1445, New York, NY, USA, 2018. Association for Computing Machinery. doi:10.1145/3183713.3190657.
- [9] Nadime Francis, Luc Segoufin, and Cristina Sirangelo. Datalog Rewritings of Regular Path Queries using Views. Logical Methods in Computer Science, 11(4), December 2015. doi:10.2168/LMCS-11(4:14)2015.
- [10] Grzegorz GΕuch, Jerzy Marcinkowski, and Piotr Ostropolski-Nalewaja. The First Order Truth Behind Undecidability of Regular Path Queries Determinacy. In 22nd International Conference on Database Theory (ICDT 2019), volume 127 of Leibniz International Proceedings in Informatics (LIPIcs), pages 15:1β15:18, Dagstuhl, Germany, 2019. Schloss Dagstuhl β Leibniz-Zentrum fΓΌr Informatik. doi:10.4230/LIPIcs.ICDT.2019.15.
- [11] Tomasz Gogacz and Jerzy Marcinkowski. The hunt for a red spider: Conjunctive query determinacy is undecidable. In Logic in Computer Science (LICS), 2015 30th Annual ACM/IEEE Symposium on, pages 281β292, United States, 2015. Institute of Electrical and Electronics Engineers. doi:10.1109/LICS.2015.35.
- [12] Tomasz Gogacz and Jerzy Marcinkowski. Red spider meets a rainworm: Conjunctive query finite determinacy is undecidable. In Proceedings of the 35th ACM SIGMOD-SIGACT-SIGAI Symposium on Principles of Database Systems, PODS β16, pages 121β134, New York, NY, USA, 2016. Association for Computing Machinery. doi:10.1145/2902251.2902288.
- [13] Harry B. Hunt, Daniel J. Rosenkrantz, and Thomas G. Szymanski. On the equivalence, containment, and covering problems for the regular and context-free languages. Journal of Computer and System Sciences, 12(2):222β268, 1976. doi:10.1016/S0022-0000(76)80038-4.
- [14] Sara Khichane. Study of new semantics for regular path queries. Masterβs thesis, UniversitΓ© Paris-CitΓ©, 2024.
- [15] Dexter Kozen. Lower bounds for natural proof systems. In 18th Annual Symposium on Foundations of Computer Science (sfcs 1977), pages 254β266, 1977. doi:10.1109/SFCS.1977.16.
- [16] Victor Marsault and Antoine Meyer. Designing and comparing rpq semantics. In ICDTβ26, 2026. To appear.
- [17] Wim Martens, Matthias Niewerth, and Tina Popp. A trichotomy for regular trail queries. Logical Methods in Computer Science, Volume 19, Issue 4, December 2023. doi:10.46298/lmcs-19(4:20)2023.
- [18] Alberto O. Mendelzon and Peter T. Wood. Finding regular simple paths in graph databases. SIAM Journal on Computing, 24(6):1235β1258, 1995. doi:10.1137/S009753979122370X.
- [19] Alan Nash, Luc Segoufin, and Victor Vianu. Views and queries: Determinacy and rewriting. ACM Trans. Database Syst., 35(3), 2010. doi:10.1145/1806907.1806913.
- [20] Jean-Γric Pin, editor. Handbook of Automata Theory, volume 1. EMS, 2021.
- [21] TigerGraph Team. TigerGraph Documentation β version 3.1, 2021. URL: https://docs.tigergraph.com/.
Appendix A Handling Empty Words in Query and View Languages
In this section, we show how the case where the views or the query accept the empty word reduces to the case where is forbidden, by using no more than Definition 13.
Proposition 32.
Let . Let be a regular path query and be a regular path view. Then if and only if:
-
1.
If , then there exists such that ;
-
2.
, where is defined as any automaton such that .
Proof.
Let . Assume that .
-
Assume that . Let be a database that contains only a single isolated vertex , and let be the empty database. Then and . Assume for contradiction that for all , . Then . However, , thus .
-
Assume for contradiction that . Then there exist two databases and such that but . Since , this means that there exists an edge that occurs only in one of or . Since and only differ on walks of length , also only occur in one of or . Remark now that since , and only differ on walks of length , that is, isolated vertices in the view images. We build two new databases and from and by adding these isolated vertices to both and . It remains to remark that while still only occur in one of or . Thus .
Conversely, assume that Properties 1 and 2 hold. Let and be two databases such that . In particular, and contain the same walks of length greater than . Thus , from which implies that . If , this immediately yields , hence . Otherwise, and might differ on walks of length . However, gives such that . Since , and must have the same walks of length (that is, and have the same set of vertices). Thus which concludes the proof.
Appendix B Alternate Construction of for the Proof of Theorem 2
Let be a regular path view and be a regular path query. By using standard automaton construction and closure properties, we show that there exists an automaton of exponential size (in the size of the automata that define and ) that accepts , the set of counterexamples for and under and (see Definition 24).
Let be a disjoint copy of , whose symbols are called marked symbols. For , we use to denote its copy in .
Let be the automaton that accepts words in with a single marked symbol, that is . is simply constructed as a copy of any automaton for that nondeterministically guesses when to add the marked symbol, and is thus of polynomial size in the size of .
Let be any automaton for . Similarly, let be a copy of that accepts words in with a single marked symbol. Finally, let be an automaton such that . Again, can be guaranteed to be of polynomial size in the size of . Intuitively, contains the words in which βseesβ the marked symbol.
Finally, let be an automaton for . Intuitively, accepts the words in which the marked symbol is βhiddenβ to . Indeed, if is such that sees , then with for some . This means that and thus . Remark that can be guaranteed to be at most of exponential size in the size of , with a standard construction for the complement of a nondeterministic automaton.
It then remains to remark that , is simply with the mark removed. Thus can be constructed as an automaton of at most exponential size.
Appendix C Additional Material for the Proof of Theorem 3
This section completes the proof of Theorem 3 given in Section 5.3.
C.1 Update Rules
A formal description of the transitions of are given by the update rules below. Notations follow the notations of the proof in Section 5.3.
Initial state.
-
, the initial state of .
-
. All other values are set to .
-
.
Computation step strictly before when reading a symbol .
-
-
.
-
For each :
-
β
If , .
-
β
If , .
-
β
-
For each , if and .
Computation step on or after , when reading a symbol .
-
-
.
-
For each :
-
β
If , .
-
β
If , .
-
β
-
For each , .
-
Then, for each :
-
β
If , skip this step.
-
β
Otherwise, nondeterministically choose a state such that there exists a word with and . If no such exists, abort the run.
-
β
.
-
β
End state.
Accepting states are states where , and .
C.2 Induction Hypotheses
The correctness of comes from the following claim, that imitates Definition 30.
Claim 33.
Let and assume that has a run on such that Mid flips to after reading if and only if there exists a family of words such that, for each factorization of as , for all , one of the following holds:
-
1.
;
-
2.
, where , , .
Moreover, this run is accepting if and only if and in each case 2, .
The proof of this claim is done by inductively constructing the family along a run of . The construction relies on the following induction hypotheses that hold at step of the computation on .
-
and for , where is the prefix of length of .
-
For and :
-
For and and :
-
For , .
-
For :
where, in the equation above, is any state in , is replaced by if and is replaced by if .
Finally, the run is accepting if and only if and , which is exactly what the claim requires.
