Revisiting the Expressiveness Landscape of Data Graph Queries


Abstract

The study of graph queries in database theory has spanned more than three decades, resulting in a multitude of proposals for graph query languages. We can identify three main families of languages, with the canonical representatives being: (1) regular path queries, (2) walk logic, and (3) first-order logic with transitive closure operators. This paper provides a complete picture of the expressive power of these languages in the context of data graphs. Specifically, we consider a graph data model that supports querying over both data and topology. For example, “Does there exist a path between two different persons in a social network with the same last name?”. We also show that an extension of (1) with regular path comparisons, augmented with transitive closure operators, can unify the expressivity of (1)–(3).

graph databases ,query languages ,data graphs ,expressiveness

1 Introduction↩︎

Graph databases are data models with a multitude of natural applications including social networks, semantic web, biology, ecology, supply chain management, and business process modeling. With graphs as one of the main repositories of data, graph querying has become a major component in data wrangling. Indeed, graph database systems – like Neo4j, Oracle, TigerGraph, among many others – have increasingly found usage in a plethora of application domains.

One important feature in graph query languages is the ability to query for paths over a given database. In fact, much of the effort in the study of graph query languages in database theory has been motivated by the need to support path queries. For example, in real world query languages (like Neo4j Cypher queries) one uses patterns like:

    (?x)=[:friend*]=>(Erdos)

to find nodes that are connected to Erdos by the friend relation (assuming it is symmetric). Similar capabilities are also supported by SPARQL property paths. A systematic study of query languages supporting “path patterns” has been undertaken in database theory since the 1990s, resulting in a plethora of query languages over graphs. The core of such languages can be classified into three categories: (1) extensions of regular path queries [1][3], (2) walk logic [4], [5], and (3) first-order logic with transitive closure operators [2], [6]. In addition, while the original query languages were studied within the basic graph database setting of edge-labelled graphs with finitely many labels, recent developments suggest the importance of supporting data in the model, not just topology. For example, if a node represents a person (with data including age, firstname, lastname, etc.) in a social network and an edge represents a “friend-of” relation, then we might be interested in a pair of friend-of-friends (i.e. transitive closure of friend relations) with the same data component lastname. To support such queries, an extended graph data model of data graphs [2], [7] was proposed, wherein additional binary relations \(\equiv_{\mathrm{\small data} ,i} \subseteq V \times V\) for \(1 \leq i \leq n\) over nodes in the graph check whether two nodes have the same \(i^{th}\) data component (e.g. lastname). The bulk of graph queries can be (and have been) extended to the setting of data graphs [2], [5], [7], [8].

Zoo of query languages over data graphs. We proceed by first surveying the categories (1)–(3) of graph query languages. The first category of query language is based on the idea of using regular languages to describe “path patterns”. This originates in the seminal paper of Mendelzon and Wood [1], which introduces the so-called Regular Path Queries (RPQ). For example, to describe the friend-of-friends relation, one may simply write the path pattern \((\texttt{friend})^*\), where \(\texttt{friend}\) is a name of a relation in the database describing the friend-of relation. The class RPQ has been extended to operate over data graphs [2], [7], and to support unions/conjunctions [9][11]. For example, the query language Conjunctive Regular Path queries denoted CRPQ arose as part of the language GraphLog [12]. It has also been extended to support regular path comparisons [3], utilized in the language Extended CRPQ(ECRPQ). In particular, register automata – or, equivalently, regular expressions with memory – are used to extend the notion of regular path patterns to data paths, an alternating sequence of data and edge labels. In register automata an unbounded register/memory is required to store data. For example, to enforce that the start node \(v\) and end node \(w\) correspond to persons with the same lastname attribute, an automaton can save the last name of the first person \(v\) in the register and then check if it is the same as the last name of the last person \(w\). The idea of using register automata to express regular patterns over data paths, or tuples of data paths, can also be easily extended to CRPQ and ECRPQ, as well as their extensions with negations CRPQ\(_\neg\), and ECRPQ\(_\neg\). To emphasize the data model used by the query languages, on which they operate, we denote RPQ, CRPQ, etc. by RDPQ, CRDPQ, etc., as suggested by [2].

The second paradigm is that of Walk Logic (WL) [4], which takes paths within graphs as the fundamental data item referenced within query variables. Paths are manipulated through first-order predicate logic operations: roughly the paradigm is “relational calculus for paths”. As explained in [5], WL can be construed as a query language over data graphs.

The third paradigm is inspired by first-order logic with transitive closure operators [6]. This logic was studied in the setting of data graphs in [2], where additional binary relations \(\equiv_{\mathrm{\small data} ,i}\subseteq V \times V\) over nodes in the graph are introduced that check whether two nodes have the same \(i^{th}\) data component. This resulting logic (called FO\(^*(\equiv_{\mathrm{\small data} })\)) subsumes GXPath [2] and also regular (data) queries [13].

Finally, we mention another language that can be related to the first paradigm, the recently proposed Graph Pattern Calculus (GPC) [14], [15], which arose during the ongoing standardization efforts [16] of SQL/PGQ and GQL for the more expressive graph data model of property graphs.

Figure 1: Prior query languages (extended with data). In the diagrams, for any pair of languages L and M, the arrow L \rightarrow M signifies that M is more expressive than L. Languages L and M are considered incomparable if there is no directed path (after taking transitive closure) between them.

Contributions: We begin by studying the prior proposals for graph query languages in the framework of data graphs. We analyze the expressiveness of these languages, identifying which containments hold: see Figure 1. In the figure, the containment results indicated by red edges are either known or trivial, while other containment and incomparability results are new. Specifically, we show that over data graphs the most expressive existing language FO(ERDPQ) from the first paradigm strictly subsumes WL, RDPQ, as well as GPC. Although we show that FO\(^*(\equiv_{\mathrm{\small data} })\), from Category (3), subsumes RDPQ, we prove that it is incomparable with FO(ERDPQ), as well as GPC. This leaves the question of whether there is a natural way to reconcile FO(ERDPQ) and FO\(^*(\equiv_{\mathrm{\small data} })\). Towards resolving this, we propose a language that subsumes all the existing ones. A summary of the revised landscape in terms of expressive power can be found in Figure 2.

Figure 2: Expressiveness of languages.

At a high level, our proofs utilize the usual expressiveness toolbox in finite model theory – e.g. automata and complexity-theoretic arguments. But their application to some of the finer-grain comparisons we consider here requires some subtlety. For example, since FO(ERDPQ) combines regular expression power with some arithmetic, in separating FO(ERDPQ) from MWL – an extension of WL introduced in this paper with expressiveness between FO(ERDPQ) and WL – we require a combination of circuit complexity bounds and rewriting techniques; in showing RDPQ is not subsumed by GPC, we need to bound the expressiveness of GPC, and thus require a variation of the pumping lemma for automata that is tailored towards the fine points of the GPC syntax.

Limitations: Deviations from other proposals and standards. This paper is a step towards a better understanding of the expressiveness landscape for these languages. In doing so, we have made a number of simplifications both at the data model and query language level, relative to languages considered by both practitioner query languages and the evolving standards. One of these simplifications is at the data model level. There is a more flexible (and complex) data model called property graphs [16], [17], which allows both edge and node labels, both of which can be varying or bound by a specific “schema”. This model has been in the spotlight in database theory in recent years, and property graphs will serve as the data model for GQL, the standard graph query language that is currently under intense development (e.g. see [14][16]).

Another simplification involves directionality in navigating a graph. We deal with a directed graph model, but in our formalization of the regular path query and walk logic paradigms, we allow only navigation in the forward direction. This is consistent with formalization of traditional query languages like R(D)PQ [2], ECRPQ [3], and Walk Logic [4]. On the other hand, queries in \(GPC\) allow navigation in both directions. Such a small “mismatch” would immediately render \(GPC\) to be incomparable with the aforementioned languages for trivial reasons. For a fair comparison, one could either (i) extend RDPQ, ECRPQ, and Walk Logic with bidirectional navigations, or (ii) allow only a forward direction in \(GPC\). We opted for (ii). See further discussion in Section 7.

A third deviation concerns support for trails: one of our considered languages, \(GPC\), allows one to restrict to paths with no repetition among nodes. We omit this feature, but only to keep the exposition briefer: we show in Section 7 that all the results still hold when the syntax of \(GPC\) is extended to include this. Although our work assumes a simpler data and query model, we believe our results will be useful in considering the expressiveness of languages making use of the full property graph data model.

2 Preliminaries↩︎

General notation. We use \(\mathbb{N}\) and \(\mathbb{Z}_{>0}\) to denote the sets of non-negative integers and positive integers, respectively. For any two \(i\) and \(j\) in \(\mathbb{N}\) where \(i<j\), the notation \([i,j]\) represents the set \(\{i, i+1, \dots, j\}\). If \(i=1\), we simply write \([j]\), abbreviating \([1,j]\). Let \(m\) be a mapping, and let \(d\) and \(i\) be elements in the domain and image of \(m\), respectively. The notation \(m[d\mapsto i]\) represents the mapping equivalent to \(m\), except that \(d\) is now mapped to \(i\).

Figure 3: Data graph G, where p stands for parent, s for spouse, and f stands for friend.

Data model. In this work, we are concerned with graphs that incorporate data, referred to as data graphs. Specifically, each node corresponds to a unique id and is accompanied by additional attributes. For instance, as shown in Figure 3, nodes possess attributes such as Name (with the data type string) and Age (with the data type natural number). To denote the sets of ids and other pertinent attributes (“properties”), we use \(\mathcal{D}_{\mathrm{\small id} }\) and \(\mathcal{D}_{\mathrm{\small prop} }\), respectively. Here, \(\mathcal{D}_{\mathrm{\small prop} }\) represents a \(k\)-ary relation, where \(k\) is the number of attributes that nodes have, excluding the id. For the example shown in Figure 3, \(k\) is 2. The data domain, denoted as \(\mathcal{D}\), is the Cartesian product of \(\mathcal{D}_{\mathrm{\small id} }\) and \(\mathcal{D}_{\mathrm{\small prop} }\) when \(k > 0\); otherwise, when \(k = 0\), \(\mathcal{D}\) is equal to \(\mathcal{D}_{\mathrm{\small id} }\).

Formally, a data graph is a directed graph in which each node corresponds to a data value. To define the data value of a node, we introduce two key functions, \(\mathrm{\small id}\) and \(\nodedata\). The function \(\mathrm{\small id}\) maps each node \(v\) to its unique id. For example, in Figure 3, we have \(\mathrm{\small id} (n_2) = 07\), \(\mathrm{\small id} (n_9) = 24\), and \(\mathrm{\small id} (n_{13}) = 29\). When \(k > 0\), for each \(i \in [k]\), we define \(\nodedata_i\) as the function that maps each node \(v\) to the \(i^{\text{th}}\) component of \(\nodedata[v]\). In other words, if \(\nodedata[v] = (d_1, \dots, d_i, \dots, d_k)\), then \(\nodedata_i(v) = d_i\). For instance, for nodes \(n_2\), \(n_9\), and \(n_{13}\), we have \(\nodedata(n_9) = (\textit{Paul}, 5) = \nodedata(n_{13})\), and \(\nodedata_2(n_2) = 66\). Since the function \(\mathrm{\small id}\) is injective, for any two nodes \(v\) and \(v'\) in \(V\), \(\mathrm{\small id} (v) = \mathrm{\small id} (v')\) if and only if \(v = v'\). The tuple \((\mathrm{\small id} (v), \nodedata(v)) \in \mathcal{D}\) represents the data value of node \(v\). For simplicity, we often treat a node’s id as synonymous with the node itself.

Our definition of data graphs extends the one provided in [7]. The primary distinction is that, in our definition, each node has a unique id as part of its data value, as is done in [5]. This slight modification allows us to model node identity in all our query languages without cluttering them with additional syntax. More importantly, treating ids as part of node data values is realized through the \(\mathrm{\small id}\) function, and this feature plays a significant role in the expressiveness of the regular data path query language (RDPQ) and its extensions, defined in Section 3.2. For example, the query “Does a node appear more than once along a path \(\pi\)?” would be inexpressible in RDPQ and its extensions if ids were not considered part of node data values, or if the \(\mathrm{\small id}\) function were removed from our definition. In such a case, these languages and other languages considered in this paper would become incomparable. However, this would contradict one of our goals: to characterize existing query languages for graphs with data and identify their core features.

The formal definition of data graphs is as follows:

Definition 1 (Data Graph). A data graph \(G\) over alphabet \(\Sigma\) and data domain \(\mathcal{D}\) is a quadruple \((V,E,\mathrm{\small id} ,\nodedata)\), where

  • \(V\) is a non-empty finite set of nodes.

  • \(E \subseteq V\times \Sigma \times V\) is a set of labeled edges.

  • \(\mathrm{\small id} : V \rightarrow \mathcal{D}_{\mathrm{\small id} }\) is an injective function mapping each node to an id.

  • \(\nodedata: V \rightarrow \mathcal{D}_{\mathrm{\small prop} }\) is a function assigning an element in \(\mathcal{D}_{\mathrm{\small prop} }\) to each node in \(V\).

A path \(\rho\) in the data graph \(G\) is a non-empty alternating sequence \[v_0 \thinspace a_1 \thinspace v_1 \thinspace\dots v_{n-1} \thinspace a_n \thinspace v_n\] where \(v_i \in V\), \(a_j \in \Sigma\), and \((v_{l-1},a_l,v_l)\) forms an edge in \(E\) for all \(i\), \(j\), and \(l\). The length of \(\rho\), denoted as \(|\rho|\), is \(n\). The set of positions of \(\rho\) is \([0,n]\), with \(v_i\) being the node at position \(i\) for every \(i \in [0,n]\). The data path corresponding to \(\rho\) is the string \(d_0 \thinspace a_1 \thinspace d_1 \dots a_n \thinspace d_n\), where \(d_i\) represents the data value associated with \(v_i\) for every \(i \in [0,n]\). This data path is denoted as \(\mathbf{dp}(\rho)\). The label of \(\rho\) is \(\mathbf{lb}(\rho) = a_1\dots a_n\). A path \(\rho\) is considered a simple path if \(v_i \neq v_j\) for every \(i,j \in [0,n]\) and \(i \neq j\). For example, consider the path in the graph from Figure 3: \[\rho = n_4 \thinspace{s} \thinspace n_3 \thinspace{p} \thinspace n_{11} \thinspace{p} \thinspace n_9 \thinspace{f} \thinspace n_{13}\] It is a simple path, with \(\mathbf{lb}(\rho) = {s \thinspace p \thinspace p \thinspace f}\) and \(\mathbf{dp}(\rho) = (03,\textit{Mary},56) \ldots\linebreak (29,\textit{Paul},5)\).

Given two paths \(\rho = v_0 ~ a_1 ~ v_1 \dots v_n\) and \(\rho' = v'_0 ~ a'_1 ~ v'_1 \dots v'_m\), \(\rho\) can be concatenated with \(\rho'\) if \(v_n = v'_0\). The concatenated path, denoted as \(\rho \cdot \rho'\), is given by \(v_0 ~ a_1 \dots v_n ~ a'_1 ~ v'_1 \dots v'_m\). A graph \(G\) is classified as a chain if it is connected and each node has at most one predecessor and at most one successor.

Queries. Informally, a query is a function that returns a Boolean value, taking as input a data graph over a given \(\Sigma, \mathcal{D}\), along with a valuation that maps a predetermined set of free variables of different types (paths, nodes, positions) to values of the appropriate kind. While these languages often vary in the types of free variables they accommodate, all our query languages support Boolean graph queries, where the input is solely a data graph over \(\Sigma, \mathcal{D}\). Usually, \(\Sigma, \mathcal{D}\) will be evident from the context, so we’ll omit them.

Definition 2. Language subsumption A query language \(L\) defines a set of queries, and we say language \(L\) is subsumed by* language \(L'\) if every Boolean graph query expressible in \(L\) is also expressible in \(L'\).*

In previous discussions, we’ve addressed languages semantically as collections of queries, yet of course, languages of interest are usually defined using syntax for expressions. Often, we identify the expressions with their corresponding queries. Therefore, given a (syntactically defined) query language, a related problem is to evaluate an expression in the language on a given data graph. This is the query evaluation problem for the language.

3 Existing query languages for graphs with data↩︎

3.1 Graph querying based on path quantification↩︎

Walk logic (WL) is a first-order graph query language that quantifies over variables ranging paths and positions within paths [4]. With the capability to manipulate paths and positions, the query \(Q_H\): “Is there a Hamiltonian path in the graph?” can be readily expressed using WL. Before providing an exact definition, it is instructive to understand how WL expresses that a graph is Hamiltonian. A graph is Hamiltonian if it possesses a path that (1) is simple (with no repeated nodes) and (2) visits all nodes. This can be expressed using a logic that quantifies over paths and positions within a given path. We employ variables \(\pi\) and \(\omega\) for variables ranging over paths, and \(\ell^\pi\) and \(m^\pi\) variables ranging over positions within the path referenced by variable \(\pi\). Intuitively, each path variable \(\pi\) in WL is interpreted as a path \(\rho = v_0 \thinspace a_1 \dots a_i \thinspace v_i\) within the data graph \(G\). Each position variable \(\ell^\pi\) represents the position \(r \in [0, i]\) of a node along the path \(\rho\). Recall that \(v_r\) is the node at the position \(r\). Hence, the following WL formula captures that path \(\pi\) is simple: \[\phi_{\mathrm{\small simple} }(\pi):= \forall \ell^{\pi},m^{\pi}.\;\ell^{\pi} \neq m^{\pi} \rightarrow \neg(\ell^{\pi} \equiv_{\mathrm{\small id} } m^{\pi}),\] where \(\ell^{\pi} \equiv_{\mathrm{\small id} } m^{\pi}\) indicates that positions referenced by \(\ell^{\pi}\) and \(m^{\pi}\) point to the same node. A path \(\rho\) visits all nodes in a graph \(G\) if and only if for every path \(\rho'\) and a node \(n'\) in \(\rho'\), there exists a node \(n\) in \(\rho\) such that \(n\) is identical to \(n'\). Therefore, the subsequent WL formula verifies whether (2) is fulfilled: \[\phi_{\mathrm{\small visitall} }(\pi):= \forall \omega.\;\forall m^\omega.\;\exists \ell^\pi.\;\ell \equiv_{\mathrm{\small id} } m.\] Hence, formula \(\exists \pi.\;\phi_{\mathrm{\small simple} }(\pi) \wedge \phi_{\mathrm{\small visitall} }(\pi)\) expresses Hamiltonicity.

The syntax of WL assumes a countably infinite set \(\Pi\) of path variables, coupled with a set \(\Lambda\) of position variables indexed by path variables. A position variable \(\ell\) is of sort \(\pi\) and is usually denoted as \(\ell^\pi\) [4], [5], representing positions within the path \(\pi\). The \(\pi\) superscript is omitted when the context is clear.

Definition 3. Let \(\Sigma\) be a finite alphabet, \(\Pi\) a countably infinite set of path variables, and \(\Lambda\) a set of position variables indexed by path variables. The formulas of WL over \(\Sigma\), \(\Pi\), and \(\Lambda\) are defined inductively as follows:

  • \(E_a(\ell^\pi,m^\pi)\), \(\ell^\pi < m^\pi\), \(\ell^\pi \equiv_{\mathrm{\small id} } n^\omega\), and \(\ell^\pi \equiv_{\mathrm{\small data} } n^\omega\) are atomic formulas, where \(\pi, \omega \in \Pi\), \(\ell^\pi, m^\pi, n^\omega \in \Lambda\), and \(a \in \Sigma\).

  • If \(\phi\) and \(\psi\) are formulas, so are \(\neg \phi\), \(\phi \vee \psi\), \(\exists \ell^\pi.\;\phi\), and \(\exists \pi.\;\phi\).

Note: in WL we can say \(\ell^\pi <n^\omega\) only if \(\pi = \omega\).

Let \(\phi\) be a WL formula and \(\alpha\) be a mapping that assigns paths in \(G\) to path variables and node positions to position variables. Assume \(\alpha(\pi)=v_0 \thinspace a_1\dots a_i \thinspace v_i\), \(\alpha(\omega)=w_0 \thinspace b_1\dots b_{j} \thinspace w_{j}\), \(\alpha(\ell^\pi)=r, \alpha(m^\pi) = s \in [0,i]\), and \(\alpha(n^\omega) =t \in [0,j]\). We say \(G\) satisfies \(\phi\) under \(\alpha\), denoted by \((G,\alpha) \models \phi\), if one of the following holds:

  1. \(\phi = E_a(\ell^\pi,m^\pi)\), \(s=r+1\), and \(a = a_s\).

  2. \(\phi = \ell^\pi < m^\pi\) and \(r < s\).

  3. \(\phi = \ell^\pi \equiv_{\mathrm{\small id} } n^\omega\) and \(\mathrm{\small id} (v_r)=\mathrm{\small id} (w_t)\).

  4. \(\phi = \ell^\pi \equiv_{\mathrm{\small data} } n^\omega\) and \(\nodedata(v_r)=\nodedata(w_t)\).

  5. \(\phi = \neg \psi\) and it is not the case that \((G, \alpha) \models \psi\).

  6. \(\phi = \phi' \vee \phi''\) and we have \((G,\alpha) \models \phi'\) or \((G,\alpha) \models \phi''\).

  7. \(\phi = \exists \ell^\pi. \psi\) and there is a node position \(r\) in \(\alpha(\pi)\) such that
    \((G, \alpha [\ell^\pi\mapsto r]) \models \psi\).

  8. \(\phi = \exists \pi. \psi\) and there is a path \(\rho\) in \(G\) such that \((G,\alpha[\pi \mapsto \rho]) \models \psi\).

3.2 Querying graphs based on regular languages↩︎

The language discussed in the preceding section has limitations in expressing certain aspects of path label patterns. Consider the query: \[\begin{align} Q_{\boldsymbol{even}}:=&\textit{``Is there a node labelled a connected by a path of even length}\\ & \textit{to a node labelled b in graph G?''.} \end{align}\]

In WL the query cannot be expressed [4]. However, the set of paths satisfying this property can be described using a regular path query (RPQ). An RPQ comprises three elements: a source node \(v_s\), a target node \(v_t\), and a regular expression \(e\) (or an NFA \(A\)). A pair of nodes \((v_s, v_t)\) satisfies such a query if there exists a path from \(v_s\) to \(v_t\) with the label of \(\rho\) is in the language defined by \(e\), that is \(\mathbf{lb}(\rho)\in L(e)\).

Various extensions of regular path query languages have been introduced in the literature, initially for labelled graphs and later for graphs with data. For instance, conjunctive regular path queries, as in [3], allow conjunction as well as automata operating over vectors of paths. In contrast, [7] and [5] permit automata capable of detecting patterns involving data values.

We introduce a language that subsumes all languages in this paradigm, first order extended regular data path query language (FO(ERDPQ)).1 We first describe the formalism informally. Regular languages are first expanded to languages defined by register automata.

Definition 4 (Register automaton). A register automaton* (RA) is an extension of finite automata, utilizing registers to store data values. A register automaton consists of a finite set of states \(Q\), an initial state \(q_0 \in Q\), and a set of final states \(F \subseteq Q\), along with a finite set of registers. A transition relation \(\delta\) takes as input a state and a Boolean combination of comparisons between registers and constants, along with a special symbol for the input data values. The (nondeterministic) output is a new state and optionally a set of update actions to each register, where an update sets a register to another register’s value, a constant, or the input data.*

Informally, when processing input symbols from an infinite alphabet, register automata compare symbols with register values, updating both registers and automaton state. The semantics are straightforward: see [18].

We now discuss register data path automata ( RDPAs ). These are modifications of register automata to accept data paths. First, the state space is partitioned into word states and data states. While in a word state, an RDPA\(A\) reads a symbol from \(\Sigma\) and transitions to a data state: there is no update and comparison with registers. In a data state, it reads an element from \(\mathcal{D}\), updates its registers, and reverts to a word state. The initial and final states are a data state and a word state, respectively. Transitions that are either of the form \(p \xrightarrow{a} q\), where \(p\) is a word state, \(q\) is a data state, and \(a \in \Sigma\), or \(r \xrightarrow{\boldsymbol{Pre}, \boldsymbol{Upd}} s\), where \(r\) is a data state and \(s\) is a word state, while \(\boldsymbol{Pre}\), the precondition, is a conjunction of equalities and inequalities among input data values, registers and constants. The update function \(\boldsymbol{Upd}\) is a conjunction of assignments of register values, input data values, or constants to registers.we allow the input alphabet to be a product space, and thus in \(\boldsymbol{Pre}\) and \(\boldsymbol{Upd}\) we can refer to the \(i^{th}\) input value. We can also fix infinite domains for each input value and register, and require \(\boldsymbol{Pre}\) and \(\boldsymbol{Upd}\) to be well-typed. Checking well-typedness – e.g. we only compare registers with the same domain – is straightforward. Thus in particular we will have certain registers that will only store ids, and we will assume that their domain is disjoint from the domains of other data values.

We now give the semantics more precisely. A data path automaton is simply an RDPA where the input words have components corresponding to \(\mathcal{D}_{\mathrm{\small id} }\) and \(\mathcal{D}_{\mathrm{\small prop} }\). Both the id and data domains contain a constant, denoted in each case by \(\sharp\) (“unset”), which can be assigned to id registers \(X_{\mathrm{\small id} }\) and \(\mathrm{\small data}\) registers \(X_{\mathrm{\small data} }\), respectively. The semantics of a data path automaton will assume that the initial value of each register is \(\sharp\). Assuming \(\mathcal{D}_{\mathrm{\small prop} }\) is a unary relation for simplicity, the data transitions will have a special shape, which we denote as \(r \xrightarrow{E,I,U} s\), where:

  • \(r\) is a data state,

  • \(s\) is a word state,

  • \(E = (E_{\mathrm{\small id} }, E_{\mathrm{\small data} })\),

  • \(I = (I_{\mathrm{\small id} }, I_{\mathrm{\small data} })\), and

  • \(U = (U_{\mathrm{\small id} }, U_{\mathrm{\small data} })\).

Here:

  • \(E_{\mathrm{\small id} }\) (“\(\mathrm{\small id}\) equality check registers”), \(I_{\mathrm{\small id} }\) (“\(\mathrm{\small id}\) inequality check registers”), and \(U_{\mathrm{\small id} }\) (“\(\mathrm{\small id}\) update registers”) are subsets of \(X_{\mathrm{\small id} }\),

  • \(E_{\mathrm{\small data} }\), \(I_{\mathrm{\small data} }\), and \(U_{\mathrm{\small data} }\) are subsets of \(X_{\mathrm{\small data} }\).

We now give the semantics. Assuming \(\ell\) registers and a single variable domain \(\mathcal{U}\), a configuration of an RDPA\(A\) is a pair \((q,v)\) where \(q\) is a state, and \(v \in (\mathcal{U})^\ell\) is an \(\ell\)-tuple representing register content. A precondition corresponding to \(E\) and \(I\) above states that, when reading a symbol \((d_{\mathrm{\small id} }, d_{\mathrm{\small data} })\), we have

  • \(v[i]=d_{\mathrm{\small id} }\) for each \(i\) in \(E_{\mathrm{\small id} }\),

  • \(v[i]=d_{\mathrm{\small data} }\) for each \(i\) in \(E_{\mathrm{\small data} }\),

  • \(v[i]\neq d_{\mathrm{\small id} }\) for each \(i\) in \(I_{\mathrm{\small id} }\)

  • \(v[i]\neq d_{\mathrm{\small data} }\) for each \(i\) in \(I_{\mathrm{\small data} }\),

And the update corresponding to \(U\) above is:

  • \(w[i]=d_{\mathrm{\small id} }\) for each \(i\) in \(U_{\mathrm{\small id} }\),

  • \(w[i]=d_{\mathrm{\small data} }\) for each \(i\) in \(U_{\mathrm{\small data} }\),

  • \(w[i]=v[i]\) for each \(i \not\in U_{\mathrm{\small id} }\cup U_{\mathrm{\small data} }\).

Given two configurations \((p,v), (q,w)\) and a transition \(\delta\), we write \((p,v) \linebreak \xrightarrow{(d_{\mathrm{\small id} }, d_{\mathrm{\small data} })}_\delta (q,w)\) if the precondition and update function are respected. \((q,v)\) is designated as the initial configuration if \(q\) is the initial state and \(v = (\sharp, \dots, \sharp)\). Similarly, \((q,v)\) is a final configuration if \(q\) is a final state. A sequence of configurations \(s=c_0 \dots c_n\) is a computation on a data path \(u=a_1 \dots a_n\) if there exists a sequence of transitions \(\delta_1 \dots \delta_n\) such that \(c_{i-1} \xrightarrow{a_i}_{\delta_i} c_i\) for each \(i \in [n]\). If \(c_0\) is the initial configuration and \(c_n\) is a final configuration, then \(s\) is an accepting computation, and \(u\) is accepted by \(A\). The language of regular data paths recognized by \(A\), denoted as \(L(A)\), comprises data paths \(u\) accepted by \(A\). Along the computation \(s\), we say register \(x_i\) is written at the \(j^{th}\) step where configuration \(c_j=(q_j,v_j)\) for \(1 \leq j \leq n\) if \(v_{j-1}[i]=\sharp\) and \(v_j[i]\neq \sharp\). Note that we can use states to keep track of which registers were written at the previous states, and whether the current content is \(\sharp\).

Figure 4: RDPAA over \Sigma=\{a\} with one register x \in X_\mathrm{\small data}.

See Figure 4. The RDPA\(A\) has one register \(x \in X_\mathrm{\small data}\) and four states \(q_0, \dots, q_3\), where \(q_0\) is the initial state, and \(q_3\) is a final state. While reading a data path \(d_0 ~ a ~ d_1 \dots a ~ d_n\), it first stores the data value \(d_0\) (excluding its id) in the register \(x\) and transitions from state \(q_0\) to \(q_1\). At state \(q_2\), for each \(i \in [1,n]\), when reading the data value \(d_i\) (excluding its id), it checks whether the value is identical to the content of the register. If the values match, it transitions to the final state \(q_3\) and accepts the data path.

An \(n\)-ary RDPA\(A\) is an RDPA over an \(n\)-ary product alphabet. Let \(u_1,\dots, u_n\) be \(n\) data paths, where \(u_i=(d^{\mathrm{\small id} ,(i)}_0,d^{\mathrm{\small data} ,(i)}_0) \thinspace a^{(i)}_1\dots (d^{\mathrm{\small id} ,(i)}_{j_i},d^{\mathrm{\small data} ,(i)}_{j_i})\) for \(1\leq i \leq n\) and some \(j_1,\dots,j_n \in \mathbb{N}\). The convolution of \(u_1,\dots, u_n\) is an \(n\)-ary data path \(d_0a_1\dots d_m\), where:

  • \(m = \max\{j_1,\dots,j_n\}\),

  • \(a_j=(b_1,\dots,b_n)\) where \(b_i=a^{(i)}_j\) if \(j \leq j_i\); otherwise, \(b_i=\sharp\) for \(1 \leq i \leq n\) and \(1 \leq j \leq m\),

  • \(d_j=(e^{\mathrm{\small id} }_1,\dots,e^{\mathrm{\small id} }_n,e^{\mathrm{\small data} }_1,\dots,e^{\mathrm{\small data} }_n)\) where \(e^{\mathrm{\small id} }_i=d^{\mathrm{\small id} ,(i)}_j\) and \(e^{\mathrm{\small data} }_i=d^{\mathrm{\small data} ,(i)}_j\) if \(j \leq j_i\); otherwise \(e^{\mathrm{\small id} }_i=e^{\mathrm{\small data} }_i=\sharp\) for \(1 \leq i \leq n\) and \(1 \leq j \leq m\).

The convolution of \(u_1, \dots, u_n\) converts the \(n\)-tuple of data paths into a single data path of tuples. This resulting data path is as long as the longest data path among \(u_1, \dots, u_n\) and is padded with \(\sharp\)’s for shorter paths. We say \((u_1,\dots, u_n)\) is accepted by \(A\) if their convolution is accepted by \(A\).

With this foundation, we proceed to define FO(ERDPQ).

Definition 5 (FO(ERDPQ)). The formulas of the logic are defined inductively:

  • atom \(::= \pi = \omega \mid x=y \mid (x,\pi,y) \mid (\pi_1,\dots,\pi_n) \in A\),

  • \(\phi ::= \textit{atom} \mid \neg\phi \mid \phi \wedge \phi \mid \exists x. \phi \mid \exists \pi. \phi\),

Here, \(\pi\) and \(\omega\) are path variables, \(x\) and \(y\) are node variables, and \(A\) is an \(n\)-ary RDPA* where \(n\in \mathbb{Z}_{>0}\). For ease of understanding, we also write \((\pi_1, \dots, \pi_n) \not\in A\) to mean \(\neg((\pi_1, \dots, \pi_n) \in A)\).*

A query in FO(ERDPQ) is referred to as a first order regular data path query (FO(RDPQ)) 2 if all RDPAs in the query are unary. An FO(RDPQ) query is called a regular data path query (RDPQ) if it is of the form: \[\exists\pi.(x,\pi,y) \wedge \pi \in A.\] The semantics of FO(ERDPQ) is standard.

Let \(\phi\) be an FO(ERDPQ) formula, \(G\) a data graph, and \(\alpha\) be a mapping that assigns paths in \(G\) to path variables and nodes to node variables. We say that \(G\) satisfies \(\phi\) under \(\alpha\), denoted by \((G,\alpha) \models \phi\), if one of the following holds:

  • \(\phi: \pi = \omega\) and \(\alpha(\pi) = \alpha(\omega)\).

  • \(\phi: x=y\) and \(\alpha(x) = \alpha(y)\).

  • \(\phi: (x,\pi,y)\) and \(\alpha(\pi)\) is a path from \(\alpha(x)\) to \(\alpha(y)\) in \(G\).

  • \(\phi: (\pi_1,\dots,\pi_n) \in A\) and \((\mathbf{dp}(\alpha(\pi_1)), \dots, \mathbf{dp}(\alpha(\pi_n)))\) is in the \(n\)-ary relation of data paths defined by \(A\).

  • \(\phi: \neg \psi\) and \(G\) does not satisfy \(\psi\) under \(\alpha\).

  • \(\phi: \phi' \wedge \phi''\) and we have \((G,\alpha) \models \phi'\) and \((G,\alpha) \models \phi''\).

  • \(\phi: \exists x. \psi\) and there is a node \(r\) in \(G\) such that \((G, \alpha [x\mapsto r]) \models \psi\).

  • \(\phi: \exists \pi. \psi\) and there is a path \(\rho\) in \(G\) such that \((G,\alpha[\pi \mapsto \rho]) \models \psi\).

Obviously, \(Q_{\boldsymbol{even}}\) is expressible in FO(ERDPQ). It corresponds to formula \(\phi_{\boldsymbol{even}}(x,y):= \exists \pi. (x,\pi,y) \wedge \pi \in A_{\boldsymbol{even}}\), where \(A_{\boldsymbol{even}}\) recognizes the set of data paths of even length. Moreover, since ids are included as a part of data values, Hamiltonicity is expressible in FO(ERDPQ), as we show in the following example:

Example 1. A path \(\rho = v_0 \thinspace a_1 \dots v_n\) is simple if there are no \(0 \leq i < j \leq n\) such that \(v_i = v_j\). Let \(A_{\boldsymbol{repeat}}\) be the unary RDPA with one register which non-deterministically records a node id and accepts the input if the recorded id repeats. Consequently, a path \(\rho\) in a data graph satisfies \((\pi \not\in A_{\boldsymbol{repeat}})\) if and only if \(\rho\) is simple. A path \(\rho\) is said to visit all nodes if, for each node \(v\), there exists an index \(i\) such that \(v_i=v\). Now, let \(A_{\boldsymbol{visit}}\) be a binary RDPA with one register, storing the first node id of the first data path and accepting if the stored id appears in the second path. Then, the FO(ERDPQ) formula \(\phi_H(\pi) := (\pi \not\in A_{\boldsymbol{repeat}}) \wedge (\forall \omega. (\omega,\pi) \in A_{\boldsymbol{visit}})\) asserts that \(\pi\) represents a Hamiltonian path.

Graph pattern calculus (GPC). GPC is another query language based on regular expressions, designed for working with graphs containing data [14]. As discussed in the introduction, we make some simplifications to the language proposed in the standard, related to inverses and trails. We return to these simplifications in Section 7.

The most foundational GPC query takes the form \(\mathfrak{t}\;\mathfrak{p}\), where \(\mathfrak{t}\) is referred to as a restrictor, and \(\mathfrak{p}\) is called a pattern. Informally, a pattern can describe the label pattern of a path, which can be represented equivalently as a regular expression. It can also perform equality tests on data values of two nodes. A restrictor can constrain paths to have non-repeating vertices, and can also enforce the paths to be the shortest among the valid paths. The forms of a restrictor \(\mathfrak{t}\) are as follows:

  • Restrictor: \(\mathfrak{t}::= \mathrm{\small simple} ~ | ~ \mathrm{\small shortest} ~| ~ \mathrm{\small shortestsimple}\)

Atomic GPC patterns are either:

  • Node patterns: \(()\) and \((x)\); or

  • Edge patterns: \(\rightarrow\) and \(\xrightarrow{a}\).

Here, \(x\) represents a node variable, and \(a \in \Sigma\).

We now give inductive rules for forming patterns, assuming two patterns \(\mathfrak{p}\) and \(\mathfrak{p}'\). We close under:

  • Union: \(\mathfrak{p}+ \mathfrak{p}'\),

  • Concatenation: \(\mathfrak{p}\mathfrak{p}'\),

  • Repetition: \(\mathfrak{p}^{n..m}\), where \(n\) and \(m\) can take values in \(\mathbb{N}\cup\{\infty\}\).

  • Conditioning: \(\mathfrak{p}_{\langle \theta \rangle}\), where \(\theta\) is a condition.

Conditions are defined as:

  • Condition: \(\theta::= x \equiv_{\mathrm{\small data} } y \mid \neg\theta \mid \theta \wedge \theta\)

where \(x\) and \(y\) are node variables.

In [14], GPC is accompanied by a type system that imposes certain restrictions. Here, we consider the notion of free variables, as introduced in [19]. Given a pattern \(\mathfrak{p}\), a node variable \(x\) in \(\mathfrak{p}\) is bounded if it appears within a repetition sub-pattern \(\mathfrak{q}\); otherwise, \(x\) is free. An important restriction on the syntax is:

If a variable \(x\) is used in the repetition sub-pattern \(\mathfrak{q}\) of \(\mathfrak{p}\), it cannot appear anywhere else in \(\mathfrak{p}\) except within \(\mathfrak{q}\)

We use \(\mathrm{\small FV}(\mathfrak{p})\) to denote the set of free variables in the pattern \(\mathfrak{p}\). 3

Let \(G = (V, E, \mathrm{\small id} , \nodedata)\) be a data graph, and let \(\mathfrak{p}\) and \(\mathfrak{p}'\) be two GPC patterns. For any two mappings \(\mu: \mathrm{\small FV}(\mathfrak{p}) \to V \cup \{\sharp\}\) and \(\mu': \mathrm{\small FV}(\mathfrak{p}') \to V \cup \{\sharp\}\), the union \(\mu \cup \mu': \mathrm{\small FV}(\mathfrak{p}) \cup \mathrm{\small FV}(\mathfrak{p}') \to V \cup \{\sharp\}\) is defined if, for all \(x \in \mathrm{\small FV}(\mathfrak{p}) \cap \mathrm{\small FV}(\mathfrak{p}')\), it holds that \(\mu(x) = \mu'(x)\) whenever both \(\mu(x) \neq \sharp\) and \(\mu'(x) \neq \sharp\), where \(\sharp\) refers to a null value. If \(\mu \cup \mu'\) is defined, then it maps each \(x\) to:

  • \(\mu(x)\) if \(\mu(x) \neq \sharp\) or \(x \not\in \mathrm{\small FV}(\mathfrak{p}')\);

  • \(\mu'(x)\) if \(\mu'(x) \neq \sharp\) or \(x \not\in \mathrm{\small FV}(\mathfrak{p})\);

  • \(\sharp\) if \(\mu(x) = \mu'(x) = \sharp\).

Given a condition \(\theta\) and a mapping \(\mu: \mathrm{\small FV}(\mathfrak{p}) \to V\), \(\mu \models \theta\) is defined recursively as follows:

  • \(\mu \models x \equiv_{\mathrm{\small data} } y\) if \(\nodedata(\mu(x)) = \nodedata(\mu(y))\).

  • \(\mu \models \neg \theta\) if \(\mu \not\models \theta\).

  • \(\mu \models \theta \wedge \theta'\) if \(\mu \models \theta\) and \(\mu \models \theta'\).

Now, we are ready to define the semantics of GPC queries. Let \(\mathfrak{p}\) be a GPC pattern, and let \(G = (V, E, \mathrm{\small id} , \nodedata)\) be a data graph over \(\Sigma\). The semantics of \(\mathfrak{p}\) in \(G\), denoted \([\![{\mathfrak{p}}]\!]_{G}\), is a set of pairs \((\rho, \mu)\), where \(\rho\) is a path and \(\mu\) is a mapping from \(\mathrm{\small FV}(\mathfrak{p})\) to \(V\). The semantics is defined recursively as follows:

  • \([\![{(x)}]\!]_{G} = \{(v, \{x \mapsto v\}) \mid v \in V\}\). Recall that \(v\) is a path of length zero in \(G\) if \(v \in V\).

  • \([\![{()}]\!]_{G} = \{(v, \emptyset) \mid v \in V\}\).

  • \([\![{\xrightarrow{a}}]\!]_{G} = \{(v \thinspace a \thinspace v', \emptyset) \mid (v, a, v') \in E\}\) for \(a \in \Sigma\). Recall that \(v \thinspace a \thinspace v'\) is a path of length one in \(G\) if \((v, a, v') \in E\).

  • \([\![{\rightarrow}]\!]_{G} = \{(v \thinspace a \thinspace v', \emptyset) \mid (v, a, v') \in E\}\).

  • \([\![{\mathfrak{p}+ \mathfrak{p}'}]\!]_{G} = \{(\rho, \mu') \mid (\rho, \mu) \in [\![{\mathfrak{p}}]\!]_{G}\) or \((\rho, \mu) \in [\![{\mathfrak{p}'}]\!]_{G}\}\), where \(\mu'\) is a mapping from \(\mathrm{\small FV}(\mathfrak{p}) \cup \mathrm{\small FV}(\mathfrak{p}')\) defined as follows:

    • \(\mu'(x) = \mu(x)\) if \(x\) is in the domain of \(\mu\);

    • \(\mu'(x) = \sharp\) otherwise.

    For example, suppose \(\mathrm{\small FV}(\mathfrak{p})=\{x,y\}\) and \(\mathrm{\small FV}(\mathfrak{p}')=\{y,z\}\). Then, we have \(\mathrm{\small FV}(\mathfrak{p}+ \mathfrak{p}') = \{x,y,z\}\). Additionally, if \((\rho,\mu) \in [\![{\mathfrak{p}'}]\!]_{G}\) with \(\mu(y)=v\) and \(\mu(z)=w\), then we have \((\rho,\mu') \in [\![{\mathfrak{p}\mathfrak{p}'}]\!]_{G}\), where:

    • \(\mu'(x) = \sharp\),

    • \(\mu'(y) = v\),

    • \(\mu'(z) = w\).

  • \([\![{\mathfrak{p}\mathfrak{p}'}]\!]_{G} = \{(\rho \cdot \rho', \mu \cup \mu') \mid (\rho, \mu) \in [\![{\mathfrak{p}}]\!]_{G}, (\rho', \mu') \in [\![{\mathfrak{p}'}]\!]_{G}\text{, and the union } \mu\cup\mu' \text{ is defined}\}\).

  • \([\![{\mathfrak{p}^{n..m}}]\!]_{G} = \bigcup_{i=n}^m [\![{\mathfrak{p}}]\!]_{G}^i\), where:

    • \([\![{\mathfrak{p}}]\!]_{G}^0 = [\![{()}]\!]_{G}\).

    • \([\![{\mathfrak{p}}]\!]_{G}^\ell = \{(\rho_1 \cdots \rho_\ell, \emptyset) \mid \exists \mu_1, \dots, \mu_\ell. \, (\rho_1, \mu_1), \dots, (\rho_\ell, \mu_\ell) \in [\![{\mathfrak{p}}]\!]_{G}\}\) for \(\ell \geq 1\).

  • \([\![{\mathfrak{p}_{\langle \theta \rangle}}]\!]_{G} = \{(\rho, \mu) \mid (\rho,\mu) \in [\![{\mathfrak{p}}]\!]_{G} \text{ and }\mu \models \theta\}\).

Given a GPC pattern \(\mathfrak{p}\) and a restrictor \(\mathfrak{t}\), the semantics \([\![{\mathfrak{t}\;\mathfrak{p}}]\!]_{G}\) is defined recursively as follows:

  • \(\{(\rho, \mu) \mid (\rho, \mu) \in [\![{\mathfrak{p}}]\!]_{G} \rho \text{ is simple}\}\) if \(\mathfrak{t}= \mathrm{\small simple}\).

  • \(\{(\rho, \mu) \mid (\rho, \mu) \in [\![{\mathfrak{p}}]\!]_{G} ~ \rho \text{ shortest among paths } \rho' with (\rho', \mu') \in [\![{\mathfrak{p}}]\!]_{G} \\ and \rho' has the same endpoints as \rho \}\) if \(\mathfrak{t}= \mathrm{\small shortest}\).

  • \(\{(\rho, \mu) \mid (\rho, \mu) \in [\![{\mathfrak{p}}]\!]_{G}, \rho \text{ is simple, and } |\rho| = \min \{ |\rho'| \mid (\rho', \mu') \in [\![{\mathfrak{p}}]\!]_{G},\linebreak \rho' \text{ is simple and has the same endpoints as } \rho \}\) if \(\mathfrak{t}=\mathrm{\small shortestsimple}\).

 

  • \([\![{Q, Q'}]\!]_{G} = \{((\bar{\rho}, \bar{\rho}'), \mu \cup \mu') \mid (\bar{\rho}, \mu) \in [\![{Q}]\!]_{G}, (\bar{\rho}', \mu') \in [\![{Q'}]\!]_{G} \text{, and the union }\linebreak \mu\cup\mu' \text{ is defined}\}\).

We omit the subscript \(G\) when it is clear from the context. We adapt GPC queries to support graph queries in the obvious way: a non-empty data graph \(G\) satisfies a GPC query \(Q\) if \([\![{Q}]\!]_{G}\) is non-empty. For simplicity, we also say that a path \(\rho\) in \(G\) is in the semantics of \(Q\), denoted as \(\rho \in [\![{Q}]\!]_{G}\), if \((\rho, \mu) \in [\![{Q}]\!]_{G}\). We also say that a path \(\rho\) satisfies \(\mathfrak{p}\), if there exists a mapping \(\mu\) such that \((\rho,\mu) \in [\![{\mathfrak{p}}]\!]_{G}\).

We end this subsection with two examples. Consider the following GPC pattern over \(\Sigma=\{a,b\}\): \[\mathfrak{p}= (x) \xrightarrow{a} () \left[ \left[\xrightarrow{b}\xrightarrow{b}\xrightarrow{b}\right]^{1..\infty} + \left[[(y) \rightarrow^{3..7} (z)]_{y\equiv_{\mathrm{\small data} } z}\right]^{1..1} \right] () \xrightarrow{b} (x).\] Since variables \(y\) and \(z\) are used in a repetition sub-pattern, we have \(\mathrm{\small FV}(\mathfrak{p}) = \{x\}\). Pattern \(\mathfrak{p}\) refers to the set of paths \(\rho = v_0 ~ a_1 ~ v_1 \dots a_n ~ v_n\), where:

  • \(v_0 = v_n\) where \(n>2\),

  • \(a_1 = a\) and \(a_n = b\), and

  • at least one of the following holds:

    (a) \(n-2\) is divisible by \(3\) and \(a_i = b\) for \(2\leq i \leq n-1\);

    (b) \(3\leq n-2 \leq 7\) and \(\mathrm{\small dataof} (v_1) = \mathrm{\small dataof} (v_{n-1})\).

See the data graph \(G\) in Figure 5. Let \(\mu\) be a mapping with \(\mu(x)=n_3\). By definition, we have \([\![{\mathfrak{p}}]\!]_{G}\) as the union of the following two sets:

  1. \(P_1 = \{(n_3 ~ a ~ (n_4 ~ b ~ n_5 ~ b ~ n_6 ~ b ~ n_7~ b)^i ~ n_3, \mu) \mid 4i-1 \text{ is divisible by 3 and } i\geq 1\}\).

  2. \(P_2 = \{(n_3 ~ a ~ n_1 ~ (a ~ n_2 ~ a ~n_1)^i ~ a ~ n_2 ~ b ~ n_3, \mu) \mid i=2,\dots, 6\}\).

Moreover, we find that \([\![{\mathfrak{t}\;\mathfrak{p}}]\!]_{G}\) is as follows:

  • When \(\mathfrak{t}= \mathrm{\small simple} , \mathrm{\small shortestsimple}\), \([\![{\mathfrak{t}\;\mathfrak{p}}]\!]_{G}\) is empty, as there is no simple path in \(G\) matching pattern \(\mathfrak{p}\).

  • When \(\mathfrak{t}= \mathrm{\small shortest}\), \([\![{\mathfrak{t}\;\mathfrak{p}}]\!]_{G} = \{(\rho,\mu) \mid \rho \text{ is a shortest path in } P_1\cup P_2\}\).

Figure 5: Data graph G over \{a,b\}, where \mathrm{\small dataof} (n_1)=\mathrm{\small dataof} (n_2)=0 and \mathrm{\small dataof} (n_i)=i for i=3,\dots,7.

Finally, consider the following GPC pattern over \(\Sigma=\{a,b\}\): \[\mathfrak{q}=\;\xrightarrow{b}\xrightarrow{b}.\] Given the same data graph \(G\) in Figure 5, we have: \[[\![{\mathfrak{q}}]\!]_{G} = \{n_4~ b ~ n_5~ b ~ n_6, n_5 ~ b ~ n_6 ~ b ~ n_6, n_6 ~ b ~ n_7 ~ b ~ n_4, n_6 ~ b ~ n_7 ~ b ~ n_3, n_7 ~ b ~ n_4 ~ b ~ n_5\}.\] Since all paths in \([\![{\mathfrak{q}}]\!]_{G}\) are simple and have the same length, we have \([\![{\mathfrak{t}\;\mathfrak{q}}]\!]_{G}=[\![{\mathfrak{q}}]\!]_{G}\) for any restrictor \(\mathfrak{t}\).

3.3 Graph querying based on FO\(^*\)↩︎

Another category of languages revolves around first-order logic with only node variables. Instead of relying on operations rooted in automata or regular languages, these languages utilize a transitive closure operator.

A data graph \(G=(V,E, \mathrm{\small id} , \nodedata)\) over \(\Sigma\) can be viewed as a first-order structure \(\langle V, \{E_a\}_{a \in \Sigma}, \equiv_{\mathrm{\small data} }\rangle\). First-order logic over this structure is denoted as FO\((\equiv_{\mathrm{\small data} })\). In this structure, the set \(V\) of nodes forms the universe, \(E_a\) is interpreted as \(\{(v,v') \in V^2 \mid (v,a,v')\in E\}\), and \(\equiv_{\mathrm{\small data} }\) is interpreted as \(\{(v,v') \mid \nodedata(v)=\nodedata(v')\}\).

We extend FO\((\equiv_{\mathrm{\small data} })\) by introducing a transitive closure constructor. If \(\phi(\mathbf{x},\mathbf{y})\) is a formula, then \(\phi^*(\mathbf{x}, \mathbf{y})\) becomes a formula, where \(\mathbf{x}\) and \(\mathbf{y}\) represent two vectors of node variables of the same arity. The interpretation is such that \(G, \rho \models \phi^*(\mathbf{x}, \mathbf{y})\) for a data graph \(G\) and a valuation \(\rho\), if there exists a sequence of node vectors \(\mathbf{x}_1=\rho(\mathbf{x}), \mathbf{x}_2, \ldots, \mathbf{x}_n=\rho(\mathbf{y})\) satisfying the condition that for each \(1 \leq i < n\), \(G, \rho \models \phi(\mathbf{x}_i, \mathbf{x}_{i+1})\). 4 We denote the extension of FO\((\equiv_{\mathrm{\small data} })\) with transitive closures as FO\(^*(\equiv_{\mathrm{\small data} })\). In contrast to other languages that rely on transitive closure of edge relations,
FO\(^*(\equiv_{\mathrm{\small data} })\) permits the transitive closure of any definable relationship, not just the closure of the edge relation.

Within this paradigm, one prominent language family is GXPath, originating from query languages for graph databases initially introduced in [2], inspired by the XML query language XPath. Within this family,
GXPath\(_{\mathrm{\small reg}}(\equiv_{\mathrm{\small data} })\) is the most powerful variant: [2] shows that it is equivalent to (FO\(^*_{3}\))\((\equiv_{\mathrm{\small data} })\), a restriction of FO\(^*(\equiv_{\mathrm{\small data} })\) allowing only formulas in which every subformula has at most three free variables, and the closure \(\phi^*\) of \(\phi(\mathbf{x},\mathbf{y})\) is allowed only if \(\mathbf{x}\) and \(\mathbf{y}\) have the same arity. Lastly, it is worth mentioning regular queries (RQ) [21], a query language for graphs without data, which extends unions of conjunctive 2-way regular path queries (UC2RPQ) by adding transitive closure. RQ can be defined as the closure of atomic queries under selection, projection, disjunction, conjunction, and transitive closure. By adding \(x \equiv_{\mathrm{\small data} } y\) to the set of atomic queries, RQ can be extended to handle graphs with data.

4 Expressiveness of existing languages↩︎

The languages discussed in Section 3 are illustrated in Figure 1. This section will be devoted to proving the following theorem, which justifies Figure 1:

Theorem 1. The subsumptions depicted in Figure 1 all hold.

It is straightforward, just chasing the definitions, to observe that RDPQ\(\subseteq\) FO(RDPQ)\(\subseteq\) FO(ERDPQ). To complete the proof, we still have to show:

(1) FO(ERDPQ) subsumes GPC.

(2) FO(ERDPQ) subsumes WL.

(3) FO\(^*(\equiv_{\mathrm{\small data} })\) subsumes RDPQ.

We will show the first and third item here. The proof of the middle item will be deferred to Section 6.

4.1 FO(ERDPQ) subsumption of GPC↩︎

We define a fragment of FO(ERDPQ) with lower data complexity which still subsumes GPC. The motivation is that there exists a substantial complexity gap between GPC and FO(ERDPQ). The data complexity of query evaluation for GPC is within PSPACE[14], whereas for FO(ERDPQ), it is non-elementary [3]. Our objective is to bridge this gap by introducing the fragment \(\forall\)(ERDPQ) of FO(ERDPQ), in which only universal quantifiers are allowed. The expressiveness of this fragment relative to others is depicted in Figure 6.

Figure 6: Fragment \forall(ERDPQ) between FO(ERDPQ) and GPC. (Higher is more expressive.)

Formalizing the syntax, a \(\forall\)(ERDPQ) formula takes the form: \[\forall \bar{\omega}. \psi(\bar{\pi},\bar{\omega}),\] where \(\psi\) is a quantifier-free FO(ERDPQ) formula. We will demonstrate that this fragment contains GPC.

Theorem 2. Every GPC query is expressible in \(\forall\)(ERDPQ).

Proof. Let \(Q\) be a GPC query of the form \(\mathfrak{t}\;\mathfrak{p}\). We will show that there exists a 1-ary \(\forall\)(ERDPQ) formula \(\phi_Q(\pi)\) equivalent to \(Q\). That is, for every data graph \(G\) and path \(\rho\) in \(G\), \(G \models \phi_Q(\rho)\) if and only if \(\rho\) is in the semantics of \(Q\).

This statement follows directly from the following claim:

Claim (S)

There is a 1-ary RDPA\(A_{\mathfrak{p}}\) recognizing the data paths \(\mathbf{dp}(\rho)\) corresponding to the paths \(\rho\) satisfying the pattern \(\mathfrak{p}\). That is, for every path \(\rho\), \(\mathbf{dp}(\rho)\) is accepted by \(A_{\mathfrak{p}}\) if and only if there exists a mapping \(\mu\) such that \((\rho,\mu) \in [\![{\mathfrak{p}}]\!]_{G}\).

Before justifying why Claim (S) holds, we first explain how it leads to the proposition. Suppose (S) is true. Then, we can construct the \(\forall\)(ERDPQ) formula \(\phi_Q\) as required in the proposition. There are three cases to consider: \(\mathfrak{t}= \mathrm{\small shortest} , \mathrm{\small simple} ,\mathrm{\small shortestsimple}\). Assuming the existence of the RDPA\(A_{\mathfrak{p}}\) in (S), consider the case where \(\mathfrak{t}= \mathrm{\small shortest}\). The required \(\forall\)(ERDPQ) formula \(\phi_Q(\pi)\) in this case is: \[\phi_{\mathrm{\small shortest} }(\pi) := \pi \in A_{\mathfrak{p}} \wedge \forall \omega. (\omega \in A_{\mathfrak{p}} \wedge A_{same}(\pi, \omega) \rightarrow (\pi, \omega) \in A_{\leq},\] where \((\pi, \omega) \in A_{\leq}\) indicates that the length of \(\pi\) is not greater than the length of \(\omega\), while \(A_{same}\) holds of a pair if they have the same endpoints. These two relations are clearly RDPA definable: in the case of \(A_{same}\), we use the fact that our attributes include an identity data value. Further, the conjunct \(\pi \in A_{\mathfrak{p}}\) can be moved inside the universal quantification.

Consider \(\mathfrak{t}= \mathrm{\small simple}\). A path \(\rho\) is simple if for every two prefixes \(\tau, \nu\) of \(\rho\) with \(|\tau| \neq |\nu|\), their last nodes have different ids. Using closure of \(RDPA\) under union, we can create a ternary RDPA\(A_{\mathrm{\small simple} }\) with one register to recognize the set of triples \((\mathbf{dp}(\rho), \mathbf{dp}(\tau), \mathbf{dp}(\nu))\), such that:

If \(\tau\) and \(\nu\) are prefixes of \(\rho\), and \(|\tau| \neq |\nu|\), then the id of the last node in \(\tau\) is different from the id of the last node in \(\nu\).

Consequently, a path is simple if and only if it satisfies the following \(\forall\)(ERDPQ) formula: \[\phi_{\mathrm{\small simple} }(\pi) := \forall \omega, \theta. (\pi, \omega, \theta) \in A_{\mathrm{\small simple} }.\] Accordingly, the \(\forall\)(ERDPQ)\(\phi_Q(\pi)\) is: \[\phi_{\mathrm{\small simple} }(\pi) \wedge \pi\in A_{\mathfrak{p}}\] assuming the RDPA\(A_{\mathfrak{p}}\) from (S).

Finally, for the case \(\mathfrak{t}= \mathrm{\small shortestsimple}\), the \(\forall\)(ERDPQ) formula \(\phi_Q\) can be derived in a similar manner. Specifically, \(\phi_Q(\pi)\) in this case is: \[\begin{align} &\phi_{\mathrm{\small shortestsimple} }(\pi):= \forall \pi', \omega, \theta. \;\; \big( (\pi, \omega, \theta) \in A_{\mathrm{\small simple} } \wedge \pi \in A_{\mathfrak{p}} \big) \;\wedge \\ & \big( (\pi' \in A_{\mathfrak{p}} \wedge (\pi',\pi)\in A_< \wedge (\pi, \pi') \in A_{same}) \rightarrow \pi' \in A_{\mathrm{\small nonsimple} } \big), \end{align}\] where \((\pi', \pi) \in A_<\) indicates that \(\pi'\) is strictly shorter than \(\pi\), \((\pi, \pi') \in A_{same}\) indicates they have the same endpoints, while \(\pi' \in A_{\mathrm{\small nonsimple} }\) expresses that \(\pi'\) contains at least one repeated node id. Note that while simplicity is not RDPA-definable, its complement \(A_{\mathrm{\small nonsimple} }\) is recognizable by a 1-register RDPA that non-deterministically stores a node id and verifies its recurrence. Thus, (S) implies the proposition.

Each pattern \(\mathfrak{p}\) is recursively constructed from atomic patterns. If no node patterns of the form \((x)\) appear in \(\mathfrak{p}\), then \(\mathfrak{p}\) is simply a regular expression, and the construction process for \(A_{\mathfrak{p}}\), as stated in (S), is identical to the process of transforming a regular expression into a corresponding finite automaton. A key distinction arises when node variables \(x\) are present in \(\mathfrak{p}\).

Now, we proceed to prove (S). For a given pattern \(\mathfrak{p}\), it is either an atomic pattern, a union or a concatenation of two sub-patterns, a repetition pattern, or a conditioning. We prove (S) by structural induction on patterns:

Node patterns

  • If \(\mathfrak{p}= ()\), then \(A_{\mathfrak{p}}\) accepts all data paths of length zero. Specifically, \(A_{\mathfrak{p}}\) has two states \(s_0\) and \(s_1\), where \(s_0\) is the initial state and \(s_1\) is a final state. The automaton has no registers. On a data path \(d_0 a_1 d_1 \dots a_n d_n\), it switches from state \(s_0\) to \(s_1\) when reading the data value \(d_0\). Thus, the data path is accepted by \(A_{\mathfrak{p}}\) if and only if \(n = 0\). Note that \(A_{\mathfrak{p}}\) is not required to be complete, meaning that it does not necessarily have a transition for every possible input from each state.

    Obviously, in this case, for every path \(\rho\), we have \((\rho,\emptyset) \in [\![{\mathfrak{p}}]\!]_{G}\) if and only if \(\mathbf{dp}(\rho)\) is accepted by \(A_{\mathfrak{p}}\).

  • If \(\mathfrak{p}= (x)\), then \(A_{\mathfrak{p}}\) accepts all data paths \(d\) of length zero, where \(d = (d_{\mathrm{\small id} }, d_{\mathrm{\small data} }) \in \mathcal{D}\), and the automaton indicates that registers \(r^{\mathrm{\small id} }_x\) and \(r^{\mathrm{\small data} }_x\) are written with values \(d_{\mathrm{\small id} }\) and \(d_{\mathrm{\small data} }\), respectively. \(A_{\mathfrak{p}}\) is obtained by modifying the automaton from the previous case to store the data value \(d_0\) in \(r^{\mathrm{\small id} }_x\) and \(r^{\mathrm{\small data} }_x\) during the transition from \(s_0\) to \(s_1\).

    In this case, for every path \(\rho\), if \((\rho,\mu) \in [\![{\mathfrak{p}}]\!]_{G}\), then \(\mathbf{dp}(\rho) = d\) for some \(d = (d_{\mathrm{\small id} }, d_{\mathrm{\small data} }) \in \mathcal{D}\). Furthermore, \((\rho,\mu) \in [\![{\mathfrak{p}}]\!]_{G}\) with \(\mu(x) = d_{\mathrm{\small data} }\) if and only if there exists an accepting run \(\gamma\) of \(A_{\mathfrak{p}}\) on the data path \(\mathbf{dp}(\rho)\) such that the value of register \(r^{\mathrm{\small data} }_x\) becomes \(d_{\mathrm{\small data} }\) along \(\gamma\).

Edge patterns

  • For \(\mathfrak{p}= \rightarrow\), \(A_{\mathfrak{p}}\) accepts all data paths of length one. Specifically, \(A_{\mathfrak{p}}\) has four states \(s_0, s_1, s_2, s_3\), where \(s_0\) is the initial state and \(s_3\) is a final state. For a data path \(d_0 a_1 d_1 \dots a_m d_m\), the transitions are as follows:

    1. Transition from \(s_0\) to \(s_1\) on reading \(d_0\).

    2. Transition from \(s_1\) to \(s_2\) on reading any symbol \(a \in \Sigma\).

    3. Transition from \(s_2\) to \(s_3\) on reading \(d_1\).

    Accordingly, \(A_{\mathfrak{p}}\) accepts the data path if and only if \(m = 1\).

  • For \(\mathfrak{p}= \xrightarrow{a}\), \(A_{\mathfrak{p}}\) accepts all data paths \(d_0 a_1 d_1\) of length one, where \(a_1 = a\). The automaton for this case is obtained by modifying the transitions of \(A_{\mathfrak{p}}\) for \(\mathfrak{p}= \rightarrow\). Specifically, all transitions from \(s_1\) to \(s_2\) on symbols \(b \neq a\) are removed, leaving only the transition on \(a\).

In the case of edge patterns, for every path \(\rho\), we have \((\rho,\emptyset) \in [\![{\mathfrak{p}}]\!]_{G}\) if and only if \(\mathbf{dp}(\rho)\) is accepted by \(A_{\mathfrak{p}}\).

Union

Let’s assume \(\mathfrak{p}= \mathfrak{p}_1 + \mathfrak{p}_2\), and we have the corresponding register automaton \(A_{\mathfrak{p}_1}\) and \(A_{\mathfrak{p}_2}\) for \(\mathfrak{p}_1\) and \(\mathfrak{p}_2\) respectively. The automaton \(A_{\mathfrak{p}}\) results from the disjunction of \(A_{\mathfrak{p}_1}\) and \(A_{\mathfrak{p}_2}\). Since register automata are closed under disjunction, the disjunction of \(A_{\mathfrak{p}_1}\) and \(A_{\mathfrak{p}_2}\) is well-defined.

For every path \(\rho\), if \(\gamma\) is an accepting run of \(A_{\mathfrak{p}}\) on the data path \(\mathbf{dp}(\rho)\), we define \(\mu\) as the mapping that assigns a free variable \(x\) to \(v\) if the registers corresponding to \(x\) hold the value \(v\), and to the null value \(\sharp\) if those registers remain unwritten along \(\gamma\).

Obviously, if \(\gamma\) is an accepting run of \(A_{\mathfrak{p}}\) on \(\mathbf{dp}(\rho)\), then \(\gamma\) is also an accepting run of \(A_{\mathfrak{p}_1}\) or \(A_{\mathfrak{p}_2}\) on \(\mathbf{dp}(\rho)\). Accordingly, if \((\rho,\mu_1) \in [\![{\mathfrak{p}_1}]\!]_{G}\) or \((\rho,\mu_2) \in [\![{\mathfrak{p}_2}]\!]_{G}\), where the domain of \(\mu_i\) is \(\mathrm{\small FV}(\mathfrak{p}_i)\) and \(\mu_i(x) = \mu(x)\) for all \(x \in \mathrm{\small FV}(\mathfrak{p}_i)\), for \(i=1,2\), then it follows that \((\rho,\mu) \in [\![{\mathfrak{p}}]\!]_{G}\) and \(\mu=\mu_1 \cup \mu_2\).

Concatenation

Let’s assume \(\mathfrak{p}= \mathfrak{p}_1 \mathfrak{p}_2\), and we have the corresponding register automaton \(A_{\mathfrak{p}_1}\) and \(A_{\mathfrak{p}_2}\) for \(\mathfrak{p}_1\) and \(\mathfrak{p}_2\), respectively. Without loss of generality, we assume that the final state of \(A_{\mathfrak{p}_1}\) is unique and has no outgoing transitions. The automaton \(A_{\mathfrak{p}}\) is obtained by concatenating \(A_{\mathfrak{p}_1}\) and \(A_{\mathfrak{p}_2}\). Specifically, this concatenation is achieved by introducing transitions defined as follows: suppose \(r \xrightarrow{E,I,U} s\) is a transition of \(A_{\mathfrak{p}_1}\), where \(s\) is the final state, and \(r' \xrightarrow{E',I',U'} s'\) is a transition of \(A_{\mathfrak{p}_2}\), where \(r'\) is the initial state. Then, \(r \xrightarrow{E,I,U} s'\) is a transition of \(A_{\mathfrak{p}}\).

Furthermore, we must modify the use of registers corresponding to variables \(x\) that are present in both \(\mathfrak{p}_1\) and \(\mathfrak{p}_2\). Before explaining this modification, we note that no variable \(x\) can appear in a repetition subpattern of \(\mathfrak{p}_1\) or \(\mathfrak{p}_2\), by the syntactic requirements of GPC. Thus, if a variable \(x\) occurs in both subpatterns \(\mathfrak{p}_1\) and \(\mathfrak{p}_2\), it must be free in both.

We will only modify the register behavior in \(A_{\mathfrak{p}_2}\), leaving the behavior in \(A_{\mathfrak{p}_1}\) unchanged. Informally, the modification will be to ensure the following property:

In the copy of \(A_{\mathfrak{p}_2}\), if we reach a state where the value of \(x\) is already set to be \(x_0\) and we are to make a transition where \(x\) is to be written again, we only allow this if the data value in the input matches \(x_0\). Otherwise the behavior is the same as in \(A_{\mathfrak{p}_2}\).

One way to enforce this is to add a component of the state tracking whether each shared variable is written or not. It is straightforward with this additional state to ensure the property above.

If \(\gamma=\gamma_1\cdot \gamma_2\) is an accepting run of \(A_{\mathfrak{p}}\) on \(\mathbf{dp}(\rho)\), then \(\gamma_1\) and \(\gamma_2\) are accepting runs of \(A_{\mathfrak{p}_1}\) and \(A_{\mathfrak{p}_2}\) on \(\mathbf{dp}(\rho_1)\) and \(\mathbf{dp}(\rho_2)\), respectively. Accordingly, if \((\rho,\mu_1) \in [\![{\mathfrak{p}_1}]\!]_{G}\) and \((\rho,\mu_2) \in [\![{\mathfrak{p}_2}]\!]_{G}\), where the domain of \(\mu_i\) is \(\mathrm{\small FV}(\mathfrak{p}_i)\) and \(\mu_i(x) = \mu(x)\) for all \(x \in \mathrm{\small FV}(\mathfrak{p}_i)\), for \(i=1,2\), then it follows that \((\rho,\mu) \in [\![{\mathfrak{p}}]\!]_{G}\) and \(\mu=\mu_1 \cup \mu_2\).

On the other hand, if \((\rho_1,\mu_1) \in [\![{\mathfrak{p}_1}]\!]_{G}\) and \((\rho_2,\mu_2) \in [\![{\mathfrak{p}_2}]\!]_{G}\) with \(\mu_1(x) = \mu_2(x)\) for all \(x \in \mathrm{\small FV}(\mathfrak{p}_1) \cap \mathrm{\small FV}(\mathfrak{p}_2)\), and the last node of \(\rho_1\) is identical to the first node of \(\rho_2\), then there exist accepting runs \(\gamma_1\) and \(\gamma_2\) of \(A_{\mathfrak{p}_1}\) and \(A_{\mathfrak{p}_2}\) on \(\mathbf{dp}(\rho_1)\) and \(\mathbf{dp}(\rho_2)\), respectively, and \(\mathbf{dp}(\rho)=\mathbf{dp}(\rho_1)\cdot\mathbf{dp}(\rho_2)\) is a valid data path. Hence, \(\gamma=\gamma_1\cdot \gamma_2\) is an accepting run of \(A_{\mathfrak{p}}\) on \(\mathbf{dp}(\rho)\).

Repetition

Given a pattern \(\mathfrak{q}\), \(\mathfrak{q}^{n \dots m}\) is also a pattern, where \(n \in \mathbb{N}\) and \(m \in \mathbb{N}\cup \{\infty\}\). This notation signifies that pattern \(\mathfrak{q}\) is repeated between \(n\) and \(m\) times. When both \(n\) and \(m\) belong to \(\mathbb{N}\), then \(\mathfrak{q}^{n \dots m}\) is equivalent to \(\mathfrak{q}_1^{n \dots n} + \ldots + \mathfrak{q}_m^{m \dots m}\), where \(\mathfrak{q}_i\) is a copy of \(\mathfrak{q}\) with fresh node variables for \(i\in [1,m]\). Similarly, pattern \(\mathfrak{q}^{n \dots \infty}\) is equivalent to \(\mathfrak{q}_1^{n \dots n} (() +\mathfrak{q}_2^{1 \dots \infty})\), where \(\mathfrak{q}_i\) is a copy of \(\mathfrak{q}\) with fresh node variables for \(i=1,2\). Recall that \(\mathfrak{p}^{0..0}\) is equivalent to node pattern \(()\) for all patterns \(\mathfrak{p}\). Therefore, we only need to consider the cases \(\mathfrak{p}=\mathfrak{q}^{n \dots n}\) and \(\mathfrak{p}=\mathfrak{q}^{1 \dots \infty}\).

Let \(A_{\mathfrak{q}}\) be the RDPA corresponding to \(\mathfrak{q}\). If \(\mathfrak{p}=\mathfrak{q}^{n \dots n}\), then \(A_{\mathfrak{p}}\) results from concatenating \(A_{\mathfrak{q}}\) with \(n-1\) many of its duplicates. Note that although the semantics of concatenating \(\mathfrak{q}\) with itself \(n\) times and the repetition \(\mathfrak{q}^{n \dots n}\) may appear similar, they are different. For instance, if \(\mathfrak{q}\) is \(() \xrightarrow{a} (x) \rightarrow (x) \rightarrow ()\), then the semantics of \(\mathfrak{p}_c = \mathfrak{q}\mathfrak{q}\) is the set of paths \(v_0 \thinspace a_1 \thinspace v_1 \dots a_6 \thinspace v_6\) of length six, where \(a_1 = a_4 = a\) and \(v_1 = v_2 = \dots = v_5\). However, the semantics of \(\mathfrak{p}_r = \mathfrak{q}^{2 \dots 2}\) is the set of data paths \(v'_0 \thinspace a'_1 \thinspace v'_1 \dots a'_6 \thinspace v'_6\) of length six, where \(a'_1 = a'_4 = a\), \(v'_1 = v'_2\), and \(v'_4 = v'_5\). Therefore, constructing \(A_{\mathfrak{p}}\) for \(\mathfrak{p}= \mathfrak{q}^{n \dots n}\) is analogous to concatenating \(\mathfrak{q}\) with itself \(n\) times, except that register unification is unnecessary. This construction is achieved simply by assigning each copy of \(A_\mathfrak{q}\) its own independent set of registers.

Suppose \(\mathfrak{p}=\mathfrak{q}^{1 \dots \infty}\). Without loss of generality, we assume that there are no outgoing transitions starting from final states of \(A_{\mathfrak{q}}\). In this case, \(A_{\mathfrak{p}}\) is derived from \(A_{\mathfrak{q}}\), where: (1) for every transition \(\delta\) of \(A_{\mathfrak{q}}\) from state \(s_1\) to state \(s_2\), if state \(s_2\) is final, then replacing \(s_2\) with an initial state \(s_0\) gives rise to a new transition \(\delta'\), which is also part of \(A_{\mathfrak{p}}\); (2) all final states of \(A_{\mathfrak{q}}\) are transformed into initial states of \(A_{\mathfrak{p}}\). Moreover, during the application of transition \(\delta'\), all register values are set to \(\sharp\).

Analogous to the union case, for every path \(\rho\), if \(\gamma\) is an accepting run of \(A_{\mathfrak{p}}\) on the data path \(\mathbf{dp}(\rho)\), then \((\rho,\mu) \in [\![{\mathfrak{p}}]\!]_{G}\), where \(\mu\) is derived from \(\gamma\) as follows: the mapping \(\mu\) assigns a free variable \(x\) to \(v\) if the registers corresponding to \(x\) hold the value \(v\), and to the null value \(\sharp\) if those registers remain unwritten along \(\gamma\).

Conditioning

Suppose \(\mathfrak{p}= \mathfrak{q}_{\langle \theta \rangle}\), where \(\theta = x \equiv_{\mathrm{\small data} } y\) for some node variables \(x\) and \(y\), and \(A_{\mathfrak{q}}\) is the automaton for \(\mathfrak{q}\). Without loss of generality, we assume there are no outgoing transitions starting from final states of \(A_{\mathfrak{q}}\).

\(A_{\mathfrak{p}}\) is identical to \(A_{\mathfrak{q}}\) except for those transitions ending in final state \(s_f\). Suppose \(\delta= s \xrightarrow{\boldsymbol{Pre}, \boldsymbol{Upd}} s_f\) is a transition of \(A_{\mathfrak{q}}\). We create a new transition \(\delta'\) which behaves as \(\delta\) except that the precondition \(\boldsymbol{Pre}\) is conjoined with the condition that the value of \(r^{\mathrm{\small data} }_x\) is equal to the value of \(r^{\mathrm{\small data} }_y\). In the case of \(\theta = \theta_1 \wedge \theta_2\), \(\theta_1 \vee \theta_2\), or \(\neg \theta_1\), the construction of \(A_{\mathfrak{p}}\) follows a similar process.

This completes the inductive construction of \(A_{\mathfrak{p}}\). Moreover, we have the structural inductive invariant on patterns that for every path \(\rho\), \(\mathbf{dp}(\rho)\) is accepted by \(A_{\mathfrak{p}}\) if and only if there exists a mapping \(\mu\) such that \((\rho, \mu) \in [\![{\mathfrak{p}}]\!]_{G}\). Thus, (S) holds, and we conclude that for every GPC query \(Q\) of the form \(\mathfrak{t}\;\mathfrak{p}\), there exists a 1-ary \(\forall\)(ERDPQ) formula \(\phi_Q(\pi)\) equivalent to \(Q\).

Thus we have completed the proof of (S). As a result, we derive Theorem 2. ◻

4.2 The data complexity of \(\forall\)(ERDPQ)↩︎

In the previous subsection, we introduced a fragment \(\forall\)(ERDPQ) of
FO(ERDPQ), which has no elementary bound on the data complexity, and showed that GPC is subsumed by \(\forall\)(ERDPQ). Additionally, we asserted that \(\forall\)(ERDPQ) has significantly lower data complexity than FO(ERDPQ), within PSPACE in terms of the size of the data graph \(G\) w.r.t. the standard encoding, which is basically polynomial in the number of the nodes and the number of edge labels. From this, we could conclude that \(\forall\)(ERDPQ) is strictly less expressive than FO(ERDPQ). We will now substantiate this data complexity claim.

Each quantifier-free FO(ERDPQ) formula \(\psi\) is a Boolean combination of atoms of the form \(\bar{\pi} \in A\) or \(\bar{\pi} \not\in A\). To check that a universally-quantified sentence does not hold on a given graph, we can negate it as an existentially-quantified Boolean combination, and then guess a conjunction of atoms of the above form that witness satisfiability.

Thus to show that \(\forall\)(ERDPQ) query evaluation is in PSPACE, it suffices to give a PSPACE algorithm for checking satisfiability of formulas: \[\label{eq:normal95form} \exists \bar{\omega}. \bigwedge_i \bar{\omega} \in A_i \wedge \bigwedge_j \neg \bar{\omega} \in B_j. \tag{1}\] Since we are concerned with data complexity, the sizes of the \(\forall\)(ERDPQ) formulas are treated as constants. Specifically, the number of variables, the number of RDPAs \(A_i\) and \(B_j\), the number of conjunctions, and the sizes of \(A_i\) and \(B_j\) are all considered constant, where the size of an RDPA refers to the number of states, transitions, and registers.

Proposition 1. Fix \(A_i,B_i\), \(i \leq n\), \(m\)-ary RDPAs and let \(\phi:=\exists \bar{\omega}. \bigwedge_i \bar{\omega} \in A_i \wedge \bigwedge_j \bar{\omega} \not\in B_j\). There is an algorithm that checks if \(G \models \phi\) running in PSPACE in the size of \(G\).

Proof. For simplicity, we will assume \(m=1\). Let \(\mathcal{D}_G\) be the set of data values appearing in \(G\) and \(\Sigma_G = \mathcal{D}_G \cup \Sigma\), a set that is polynomial in \(G\) for fixed \(\Sigma\). For any RDPA \(A\) there is a PTIME algorithm inputting \(G\) and producing an NFA over \(\Sigma_G\) that accepts exactly the data paths through \(G\) that are accepted by \(A\). Intuitively, we can consider \(G\) as an automaton, and the resulting automaton is the product automaton of \(A\) and \(G\), which can be constructed in quadratic time. Applying this to each \(A_i\) and \(B_j\), we have reduced to checking whether a Boolean combination of NFA is non-empty. Since the size of the product automaton for a \(B_j\) and \(G\) is polynomial in the size of \(G\), checking the emptiness of the complement of the product automaton can be done in PSPACE with respect to the size of \(G\). ◻

Combining the reduction to satisfiability of sentences of the form (Eq. 1 ), we have shown that \(\forall\)(ERDPQ) has much lower complexity than FO(ERDPQ):

Corollary 1. The data complexity of \(\forall\)(ERDPQ) query evaluation is in PSPACE.

4.3 RDPQ to FO\(^*(\equiv_{\mathrm{\small data} })\)↩︎

To show the inclusion of RDPQ in FO\(^*(\equiv_{\mathrm{\small data} })\), for every RDPA\(A\) we will construct an FO\(^*(\equiv_{\mathrm{\small data} })\) formula \(\phi_A\) simulating the computation of \(A\). Without loss of generality, assume \(A\) is a unary RDPA over \(\Sigma=\{a,b\}\) and it has \(n=2^t\) states for some positive integer \(t\). Similar to the translation of an \(n\)-ary NFA to an FO\(^*\) formula for arbitrary \(n\), the translation from an \(n\)-ary RDPA\(A\) to \(\phi_A\) follows a process analogous to the 1-ary case. First, let’s explore a simplified scenario of using an FO\(^*\) formula to emulate the computation of an NFA.

Let \(G\) be a graph with only ids as data, containing at least two nodes \(v\) and \(w\). Let \(A\) be an NFA. We can assume \(Q=\{\boldsymbol{r}_1,\dots,\boldsymbol{r}_n\}\), where each \(\boldsymbol{r}_i\) is a \(t\)-tuple over \(\{v,w\}\). We do this by taking \(t\) large enough so that the size of \(Q\) is at most \(2^t\). Since \(Q\) is finite, we can define first-order formulas \(\phi^{\boldsymbol{tran}}_a\) and \(\phi^{\boldsymbol{tran}}_b\) such that (i) \(\phi^{\boldsymbol{tran}}_a(\boldsymbol{r}_i,\boldsymbol{r}_j)\) holds if and only if \((\boldsymbol{r}_i,a,\boldsymbol{r}_j)\) is a transition in \(A\) for \(i,j \in [n]\) and (ii) \(\phi^{\boldsymbol{tran}}_b(\boldsymbol{r}_i,\boldsymbol{r}_j)\) holds if and only if \((\boldsymbol{r}_i,b,\boldsymbol{r}_j)\) is a transition in \(A\) for \(i,j \in [n]\).

For any path \(\rho\) in \(G\), with label \(\mathbf{lb}(\rho)=a_1\dots a_m \in L(A)\), there exist sequences of states \(p_0 \dots p_m\) and nodes \(v_0 \dots v_m\) in \(G\) such that \(p_0\) is the initial state, \(p_m\) is a final state, \((p_{i-1},a_i,p_i)\) is a transition in \(A\), and \((v_{i-1},a_i,v_i)\) forms an edge in \(G\) for \(i\in [m]\). We can define: \[\psi^{\boldsymbol{tran}}_?(\boldsymbol{z},\boldsymbol{z}'):= \phi^{\boldsymbol{tran}}_?(\boldsymbol{x},\boldsymbol{x}') \wedge E_?(y,y'),\] where \(\boldsymbol{z}=(\boldsymbol{x},y)\) and \(\boldsymbol{z}'=(\boldsymbol{x}',y')\) have the same arity, for \(?=a,b\) and \[\psi_{\boldsymbol{tran}} := \psi^{\boldsymbol{tran}}_a \vee \psi^{\boldsymbol{tran}}_b.\] Thus \(\mathbf{lb}(\rho) \in L(A)\) if and only if \(\psi^*_{\boldsymbol{tran}}(\boldsymbol{r},\boldsymbol{s})\) holds where \(\boldsymbol{r}=(\boldsymbol{r}_i,r)\), \(\boldsymbol{s}=(\boldsymbol{r}_j,s)\), \(\boldsymbol{r}_i\) is the initial state, \(\boldsymbol{r}_j\) is a final state, and \(\rho\) goes from node \(r\) to node \(s\).

Now, let’s consider the general case where \(A\) is an RDPA and \(G\) is a data graph. Suppose that \(A\) has registers \(\{1, \dots, \ell\}\) and \(u = d_1 \thinspace d_2 \dots d_m\) is a data path in \(G\). The data path \(u\) is accepted by \(A\) if there exists a sequence of accepting configurations \(c_0 \thinspace c_1 \dots c_m\) and a sequence of transitions \(\delta_1 \dots \delta_m\) such that \(c_{i-1} \xrightarrow{d_i}_{\delta_i} c_i\) for each \(i \in [m]\). Assume \(X_{\mathrm{\small id} }=\{1,\dots,\eta-1\}\) and \(X_{\mathrm{\small data} }=\{\eta,\dots,\ell\}\) for some index \(\eta\). A configuration of \(A\) takes the form \((q,r_1,\dots,r_\ell)\), where \(q\) is an \(A\)-state, \(r_i=\mathrm{\small id} (v_j)\) if \(i < \eta\), and \(r_i=\nodedata(v_j)\) if \(i\geq \eta\) for some \(v_j\) in \(G\). The value of \(r_i\) is uniquely determined once \(v_j\) is known. Thus \(u\) is accepted by \(A\) if and only if there exists a sequence \(\alpha_0 \dots \alpha_m\), where \(\alpha_i = (q_i,v^{(i)}_1,\dots,v^{(i)}_\ell)\) for some \(A\)-state \(q_i\) and \(G\)-nodes \(v^{(i)}_1,\dots,v^{(i)}_\ell\) such that \(c_i = (q_i,\mathrm{\small id} (v^{(i)}_1),\dots,\mathrm{\small id} (v^{(i)}_{\eta-1}),\nodedata(v^{(i)}_\eta),\dots,\nodedata(v^{(i)}_\ell))\) for \(i \in [m]\).

In the case of NFA emulation, we utilized tuples \(\boldsymbol{r}\) of nodes to carry the state information of the automaton. Likewise, for RDPAs, we can also employ tuples of nodes to carry \(\alpha_0, \dots, \alpha_m\) around. Recall that there are two kinds of transitions in \(A\): word transitions of the form \(\delta_w = p \xrightarrow{a} q\) and data transitions of the form \(\delta_d = r \xrightarrow{E,I,U} s\). When \(\delta_w\) is applied, the content of the registers is not modified. Therefore the RDPA-version formula \(\psi^{\boldsymbol{tran}}_{\delta_w}(\boldsymbol{x}, y, \boldsymbol{z}, \boldsymbol{x}', y', \boldsymbol{z}')\) corresponding to \(\delta_w\) can be defined as: \[\begin{align} \phi^{\boldsymbol{tran}}_a(\boldsymbol{x}, \boldsymbol{x}') \wedge E_a(y, y') \wedge \left(\bigwedge_{1 \leq i < \eta} (z_i = z'_i)\right) \wedge \left(\bigwedge_{\eta \leq i \leq \ell} (z_i \equiv_{\mathrm{\small id} } z'_i)\right). \end{align}\] When \(\delta_{\delta_d}\) is applied, the values of the registers are compared with the data value of a node and updated. We can define the RDPA-version formula \(\psi^{\boldsymbol{tran}}_d\) corresponding to \(\delta_d\) as follows: \[\psi^{\boldsymbol{tran}}_{\delta_d}(\boldsymbol{x}, y, \boldsymbol{z}, \boldsymbol{x}', y', \boldsymbol{z}', w) := \phi^{\boldsymbol{tran}}_d(\boldsymbol{x}, \boldsymbol{x}') \wedge \phi_{E}(\boldsymbol{z}, w) \wedge \phi_I(\boldsymbol{z}, w) \wedge \phi_U(\boldsymbol{z}, \boldsymbol{z'}, w),\] where:

  • \(\phi^{\boldsymbol{tran}}_d\) is the formula such that \(\phi^{\boldsymbol{tran}}_d(\boldsymbol{r}, \boldsymbol{s})\) holds if and only if \(\delta_d=r \xrightarrow{E, I, U} s\) is a data transition from \(r\) to \(s\), and states \(r, s\) correspond to tuples \(\boldsymbol{r}, \boldsymbol{s} \in Q\), respectively.

  • \[\phi_E(\boldsymbol{z}, w) := \left(\bigwedge_{x_i \in E_{\mathrm{\small id} }} z_i = w\right) \wedge \left(\bigwedge_{x_i \in E_{\mathrm{\small data} }} z_i \equiv_{\mathrm{\small data} } w\right)\] states that the id of node \(w\) is identical to the values of registers in \(E_{\mathrm{\small id} }\) and the data value excluding the id of node \(w\) is identical to the values of registers in \(E_{\mathrm{\small data} }\).

  • \[\phi_I(\boldsymbol{z}, w) := \left(\bigwedge_{x_i \in I_{\mathrm{\small id} }} \neg(z_i = w)\right) \wedge \left(\bigwedge_{x_i \in I_{\mathrm{\small data} }} \neg(z_i \equiv_{\mathrm{\small data} } w)\right)\] states that the id of node \(w\) is different from the values of registers in \(I_{\mathrm{\small id} }\) and the data value excluding the id of node \(w\) is different from the values of registers in \(I_{\mathrm{\small data} }\).

  • \[\phi_U(\boldsymbol{z}, \boldsymbol{z}', w) := \left(\bigwedge_{x_i \not\in U} z'_i = z_i\right) \wedge \left(\bigwedge_{x_i \in U} z'_i = w\right)\] states how the registers are updated.

Finally, let \[\psi_{\boldsymbol{tran}}(\boldsymbol{x},y,\boldsymbol{z},v,\boldsymbol{x}',y',\boldsymbol{z}',v'):= \bigvee_{\delta\in\Delta} \psi^{\boldsymbol{tran}}_{\delta} \wedge \phi_{\delta}(v,v'),\] where \(\phi_\delta(v,v')\) holds if \(\delta\) is a data transition with \((v,v')=(w,u)\), or if \(\delta\) is a word transition with \((v,v')=(u,w)\). Thus, we have \(\mathbf{dp}(\rho) \in L(A)\) if and only if \(\psi^*_{\boldsymbol{tran}}(\boldsymbol{x},y,\boldsymbol{z},w,\boldsymbol{x}',y',\boldsymbol{z}',u)\) holds, where \(\boldsymbol{x}\) is the initial state, \(\boldsymbol{x}'\) is a final state, \(\boldsymbol{z}\) specifies that all registers hold the null value \(\sharp\), and \(\rho\) is a path from node \(y\) to node \(y'\). This completes the proof.

4.4 Strictness of the inclusions in Figure 1↩︎

Since GXPath\(_{\mathrm{\small reg}}(\equiv_{\mathrm{\small data} })\) and (FO\(^*_{3}\))\((\equiv_{\mathrm{\small data} })\) share the same expressive power [2], GXPath\(_{\mathrm{\small reg}}(\equiv_{\mathrm{\small data} })\) is subsumed by full transitive closure logic, as shown in Figure 1. The following result states that the subsumptions in the diagram are all strict.

Theorem 3. Assuming NL\(\neq\) NP, no containment relations other than those depicted in the diagram are valid. Specifically, all the containment relations in the diagram are strict.

Since the diagram includes numerous containments, for the sake of clarity, we will initially enumerate a set of properties that we intend to derive.

A. Every pair from the following set is incomparable: GPC, WL, FO(RDPQ), FO\(^*(\equiv_{\mathrm{\small data} })\) under the assumption that NL\(\neq\) NP.

B. GXPath\(_{\mathrm{\small reg}}(\equiv_{\mathrm{\small data} })\) is not subsumed by FO(ERDPQ).

C. RDPQ is not subsumed by GXPath\(_{\mathrm{\small reg}}(\equiv_{\mathrm{\small data} })\), GPC, or WL.

The assumption NL\(\neq\) NP will be used only in the first item, and there it will be used to derive that GPC and FO(RDPQ) are not subsumed by FO\(^*(\equiv_{\mathrm{\small data} })\) and GPC is not subsumed by FO(RDPQ). In the previous section, we showed that RDPQ, a query language based on regular languages, is subsumed by FO\(^*(\equiv_{\mathrm{\small data} })\). However, we cannot extend this result to GPC, although GPC is also inspired by regular languages. That is, GPC is not subsumed by FO\(^*(\equiv_{\mathrm{\small data} })\), due to the usage of restrictors in GPC. Specifically, it is unclear whether the notion of “simple” can be expressed in FO\(^*(\equiv_{\mathrm{\small data} })\).

These properties are sufficient to obtain the following, which implies that no other containments are derivable:

A. FO\(^*(\equiv_{\mathrm{\small data} })\) and FO(ERDPQ) are incomparable.

B. GPC, WL, FO(RDPQ) are strictly subsumed by FO(ERDPQ).

C. RDPQ is strictly subsumed by FO(RDPQ) and FO\(^*(\equiv_{\mathrm{\small data} })\).

D. GPC, WL, RDPQ, and GXPath\(_{\mathrm{\small reg}}(\equiv_{\mathrm{\small data} })\) are incomparable.

E. GXPath\(_{\mathrm{\small reg}}(\equiv_{\mathrm{\small data} })\) is incomparable with FO(RDPQ) and FO(ERDPQ).

F. GXPath\(_{\mathrm{\small reg}}(\equiv_{\mathrm{\small data} })\) is strictly subsumed by FO\(^*(\equiv_{\mathrm{\small data} })\).

We start with P.[prop:sublanguage95incomparable]. We begin by showing that FO\(^*(\equiv_{\mathrm{\small data} })\) is not subsumed in any of the other languages considered in P.[prop:sublanguage95incomparable]. To give intuition for the separating example, consider an encoding of an ordinary graph \(G\), with arbitrary connectivity, as a highly disconnected data graph \(G'\), where in \(G'\) each node is linked to only two other nodes. The translation is shown in Figure 7. The edge connection between nodes \(v_2\) and \(v_4\) in \(G\) is represented in \(G'\) as an \(\mathrm{\small OUT}\)-labelled edge to a node carrying a certain data value, then an \(\mathrm{\small IN}\)-edge from another node with the same data value to \(v_4\).

Based on this, we create our separating example. We formulate an FO formula \(\mathrm{\small DataLink} (x, y)\) such that a pair of nodes \(v\) and \(w\) in \(G'\) satisfies \(\mathrm{\small DataLink}\) if there exists a node \(s\) linked to \(v\) through an \(\mathrm{\small OUT}\) edge and another node \(f\) linked to \(w\) through an \(\mathrm{\small IN}\) edge, with the data value of \(s\) equating the data value of \(f\). For instance, \((v_1, v_4)\) satisfies \(\mathrm{\small DataLink}\), while \((v_3, v_5)\) does not. Accordingly, we can create an FO\(^*(\equiv_{\mathrm{\small data} })\) formula \(\mathrm{\small DataConnection} (x, y)\) representing the transitive closure of \(\mathrm{\small DataLink}\). Consequently, a pair of nodes \((v, w)\) in \(G'\) satisfies \(\mathrm{\small DataConnection}\) if \(v\) and \(w\) are connected in \(G\).

We now argue that this formula cannot be expressed in the other languages mentioned in P.[prop:sublanguage95incomparable], like FO(ERDPQ). To see this, consider the family of graphs similar to \(G'\) in Figure 7, and note that path lengths are confined to \(2\). Therefore, fixing a vocabulary with three relations \(P_0, P_1, P_2\) over nodes – where \(P_0\), \(P_1\), and \(P_2\) are unary, binary, and ternary, respectively – we can convert any FO(ERDPQ) formula \(f\) into a first-order logic formula without path variables. But connectivity cannot be expressed using first-order logic [22]. Consequently, FO(ERDPQ) does not subsume FO\(^*(\equiv_{\mathrm{\small data} })\), and thus FO\(^*(\equiv_{\mathrm{\small data} })\) is not subsumed by any of the other three languages.

It is known that there is no elementary bound on the data complexity for WL, even for graphs with only ids as data [5]. But FO\(^*(\equiv_{\mathrm{\small data} })\), GPC, and FO(RDPQ) do have elementary bounds on data complexity, with FO\(^*(\equiv_{\mathrm{\small data} })\) having a NL bound [23]. Consequently, these languages cannot subsume WL.

What remains in P.[prop:sublanguage95incomparable] is to show that GPC and FO(RDPQ) cannot be subsumed by WL, by FO\(^*(\equiv_{\mathrm{\small data} })\), or by each other. It is known [24] that GPC can express NP-hard queries (in particular, \(Q_{\boldsymbol{even}}\)).

Proposition 2. ([24])Query evaluation for GPC(even without data) is \(\mathrm{\small NP}\)-hard in data complexity.

We now argue that FO(RDPQ) are both NP-hard in data complexity. Since FO\(^*(\equiv_{\mathrm{\small data} })\) is in NL, this will imply that FO\(^*(\equiv_{\mathrm{\small data} })\) cannot subsume either of these languages, assuming NP is not equal to NL.

Proposition 3. Query evaluation for FO(RDPQ) is NP-hard in terms of data complexity.

Proof. We reduce the Hamiltonian path problem to FO(RDPQ) query evaluation. Given a directed graph \(G=(V,E)\) where \(|V|=n_G\) and \(V=[n_G]\), we let \(G'=(V',E',\mathrm{\small id} ,\nodedata)\) be the data graph where

  • \(\Sigma=\{a,b\}\),

  • \(V' = \bigcup_{i=1}^{n_G} V_i\) where \(V_i = \{v + i\cdot n_G \in \mathbb{N} \mid v \in V\}\),

  • \(E'=\bigcup_{i=2}^{n_G} E_i\) where \(E_i = \{(v+(i-1)\cdot n_G ,a_i,w+i\cdot n_G) \in V_{i-1}\times \Sigma \times V_i \mid (v,w) \in E\}\) and \(a_i=a\) iff \(i \in \{2, n_G\}\),

  • \(\nodedata(v+i\cdot n_G) = v\) for each \(v \in V\) and \(1 \leq i \leq n_G\).

According to the construction of \(G'\), we have that \(G\) contains a Hamiltonian path if and only if there is a path \(\pi\) in \(G'\) such that the data path \(\mathbf{dp}(\pi) = d_1 \thinspace a_2 \thinspace d_2 \dots a_{n_G} \thinspace d_{n_G}\), \(a_2\dots a_{n_G} \in ab^*a\), and \(d_1\dots d_{n_G} \not\in L=\{e_1\dots e_m \in \mathbb{N}^* \mid e_i = e_j \textit{ for some } 1\leq i < j \leq m\}\). Regular languages are closed under complement, so there is a finite automaton recognizing the complement of \(ab^*a\). It is known that \(L\) is recognizable by a register automaton [18]. Consequently, we have that there is an RDPA\(A\) such that the data path \(\mathbf{dp}(\pi) = d_1 \thinspace a_2 \thinspace d_2 \dots a_{n_G} \thinspace d_{n_G} \not\in L(A)\) if and only if \(a_2\dots a_{n_G} \in ab^*a\) and \(d_1\dots d_{n_G} \not\in L\). ◻

While GPC and FO(RDPQ), which are based on regular languages, can express the query \(Q_{\boldsymbol{even}}\), we know from [4] that \(Q_{\boldsymbol{even}}\) is not expressible in WL for graphs with only ids as data. Thus neither of these languages is subsumed by WL.

To finish the derivation of Property P.[prop:sublanguage95incomparable], we need to show that neither of FO(RDPQ) and GPC subsumes the other. For one non-containment, we use that GPC is NP-hard even without data (Proposition 2), while FO(RDPQ) is in NL without data [3]. For the other, we show that even RDPQ is not subsumed by GPC: this is shown in the argument for Property P.[prop:languages95not95contain95rd] below.

We turn to P.[prop:edn95not95contain95gxpath]. Previously, we derived that FO\(^*(\equiv_{\mathrm{\small data} })\) is not subsumed by FO(ERDPQ) by showing that \(\mathrm{\small DataConnection}\) cannot be expressed within FO(ERDPQ). This example can be used to show non-containment of GXPath\(_{\mathrm{\small reg}}(\equiv_{\mathrm{\small data} })\) within FO(ERDPQ). The languages GXPath\(_{\mathrm{\small reg}}(\equiv_{\mathrm{\small data} })\) and (FO\(^*_{3}\))\((\equiv_{\mathrm{\small data} })\) are equivalent in expressiveness [2]. The language
(FO\(^*_{3}\))\((\equiv_{\mathrm{\small data} })\) allows us to express \(\mathrm{\small DataConnection} =\mathrm{\small DataLink} ^*\), where \(\mathrm{\small DataLink} (x,y)\) is \[\exists z. (\mathrm{\small OUT}(z,x) \wedge (\exists x. (\mathrm{\small IN}(x,y) \wedge x \equiv_{\mathrm{\small data} } z)))\] As a result, we have P.[prop:edn95not95contain95gxpath].

Next, we argue for P.[prop:languages95not95contain95rd]. Given that RDPQ is also based on regular languages, it can express the query \(Q_{\boldsymbol{even}}\). Consequently, we deduce that WL does not subsume RDPQ. Let’s define \(Q_{\mathrm{\small 4nodes}}\) as the query: \[\begin{align} Q_{\mathrm{\small 4nodes}}:= & \textit{``Is there a path from node s to node t}\\ & \textit{containing four distinct nodes?''.} \end{align}\] For any complete graph \(G\) with two nodes \(s\) and \(t\), there exists a path from \(s\) to \(t\) containing four distinct nodes if and only if \(G\) has at least four nodes. It was established that no GXPath\(_{\mathrm{\small reg}}(\equiv_{\mathrm{\small data} })\) formula can differentiate between \(K_3\) and \(K_4\) [2], where \(K_n\) is the complete graph on \(n\) nodes for all \(n\in \mathbf{Z}_{>0}\). More specifically, there is no GXPath\(_{\mathrm{\small reg}}(\equiv_{\mathrm{\small data} })\) sentence \(\phi\) such that \(K_4 \models \phi\), but \(K_3 \not\models \phi\). Therefore, \(Q_{\mathrm{\small 4nodes}}\) cannot be expressed using the language GXPath\(_{\mathrm{\small reg}}(\equiv_{\mathrm{\small data} })\). However, the query \(Q_{\mathrm{\small 4nodes}}\) is expressible using RDPQ. So we conclude that GXPath\(_{\mathrm{\small reg}}(\equiv_{\mathrm{\small data} })\) does not subsume RDPQ.

Lastly, to show that RDPQ is not subsumed by GPC, we require the notion of normal form patterns and their corresponding properties:

Definition 6. A GPC pattern \(\mathfrak{p}\) is in normal form* if \(\mathfrak{p}= \mathfrak{p}_1 + \dots + \mathfrak{p}_n\), where each \(\mathfrak{p}_i\) is of the form \(\{{\mathfrak{q}_1} \dots {\mathfrak{q}_m}\}_{\langle \theta \rangle}\) such that for every \(j \in [m]\), \(\mathfrak{q}_{j}\) is either:*

  • an atomic pattern, or

  • \(\mathfrak{q}_{j}= \mathfrak{q}^* (= \mathfrak{q}^{0..\infty})\) for some pattern \(\mathfrak{q}\).

By applying the following two families of rules, we can normalize every GPC pattern. The first family pushes filters out of compositions:

Proposition 4. \(\mathfrak{p}_{\langle \theta \rangle} \mathfrak{q}_{\langle \eta \rangle} \approx \{\mathfrak{p}\mathfrak{q}\}_{\langle \theta \wedge \eta \rangle}\) if the pattern \(\mathfrak{p}_{\langle \theta \rangle} \mathfrak{q}_{\langle \eta\rangle}\) is valid.

Proof. Suppose \((\rho,\mu) \in [\![{\mathfrak{p}_{\langle \theta \rangle} \mathfrak{q}_{\langle \eta \rangle}}]\!]_{G}\). Then, we have \((\rho,\mu) \in [\![{\mathfrak{p}\mathfrak{q}}]\!]_{G}\), \(\mu \models \theta\), and \(\mu \models \eta\). These imply \((\rho,\mu) \in [\![{\mathfrak{p}\mathfrak{q}}]\!]_{G}\) and \(\mu \models \theta \wedge \eta\). Accordingly, we have \((\rho,\mu) \in [\![{\{\mathfrak{p}\mathfrak{q}\}_{\langle \theta \wedge \eta \rangle}}]\!]_{G}\).

Conversely, if \((\rho,\mu) \in [\![{\{\mathfrak{p}\mathfrak{q}\}_{\langle \theta \wedge \eta \rangle}}]\!]_{G}\), then \((\rho,\mu) \in [\![{\mathfrak{p}\mathfrak{q}}]\!]_{G}\) and \(\mu \models \theta \wedge \eta\), which implies \(\mu \models \theta\) and \(\mu \models \eta\). Thus, we conclude \((\rho,\mu) \in [\![{\mathfrak{p}_{\langle \theta \rangle} \mathfrak{q}_{\langle \eta \rangle}}]\!]_{G}\). ◻

A second family of normalization rules eliminates filters from Kleene star patterns:

Proposition 5. \(\{\mathfrak{p}^*\}_{\langle \theta \rangle} \approx \{\mathfrak{p}^*\}_{\langle \top \rangle} \approx \mathfrak{p}^*\) if \(\{\mathfrak{p}^*\}_{\langle \theta \rangle}\) is valid.

Proof. By the definition of GPC patterns, we have \(\mathrm{\small FV}(\mathfrak{p}^*) = \emptyset\). Accordingly, if \(\{\mathfrak{p}^*\}_{\langle \theta \rangle}\) is valid, then \(\theta\) must be equivalent to \(\top\). ◻

Note also that \(\mathfrak{p}^{n...m}\) can be eliminated, since it can be seen as \(\mathfrak{p}^{n...n}+...+\mathfrak{p}^{m...m}\), and each \(\mathfrak{p}^{i...i}\) is equivalent to the concatenation of \(i\) copies of \(\mathfrak{p}\), with each copy using a fresh set of node variables. This allows us to consider only the case \(\mathfrak{p}^{0...\infty}\).

As a result, we have:

Lemma 1. Every GPC pattern is equivalent to a normal form pattern.

We will also rely on the fact that patterns cannot distinguish between two graphs that are isomorphic:

Proposition 6. Let \(\mathfrak{p}\) be a GPC pattern. For any two data graphs \(G_1 = (V_1, E_1, \nodedata_1)\) and \(G_2 = (V_2, E_2, \nodedata_2)\), if \(V_1 = V_2\), \(E_1 = E_2\), and \(\nodedata_1(v_i) = \nodedata_1(v_j) \Leftrightarrow \nodedata_2(v_i) = \nodedata_2(v_j)\) for all \(i, j\), and if \(\mu_1, \mu_2\) are two mappings such that \(\nodedata_1(\mu_1(x)) = \nodedata_2(\mu_2(x))\) for all \(x \in \mathrm{\small FV}(\mathfrak{p})\), then \((\rho_{G_1}, \mu_1) \in [\![{\mathfrak{p}}]\!]_{G_1} \Leftrightarrow (\rho_{G_2}, \mu_2) \in [\![{\mathfrak{p}}]\!]_{G_2}.\)

Now we are ready to show that RDPQ is not subsumed by GPC.

Theorem 4. RDPQ is not subsumed by GPC.

Proof. To prove this theorem, we will show that the following query, which is evidently expressible in RDPQ, cannot be expressed in GPC: \[\begin{align} Q_{\boldsymbol{3val}}(s,t):= & \textit{``Is there a path \rho from node s to node t where the number of}\\ & \textit{distinct data values (excluding ids) along \rho is exactly 3?''.} \end{align}\]

Figure 8: Chain graph G and path \rho_G from s to t.

We will actually show a stronger separation: \(Q_{\boldsymbol{3val}}\) cannot be expressed in \(GPC\) even over chain graphs. Suppose we restrict our attention to the chain data graphs shown in Figure 8, and we use \(\rho_G\) to denote the unique, shortest path from \(s\) to \(t\) in graph \(G\). In such graphs, a path from \(s\) to \(t\) contains exactly three distinct data values if and only if it is \(\rho_G\). Accordingly, we can restrict ourselves to the case where \(\mathfrak{t}=\mathrm{\small shortest}\). This assertion holds even when restricting to chain data graphs over a unary alphabet \(\Sigma\) (i.e., \(\Sigma\) contains exactly one symbol).

a
b

Figure 9: A data graph \(G\) with exactly 3 distinct data values (excluding ids).. a — Three isomorphic copies \(H_1,H_2, H_3\) of \(G\)., b — Data graph \(G'\) derived from merging \(G\) and \(H_2\).

Before continuing, we provide an overview and the main idea of the proof showing why a pattern equivalent to \(Q_{\boldsymbol{3val}}\) does not exist. We will use a proof by contradiction. Specifically, we will demonstrate that for any pattern \(\mathfrak{p}\), it is possible to construct two graphs, \(G\) and \(G'\), such that \(\rho_G\) and \(\rho_{G'}\) either both agree with \(\mathfrak{p}\) or both disagree with \(\mathfrak{p}\). However, \(G\) contains exactly three distinct data values, while \(G'\) does not. See Figure 9 (a). The data graph \(G\) contains exactly three distinct data values (excluding ids), namely 1, 2, and 3. Additionally, the data graphs \(H_1, H_2, H_3\) are isomorphic to \(G\) and to each other. By Proposition 6, we have that for any pattern \(\mathfrak{p}\), \(\rho_{G}\) is in the semantics of \(\mathfrak{p}\) if and only if \(\rho_{H_i}\) is in the semantics of \(\mathfrak{p}\) for \(i \in \{1, 2, 3\}\). See Figure 9 (b). Furthermore, we can construct a data graph \(G'\) from \(G\) and \(H_i\) for some \(i \in \{1,2,3\}\) such that \(G'\) contains exactly four distinct data values (excluding ids) and satisfies \(\mathfrak{p}\) in the same way as \(G\), \(H_1\), \(H_2\), and \(H_3\).

We now proceed to provide the detailed proof. Suppose that \(\mathfrak{p}_{\boldsymbol{3val}}\) is a GPC pattern such that \(\mathfrak{t}\;\mathfrak{p}_{\boldsymbol{3val}}\) expresses \(Q_{\boldsymbol{3val}}\), where \(\mathfrak{t}=\mathrm{\small shortest}\).

For simplicity, throughout the rest of this section, when comparing two chains \(G_1=(V_1,E_1,\mathrm{\small id} _i,\nodedata_1)\) and \(G_2=(V_2,E_2,\mathrm{\small id} _2,\nodedata_2)\), if \(|V_1| \leq |V_2|\), we assume \(V_1 \subseteq V_2\) and \(E_1 \subseteq E_2\), and we will directly ignore the functions \(\mathrm{\small id} _1\) and \(\mathrm{\small id} _2\), as well as the labels of edges, treating paths as sequences of nodes. Furthermore, given a chain \(G=(V,E,\nodedata)\), we assume that \(V=\{v_0,\dots,v_n\}\) for some \(n\), and \(E=\{(v_0,v_1),\dots,(v_{n-1},v_n)\}\). When referring to a path \(\rho=v_i\dots v_j\) in \(G\) for some \(i\leq j\), we use \(G_{\rho}\) to denote the subgraph \((V_{i,j},E_{i,j},\nodedata)\) from node \(v_i\) to \(v_j\), where \(V_{i,j}=\{v_i,\dots,v_j\}\) and \(E_{i,j}=\{(v_i,v_{j-1}),\dots,(v_{i+1},v_j)\}\). For any two patterns \(\mathfrak{p}\) and \(\mathfrak{q}\), we write \(\mathfrak{p}\approx \mathfrak{q}\) if \([\![{\mathfrak{p}}]\!]_{G} = [\![{\mathfrak{q}}]\!]_{G}\) for all \(G\).

If \(\mathfrak{p}_{\boldsymbol{3val}}\) is a disjunction of two sub-patterns \(\mathfrak{p}_1\) and \(\mathfrak{p}_2\), and a path \(\rho_G\) of chain graph \(G\) matches the pattern \(\mathfrak{p}_{\boldsymbol{3val}}\), then \(\rho_G\) matches \(\mathfrak{p}_1\) or \(\mathfrak{p}_2\). Accordingly, by the normal form assumption, we can assume that \(\mathfrak{p}_{\boldsymbol{3val}}\) is equivalent to \(\{\mathfrak{q}_1 \dots \mathfrak{q}_m\}_{\langle \theta \rangle}\) for some condition \(\theta\) and patterns \(\mathfrak{q}_1, \dots, \mathfrak{q}_m\), where each \(\mathfrak{q}_j\) is either an atomic pattern or has the form \(\mathfrak{r}^*\) for some pattern \(\mathfrak{r}\).

Now, consider any chain graph \(G\) with three alternating values that is sufficiently long, denoted as \(G=(V,E,\nodedata)\), where \[|V|=3^\ell> 3\cdot|\mathfrak{p}_{\boldsymbol{3val}}|+7\] for some positive integer \(\ell\). Here, \(\nodedata(\rho_G)=(d_1 \thinspace d_2 \thinspace d_3)^\ell\), and \(|\{d_1,d_2,d_3\}|=3\). We have \((\rho_G,\mu) \in [\![{\mathfrak{p}_{\boldsymbol{3val}}}]\!]_{G}\) for some \(\mu\). Since \(\frac{|V|-7}{3}> |\mathfrak{p}_{\boldsymbol{3val}}|\), there is an index \(j\) and a pattern \(\mathfrak{r}\) such that \(\mathfrak{q}_j = \mathfrak{r}^*\): in other words, there is some segment of the graph matched by a wildcard sub-pattern.

Consider \(\theta = \top\). There are two possibilities: \(m=1\) and \(m>1\). The case \(m=1\) can be easily transformed into case \(m>1\) because for every pattern \(\mathfrak{r}\), \(\mathfrak{r}^*\) is equivalent to \(\mathfrak{r}^*\mathfrak{r}^*\). Therefore, we will assume \(m>1\): the composition has more than one component.

Up to this point, we have been reasoning about the pattern \(\mathfrak{p}_{\boldsymbol{3val}}\) on the chain graph \(G\). Now we define several additional isomorphic copies of \(G\). Let \(e \not\in \{d_1,d_2,d_3\}\), and define \(H_i=(V,E,\nodedata_s)\) for \(i=1,2,3\), where \(\nodedata_1(\rho_{H_1})=(e \thinspace d_2 \thinspace d_3)^\ell\), \(\nodedata_2(\rho_{H_2})=(d_1 \thinspace e \thinspace d_3)^\ell\), and \(\nodedata_3(\rho_{H_3})=(d_1 \thinspace d_2 \thinspace e)^\ell\). For instance, let \(d_1=1, d_2=2, d_3=3\), and \(e=4\). Then, \(G, H_1, H_2, H_3\) are illustrated in Figure 9 (a).

Since all four graphs are isomorphic, and the set of nodes and the set of edges of \(H_i\) are \(V\) and \(E\), respectively, for all \(i=1,2,3\), by Proposition 6, we have \((\rho_{H_i},\mu) \in [\![{\mathfrak{p}_{\boldsymbol{3val}}}]\!]_{H_i}\) for \(i=1,2,3\). By our assumption, \(\mathfrak{p}_{\boldsymbol{3val}}=\{\mathfrak{q}_1\dots \mathfrak{q}_m\}_{\langle \theta \rangle}\), the path \(\rho_G\) (and \(\rho_{H_i}\) for \(i=1,2,3\)) can be divided into segments \(\rho_1,\dots,\rho_m\) (and \(\tau^i_1,\dots,\tau^i_m\) for \(i=1,2,3\)), where \((\rho_j,\mu_j) \in [\![ \mathfrak{q}_j ]\!]_{G}\) (and \((\tau^i_j,\mu_j) \in [\![ \mathfrak{q}_j ]\!]_{H_i}\) for \(i=1,2,3\)) for \(j=1,\dots,m\), where \(\mu_j\) is \(\mu\) restricted to the variables of \(\mathfrak{q}_j\). Additionally, we can assume that \(|\rho_j|=|\tau^i_j|\) for \(i=1,2,3\) for all \(j\).

Since \(|\rho_G|=|\rho_{H_1}|=|\rho_{H_2}|=|\rho_{H_3}|=|V| > 3\cdot|\mathfrak{p}_{\boldsymbol{3val}}|+7\), there is an index \(1\leq \iota \leq m\) such that \(3 \leq |\rho_\iota|=|\tau^i_\iota|\) for \(i=1,2,3\) and \(\mathfrak{q}_\iota = \mathfrak{r}^*\) for some \(\mathfrak{r}\). Since \(\mathfrak{r}^* \mathfrak{r}^*\) is equivalent to \(\mathfrak{r}^*\), we can also demand that \(|\rho_\iota| < |\rho_{G}| - 3\). In other words, there is a “non-trivial” segment matched by a Kleene star pattern component within \(G\), and likewise within each of the \(H_i\). This is a segment where we will perform our merging.

Let \(3 < a < b < 3^\ell-3\) be the indices marking the beginning and end of the crucial segment, corresponding to nodes \(v_a\) and \(v_b\) in graph \(G\), such that \(\rho_\iota=\rho_G[v_a,v_b]\). Note that within each \(H_i\), the positions that contain the value \(4\) are congruent modulo \(3\). As we consider \(H_1, H_2, H_3\), the positions of the value \(4\) cover every possible residue class modulo \(3\). Therefore, in one of the \(H_i\), which we will call \(H_r\), the positions of nodes with value \(4\) do not align with \(a\) or \(b\) modulo \(3\). For this particular \(r\), we have agreement between \(G\) and \(H_r\) at the endpoints of the crucial segment: \(\nodedata(v_a)=\nodedata_r(v_a)\) and \(\nodedata(v_b)=\nodedata_r(v_b)\). For example, if \(\nodedata(v_a)=3\) and \(\nodedata(v_b)=1\), then we have \(r=2\).

Let \(G'=(V,E,\nodedata')\) where:

  • \(\nodedata'(v_r)=\nodedata(v_r)\) if \(r < a\) or \(b<r\);

  • \(\nodedata'(v_r)=\nodedata_r(v_u)\) if \(a\leq u \leq b\).

Figure 9 (b) illustrates the process of merging \(G\) with \(H_r\) to obtain \(G'\).

We now claim that \((\rho_{G'},\mu) \in [\![{\mathfrak{p}_{\boldsymbol{3val}}}]\!]_{G'}\). Formally, we divide \(\rho_{G'}\) into \(\rho'_1,\dots,\rho'_m\) such that \(|\rho'_p| = |\rho_p|\) for all \(p=1,\dots,m\). Then we have \(\rho'_\iota = \tau^r_\iota\), \(\nodedata'(\rho'_\iota)=\nodedata_r(\tau^r_\iota)\), \(\rho'_p=\rho_p\), and \(\nodedata'(\rho'_{p'})=\nodedata(\rho_p)\) for each \(p \in \{1,\dots,m\}\setminus \{\iota\}\). Thus \((\rho'_p,\mu) \in [\![ \mathfrak{q}_p ]\!]_{G'}\) for \(p=1,\dots,m\), and \((\rho_{G'},\mu) \in [\![ \mathfrak{q}_1\dots \mathfrak{q}_m ]\!]_{G'} \subseteq [\![ \mathfrak{p}_{\boldsymbol{3val}} ]\!]_{G'}\). Since \(3 < |\rho'_\iota| < |V|-3\), we have \(\nodedata'(\rho_{G'})=4>3\). This leads to a contradiction.

The analysis for the case \(\theta \neq \top\) is similar. For instance, suppose \(x \equiv_{\mathrm{\small data} } y\) is a sub-formula of \(\theta\). Then, the node variables \(x\) and \(y\) do not appear in \(\mathfrak{q}_j = \mathfrak{r}^*\) since \(\mathrm{\small FV}(\mathfrak{r}^*)=\emptyset\). Therefore, the existence of \(x\) and \(y\) does not affect our construction of \(G'\). This reasoning applies to all variables mentioned in \(\theta\). Hence, Theorem 4 is proved. ◻

5 Unifying the Languages↩︎

A natural way to find a language subsuming all the languages in Figure 1 is to extend FO(ERDPQ) or FO\(^*(\equiv_{\mathrm{\small data} })\), which are shown to be the maximally expressive query languages within the diagram in the preceding section. Essentially, FO(ERDPQ) is a first-order logic. The extension of FO(ERDPQ) augmented with transitive closures then intuitively subsumes FO\(^*(\equiv_{\mathrm{\small data} })\). However, there is an issue we need to address. In FO(ERDPQ), there are two types of variables: node variables and path variables. Given a formula \(\phi(\boldsymbol{x},\boldsymbol{y})\), where \(\boldsymbol{x}\) and \(\boldsymbol{y}\) have the same arity, we cannot form \(\phi^*(\boldsymbol{x},\boldsymbol{y})\) without considering the types of variables in \(\boldsymbol{x}\) and \(\boldsymbol{y}\). For instance, it does not make sense to allow a formula \(\psi^*(x,\pi)\) from a formula \(\psi(x,\pi)\) where \(x\) is a node variable and \(\pi\) is a path variable. We address this by imposing the restriction that all the variables in vectors \(\boldsymbol{x}, \boldsymbol{y}\) of formula \(\phi\) are node variables.

Definition 7. The formulas of FO\(^*\)(ERDPQ) are defined inductively by the following rules:

  • FO(ERDPQ) formulas are FO\(^*\)(ERDPQ) formulas.

  • If \(\phi\) and \(\psi\) are FO\(^*\)(ERDPQ) formulas, then \(\neg\phi\), \(\phi \vee \psi\), \(\exists x. \phi\), and \(\exists \pi. \psi\) are also FO\(^*\)(ERDPQ) formulas, where \(x\) and \(\pi\) are node and path variables appearing free in \(\phi\) and \(\psi\), respectively.

  • If \(\phi(\boldsymbol{x},\boldsymbol{y})\) is an FO\(^*\)(ERDPQ) formula where \(\boldsymbol{x},\boldsymbol{y}\) are vectors of node variables with the same arity, then \(\phi^*(\boldsymbol{x},\boldsymbol{y})\) is an FO\(^*\)(ERDPQ) formula.

Since FO\(^*\)(ERDPQ) is an extension of FO(ERDPQ), to define the semantics, we simply have to illustrate the meaning of \(\phi^*(\boldsymbol{x},\boldsymbol{y})\), where \(\boldsymbol{x}, \boldsymbol{y}\) are vectors of node variables with the same arity. Given a data graph \(G\), we write \(G \models \phi^*(\boldsymbol{v},\boldsymbol{v}')\) if there exists a sequence of vectors of nodes \(\boldsymbol{v}_1=\boldsymbol{v},\dots,\boldsymbol{v}_n=\boldsymbol{v}'\) such that \(G \models \phi(\boldsymbol{v}_i,\boldsymbol{v}_{i+1})\) for \(1\leq i < n\).

By the definition of FO\(^*\)(ERDPQ), we have the following theorem:

Theorem 5. FO\(^*\)(ERDPQ) subsumes all languages from Figure 1.

Next, we show that FO\(^*\)(ERDPQ) is well-behaved.

Proposition 7. The FO\(^*\)(ERDPQ) query evaluation problem is decidable.

Proof. Let \(\phi(\boldsymbol{x},\boldsymbol{\pi})\) be an FO\(^*\)(ERDPQ) formula and \(G\) be a data graph. Without loss of generality, we assume that both \(\mathcal{D}_{\mathrm{\small id} },\mathcal{D}_{\mathrm{\small prop} } \subseteq \mathbb{N}\). Therefore, all data paths in \(G\) are in the set \(\mathbb{P}=\mathbb{N}^2\times (\Sigma \times \mathbb{N}^2)^*\). The FO\(^*\)(ERDPQ) query evaluation is decidable if and only if the emptiness problem for the set \(L_{\phi,G}=\{(\boldsymbol{v},\boldsymbol{\rho}) \mid G\models \phi(\boldsymbol{v},\boldsymbol{\rho})\}\) is decidable for arbitrary \(\phi\) and \(G\). We can decide emptiness using the following:

Claim 1. A 2-ary finite automaton \(A_{\phi,G}\) recognizing \(L_{\phi,G}\) can be effectively derived from \(\phi\) and \(G\).

In [3], it is shown that the statement holds when \(\phi\) is an FO(ERDPQ) formula and \(G\) is a graph without data; thus, all automata \(A\) appearing in \(\phi\) are finite automata. We explain how to adapt the proof for data graphs. Here is the idea: consider the formulas \(\phi = \exists \pi. \pi \in A\) and \(\phi' = \exists \pi. \neg(\pi \in A)\). Given a graph \(G\), we treat it as an automaton where all states are both initial and final. Recall that an NFA is a directed graph with an initial state and a set of final states. The automaton \(A_{\phi,G}\) is then the product automaton of \(A\) and \(G\). Consequently, \(G \models \phi\) if and only if \(A_{\phi,G}\) is non-empty. On the other hand, the automaton \(A_{\phi',G}\) for the formula \(\phi'\) is the product automaton of \(A_\neg\) and \(G\), where \(A_\neg\) is the automaton recognizing the complement of \(L(A)\). Moreover, \(G \models \phi'\) if and only if \(A_{\phi',G}\) is non-empty.

In [3], the authors give an inductive construction of \(A_{\phi,G}\). The main inductive step relies on closure of finite automata under complement. Although we consider data graphs, the automata \(A\) appearing in \(\phi\) are RDPAs, and RDPAs are not closed under complementation. However, once a data graph \(G\) is fixed, we can transform all RDPAs \(A\) into finite automata \(A'\) and derive an FO(ERDPQ) formula \(\phi'\) from \(\phi\) by replacing \(A\) with \(A'\) such that \(G \models \phi(\boldsymbol{v}, \boldsymbol{\rho})\) if and only if \(G \models \phi'(\boldsymbol{v}, \boldsymbol{\rho})\).

For instance, consider Example 1. There is no RDPA recognizing the complement of \(L(A_{\boldsymbol{repeat}})\) in \(\mathbb{P}\). However, once \(G\) is fixed, there are two finite subsets \(D^G_{\mathrm{\small id} },D^G_{\mathrm{\small prop} }\) of \(\mathbb{N}\) s.t. all data paths in \(G\) are over the union of \(D^G_{\mathrm{\small id} }\), \(D^G_{\mathrm{\small prop} }\), and \(\Sigma\). Thus there is a finite automaton \(A^{G}_{\boldsymbol{repeat}}\) s.t. for every data path \(\rho\) in \(G\), \(\rho \in L(A_{\boldsymbol{repeat}})\) if and only if \(\rho \in L(A^G_{\boldsymbol{repeat}})\). Hence, the claim is true when \(\phi\) is an FO(ERDPQ) formula, even when \(G\) is with data.

From Claim 1 Proposition 7 follows. ◻

Figure 2 summarizes the results of this section.

6 Multi-Path Walk Logic, an extension of WL↩︎

In the previous section, we extended FO(ERDPQ) to unify the prior languages. Based on Theorem 3, we have that FO(ERDPQ) subsumes WL, GPC, RDPQ, and FO(RDPQ). The query languages RDPQ for data graphs and FO(ERDPQ) for graphs without data are well-studied [2], [3]. In this section, we examine WL and derive an extension of WL, still subsumed by FO(ERDPQ).

Consider a path \(\rho = v_0a_1v_1 \dots v_n\). Node \(v_i\) is at the \(i^{th}\) position in \(\rho\) for \(i\in [0,n]\). In other words, every node in \(\rho\) corresponds to a number in \([0,n]\). In WL, we can compare nodes’ data values through their positions. Additionally, we can compare node positions as numbers if they are on the same path. However, comparison across different paths is not allowed. That is, we can assert \(l^\pi < n^\omega\) only if \(\pi = \omega\). We call the extension of WL obtained by lifting this limitation multi-path walk logic (MWL). Note that \(\ell^\pi < n^\omega\) is expressible in WL for different \(\pi, \omega\) if \(\ell\) and \(n\) refer to some given constants. In this section, we study the properties of MWL. We relate it to the languages investigated in the preceding sections and derive the decidability of query evaluation.

Recall from Section 4 that to complete the proof of Theorem 1, we need to show that WL is contained in FO(ERDPQ). We will show something stronger: that MWL, an extension of WL, is contained in FO(ERDPQ).

Proposition 8. MWL is strictly stronger than WL in expressive power.

Proof. It is known that the query “Are there two paths of different lengths from a given start node (represented as a singleton path) to a given target node (another singleton path)?” is not expressible in WL[4].

It is easy to see that this query is expressible as an MWL query \(Q^{\mathrm{\small diff} }_{\mathrm{\small len} }(\pi_1, \pi_2)\). Below we give the idea, omitting for brevity the requirement that \(\pi_1\) and \(\pi_2\) are singletons (and thus represent single nodes):

\[\exists \pi, \omega, \ell^\pi, m^\pi, s^\omega, t^\omega. (\boldsymbol{first}(\ell) \wedge \boldsymbol{first}(s) \wedge \boldsymbol{last}(m) \wedge \boldsymbol{last}(t)) \wedge \ell < m\] \[\wedge \phi_{begins}(\pi, \pi_1) \wedge \phi_{begins}(\omega, \pi_1) \wedge \phi_{ends}(\pi, \pi_2) \wedge \phi_{ends}(\omega, \pi_2),\] where: \[\boldsymbol{first}(\ell^\pi) := \forall {\ell}'^\pi. \, \ell^\pi \leq {\ell}'^\pi\] indicates that \(\ell^\pi\) is the first position in \(\pi\), and the formula \(\boldsymbol{last}(m^\pi)\), indicating that \(m^\pi\) is the last position in \(\pi\), can be defined analogously. The formula \(\phi_{begins}(\pi, \pi_1)\) states that paths \(\pi\) and \(\pi_1\) have the same initial point, while \(\phi_{ends}(\pi, \pi_1)\) states that paths have the same final point. All of these are easily expressible in \(MWL\).

As a result, we have that MWL is more powerful than WL in expressiveness. ◻

In Theorem 1, we claimed that WL is subsumed by FO(ERDPQ), which follows directly from the following result:

Proposition 9. MWL is subsumed by FO(ERDPQ).

Proof. We show that MWL formulas can be inductively translated into
FO(ERDPQ) formulas. First, consider MWL atoms:

\(E_a(x,y)\).

\(x < y\).

\(x \equiv_{\mathrm{\small id} } y\).

\(x \equiv_{\mathrm{\small data} } y\).

Consider two paths \(\rho\) and \(\tau\) and two node positions \(i^\rho\) and \(j^\tau\), Each of ([atom:E95a]) to ([atom:eqdata]) corresponds to a property of prefixes \(\rho'\) of \(\rho\) (for \(x\)) with length \(i^\rho\) and \(\tau'\) of \(\tau\) (for \(y\)) with length \(j^\tau\), as follows:

  1. \(|\tau'| = |\rho'| + 1\) and the last symbol from \(\Sigma\) along \(\tau'\) is \(a\).

  2. The length of \(\rho'\) is below the length of \(\tau'\).

  3. The last node along \(\rho'\) is the same as the last node along \(\tau'\).

  4. The last node’s data value (excluding the id) along \(\rho'\) is equal to the last node data value (excluding the id) along \(\tau'\).

Each of these relations (\(\ref{mod:E95a}'\)) through (\(\ref{mod:eqdata}'\)) can be defined by RDPA expressions. Note that in the case of ([atom:E95a]), variables \(x\) and \(y\) should belong to the same sort.

Note that in FO(ERDPQ), there are no position variables. So above, when we translate an MWL formula into an FO(ERDPQ) one, we map a position variable \(x\) associated to the path variable \(\pi\) to a path variable that is constrained to be a prefix of \(\pi\). The property that path \(x\) is a prefix of \(\pi\) can be expressed by the atomic FO(ERDPQ) formula \((x,\pi) \in A_{\mathrm{\small prefix}}\), where \(A_{\mathrm{\small prefix}}\) is the RDPA recognizing the pair \((\rho,\tau)\) of data paths where \(\rho\) is a prefix of \(\tau\). By using the RDPAs defined by (\(\ref{mod:E95a}'\))-(\(\ref{mod:eqdata}'\)), we can then recursively translate MWL formulas into their corresponding FO(ERDPQ) forms. ◻

On the other hand, MWL remains fundamentally a first-order language, unable to count the parity of a set. More specifically, we show that on \(\Sigma\)-words, MWL is subsumed by \(\mathrm{\small FO}[<, +, \{a\}_{a \in \Sigma}]\), a first-order logic where variables range over positions of words and the interpretations of \(<, +, \{a\}_{a \in \Sigma}\) are standard. Since checking whether the number of positions with a particular symbol \(a\) is even is not definable in \(\mathrm{\small FO}[<, +, \{a\}_{a \in \Sigma}]\) [20], it is also not definable in MWL.

Proposition 10. Over words (i.e. chain graphs) MWL is subsumed by
\(\mathrm{\small FO}[<,+,\{a\}_{a\in \Sigma}]\).

Proof. Given a chain data graph \(G\), we use \(w_G\) to denote the label of the chain.

Claim 2. For each MWL sentence \(\phi\), there is an \(\mathrm{\small FO}[<,+,\{a\}_{a\in \Sigma}]\) sentence \(\psi\) such that for every chain graph \(G\) with only ids as data, \(G \models \phi\) if and only if \(w_G \models \psi\).

Each path variable \(\pi\) in \(\phi\) is translated to two position variables \(\pi^{\boldsymbol{begin}}\) and \(\pi^{\boldsymbol{end}}\) in \(\psi\), representing the endpoints. Each position variable \(\ell\) in \(\phi\) is translated to a position variable \(x_\ell\) in \(\psi\). Additionally, we enforce the following conditions:

  • \(\pi^{\boldsymbol{begin}} \leq \pi^{\boldsymbol{end}}\), and the equality holds if and only if \(\pi\) is empty.

  • \(0 \leq x_\ell < \pi^{\boldsymbol{end}}-\pi^{\boldsymbol{begin}}\) if \(\ell\) is of sort \(\pi\), and \(\pi\) is not empty.

Then, we can translate MWL atomic formulas as follows:

  • \(E_a(\ell^\pi,m^\pi)\) is translated to \(a(x_\ell+\pi^{\boldsymbol{begin}})\wedge (x_m=x_\ell+1)\).

  • \(\ell < m\) is translated to \(x_\ell < x_m\).

  • \(\ell^\pi \equiv_{\mathrm{\small id} } m^\omega\) is translated to \(\ell + \pi^{\boldsymbol{begin}} = m + \omega^{\boldsymbol{begin}}\).

\(\mathrm{\small FO}[<,+,\{a\}_{a\in \Sigma}]\) is a first-order logic that incorporates existential quantification, disjunction, and negation, so the induction step for the corresponding MWL operators is straightforward. This completes the proof of Claim 2. ◻

Parity is a regular language, so it is in RDPQ and GPC. Thus:

Proposition 11. MWL does not subsume GPC or RDPQ.

As a result, we have:

Proposition 12. MWL is strictly subsumed by FO(ERDPQ).

7 Discussion↩︎

In this work, we have provided what we believe is a fairly complete picture of the landscape of expressiveness among query languages for data graphs. See Figure 2. We showed that the landscape of prior query languages lacked a single maximally expressive language. FO\(^*(\equiv_{\mathrm{\small data} })\), a first-order language augmented with transitive closure, and FO(ERDPQ) were maximally expressive query languages, but they are incomparable. To remedy this, we introduce FO\(^*\)(ERDPQ), which is FO(ERDPQ) extended with transitive closure. We show that it subsumes the prior languages.

Beyond exploring the landscape of query languages for data graphs, we examine the potential of WL, which only allows comparisons along a single path. We show that MWL, the extension of WL allowing multi-path comparisons, is more powerful than WL.

Although query evaluation of FO\(^*\)(ERDPQ) is decidable, we acknowledge that it is, in an important sense, too expressive, as the worst-case complexity of evaluation is extremely high, with no elementary bound in the size of the data. Identifying fragments with better evaluation complexity, as well as developing algorithmic techniques for implementing them, is a key piece of ongoing work.

Since RDPQ and its extensions, including FO\(^*\)(ERDPQ), manipulate data along the paths through register automata, we can easily extend these languages to include aggregates by replacing register automata with other automata such as register automata with linear arithmetic [25] and cost register automata [26]. This is another component of future work.

7.1 Other aspects of graph query languages↩︎

A number of aspects of graph querying have not been considered here.

Property graphs vs our data model. First, in our work we deal with a simplified data model. A commonly considered data model for graphs with data in recent years is the property graph model [14], and this data model is the basis for work on standards. In a property graph, both nodes and edges can have associated data. This data can be left unrestricted, including varying the number of attributes as well as their datatypes. Or it can be restricted by a schema. In our simplified data model, we require a fixed set of attributes for nodes, each with standard infinite datatypes, while we have a fixed set of edge relations, not associated with data values. While we believe that our results can be extended to the property graph model (e.g. by standard encoding of edge labels within node labels), we do not formalize this.

GPC. In this work, we have not considered several aspects of GPC, including inverse edges and trails.

Inverses. As mentioned earlier, inverse edges are not part of the definition of many of the classical graph query languages (including R(D)PQ and Walk Logic) and a sensible comparison would need to either include inverse edges in these languages, or consider the fragment of GPC without inverse edges. We have chosen the latter, to simplify our presentation. The former would also not change the subsumption of the query languages, and take us to languages like 2RPQ [9] and extension with data [8].

Trails. We now discuss trails, which restrict paths so that no edges are repeated. We do not consider trails in detail here. But we note that including trails does not change the subsumption of GPC in the other query languages that we considered in this paper. For example, we can assert that a path is a trail in Walk Logic as follows: \[\begin{align} \phi_{trail}(\pi) & := & \forall \ell^{\pi},m^{\pi}.\;\ell^{\pi} \neq m^{\pi} \wedge \ell^{\pi} \equiv_{\mathrm{\small id} } m^{\pi} \wedge \\ & & \bigvee_{a \in \Sigma} (E_a(\ell^{\pi},\ell^{\pi}+1) \wedge E_a(m^{\pi},m^{\pi}+1)) \rightarrow (\ell^{\pi}+1 \not\equiv_{\mathrm{\small id} } m^{\pi}+1). \end{align}\] Similarly, we can express trails in FO(ERDPQ) by using similar register automata as in Example 1, but with two registers instead of just one.

Joins. We have discussed GPCpattern queries here, which return paths. It is possible to extend these queries to return more complex objects, particularly tuple of paths. For two GPC queries \(Q\) and \(Q'\) with semantics \([\![{Q}]\!]_{G}\) and \([\![{Q'}]\!]_{G}\), respectively, we define their join as follows:

  • \([\![{Q, Q'}]\!]_{G} = \{((\bar{\rho}, \bar{\rho}'), \mu \cup \mu') \mid (\bar{\rho}, \mu) \in [\![{Q}]\!]_{G}, (\bar{\rho}', \mu') \in [\![{Q'}]\!]_{G}\), and the union \(\mu\cup\mu' \text{ is defined}\}\).

Thus a join of two path patterns returns a pair of paths. We can close the syntax of GPC under join, allowing us to return \(k\)-tuples for any \(k\). In our paper we compare languages by considering the graph queries that return Booleans which they can express (Definition 2 in Section 2). Thus, since we do not consider queries that return tuples, and we cannot use joins to produce new paths or Booleans, the presence or absence of joins has no impact on our results.

References↩︎

[1]
A. O. Mendelzon and P. T. Wood, “Finding regular simple paths in graph databases,” SIAM J. Comput., vol. 24, no. 6, pp. 1235–1258, 1995.
[2]
L. Libkin, W. Martens, and D. Vrgoc, “Querying graphs with data,” J. ACM, vol. 63, no. 2, pp. 14:1–14:53, 2016.
[3]
P. Barceló, L. Libkin, A. W. Lin, and P. T. Wood, “Expressive languages for path queries over graph-structured data,” ACM Trans. Database Syst., vol. 37, no. 4, 2012.
[4]
J. Hellings, B. Kuijpers, J. Van den Bussche, and X. Zhang, “Walk logic as a framework for path query languages on graph databases,” in ICDT, 2013.
[5]
P. Barceló, G. Fontaine, and A. W. Lin, “Expressive path queries on graphs with data,” Log. Methods Comput. Sci., vol. 11, no. 4, 2015.
[6]
N. Immerman, Descriptive complexity. Springer, 1999.
[7]
L. Libkin and D. Vrgoc, “Regular path queries on graphs with data,” in ICDT, 2012.
[8]
D. Figueira, A. Jez, and A. W. Lin, “Data path queries over embedded graph databases,” in PODS, 2022.
[9]
D. Calvanese, G. D. Giacomo, M. Lenzerini, and M. Y. Vardi, “Containment of conjunctive regular path queries with inverse,” in KR, 2000.
[10]
A. Deutsch and V. Tannen, “Optimization properties for classes of conjunctive regular path queries,” in Database programming languages, 2001.
[11]
D. Florescu, A. Y. Levy, and D. Suciu, “Query containment for conjunctive queries with regular expressions,” in PODS, 1998.
[12]
M. P. Consens and A. O. Mendelzon, GraphLog: a Visual Formalism for Real Life Recursion,” in PODS, 1990.
[13]
J. L. Reutter, M. Romero, and M. Y. Vardi, “Regular queries on graph databases,” Theory Comput. Syst., vol. 61, no. 1, pp. 31–83, 2017.
[14]
N. Francis et al., GPC: A pattern calculus for property graphs,” in PODS, 2023.
[15]
N. Francis et al., “A researcher’s digest of GQL (invited talk),” in ICDT, 2023.
[16]
A. Deutsch et al., Graph Pattern Matching in GQL and SQL/PGQ,” in SIGMOD, 2022.
[17]
R. Angles, M. Arenas, P. Barceló, A. Hogan, J. L. Reutter, and D. Vrgoc, “Foundations of modern query languages for graph databases,” ACM Comput. Surv., vol. 50, no. 5, pp. 68:1–68:40, 2017.
[18]
M. Kaminski and N. Francez, “Finite-memory automata,” Theoretical Computer Science, vol. 134, no. 2, pp. 329–363, 1994.
[19]
A. Gheerbrant, L. Libkin, L. Peterfreund, and A. Rogova, GQL and SQL/PGQ: Theoretical Models and Expressive Power.” 2024.
[20]
L. Libkin, Elements of finite model theory. Springer, 2004.
[21]
J. L. Reutter, M. Romero, and M. Y. Vardi, “Regular queries on graph databases,” Theor. Comp. Sys., pp. 31–83, Jul. 2017.
[22]
E. Grädel, “On transitive closure logic,” in CSL, 1992.
[23]
N. Immerman, “Nondeterministic space is closed under complementation,” SIAM Journal on Computing, vol. 17, no. 5, pp. 935–938, 1988.
[24]
W. Martens, M. Niewerth, and T. Popp, “A trichotomy for regular trail queries,” Log. Methods Comput. Sci., vol. 19, no. 4, 2023, doi: 10.46298/LMCS-19(4:20)2023.
[25]
Y.-F. Chen, O. Lengál, T. Tan, and Z. Wu, “Register automata with linear arithmetic,” in LICS, 2017.
[26]
R. Alur, L. D’Antoni, J. Deshmukh, M. Raghothaman, and Y. Yuan, “Regular functions and cost register automata,” in LICS, 2013.

  1. In the literature, FO(ERDPQ) for graphs without data is known as ECRPQ\(^\neg\) [3].↩︎

  2. In the literature, FO(RDPQ) for graphs without data is known as CRPQ\(^\neg\) [3].↩︎

  3. The definitions of GPC provided in [14] and [19] are not identical. For instance, the pattern \(((x) + ()) \rightarrow (y)\) is valid in [14] but not in [19], because the node variable \(x\) appears in the node sub-pattern \((x)\) but not in the sub-pattern \(()\). In general, in [19] the use of variables is more complex. In this paper, we adopt the simpler definitions from [14].↩︎

  4. In some prior literature [20], transitive closure operators are defined over formulas of the form \(\phi(\mathbf{x}, \mathbf{y}, \mathbf{z})\), which involve three tuples of variables: \(\mathbf{x}\), \(\mathbf{y}\), and \(\mathbf{z}\), where \(\mathbf{z}\) represents free variables in \(\phi^*(\mathbf{x}, \mathbf{y}, \mathbf{z})\). These two variants of the language FO\(^*\) are equivalent in expressiveness. Specifically, \(\phi^*(\mathbf{x}, \mathbf{y}, \mathbf{z})\) from the alternative variant can be translated into the equivalent formula \(\exists \mathbf{z}'. {\phi'}^*(\mathbf{x}', \mathbf{y}')\) of the variant used in this paper, where \(\mathbf{x}' = (\mathbf{x}, \mathbf{z})\), \(\mathbf{y}' = (\mathbf{y}, \mathbf{z}')\), and \(\phi'(\mathbf{x}', \mathbf{y}') = \phi(\mathbf{x}, \mathbf{y}, \mathbf{z}) \wedge \mathbf{z} = \mathbf{z}'\).↩︎