Complexity of Evaluating GQL Queries
Abstract
GQL has recently emerged as the standard query language over graph databases, particularly, property graphs. Indeed, this is analogous to the role of SQL for relational databases. Unlike SQL, however, fundamental problems regarding GQL are still unsolved, most notably the complexity of query evaluation. In this paper we provide a complete solution to this problem for the core fragment of GQL and for its extension with path restrictors. In particular, we show that the data complexity of these fragments is -complete in general, and drops to NL-complete when restrictors are disallowed. Using techniques from embedded finite model theory, we show that this is true, even when the queries use data from infinite concrete domains such as real numbers with arithmetic. In proving these results, we establish and exploit tight connections between GQL and query languages over relational databases, especially extensions of relational calculus with transitive closure operators and fragments of second-order logic.
Keywords and phrases:
Graph query languages, GQL, complexity, database theoryFunding:
Diego Figueira: Partially supported by ANR grants INTENDED (ANR-19-CHIA-0014) and EXPAND (ANR-25-CE23-1215).Copyright and License:
2012 ACM Subject Classification:
Theory of computation Database theoryAcknowledgements:
We thank Michael Benedikt, Leonid Libkin and anonymous reviewers for valuable feedback.Editors:
Balder ten Cate and Maurice FunkSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl – Leibniz-Zentrum für Informatik
1 Introduction
Property-graph databases and related knowledge-graph applications gained significant popularity in the last decades, with numerous application domains, including social networks, semantic web, biological and ecological databases, and more. On the practical side, there has been rapid growth in the development of commercial graph database systems, including systems such as Neo4j, Oracle, IBM, TigerGraph, and JanusGraph. This wealth of available systems has also motivated the recent and still ongoing standardization effort of graph data models (in particular, property graphs) and query languages (in particular, GQL), which has been undertaken by several working groups consisting of research leaders from academia and industry (see, e.g., [20, 11]).
GQL [10] was developed to fill in the role of SQL (i.e., as a yardstick query language) for property graphs. Unlike SQL, whose complexity landscape has been mapped for decades, the rigorous study of GQL is only now taking shape. A first informal description of the language appeared in [11], followed by a formal treatment of its pattern-matching layer in [14]. The relational-algebra layer was analyzed soon after in [15], and a study of expressiveness subsequently distilled a streamlined theoretical core [16]. Consequently, even the most basic issue – that of data complexity (query evaluation with only the database as input) – remains largely open. Hitherto, we know only that the complexity of enumerating query outputs is in PSpace [14], and we have an NP-hard lower bound easily derivable from [27]. In this paper, we identify the precise data complexity of the core fragment of GQL for the first time.
GQL on property graphs in a nutshell.
A property graph [2] is a graph whose nodes and edges are labeled, often to represent their type or role in the graph, and are enriched with additional attributes called properties. These properties are stored in a key-value format, enabling a flexible and detailed representation of both entities and their relationships. Figure 1 depicts a property graph of bike lanes and roads between towns and crossroads. It has two node types indicated by their labels – Town and Crossroad, and two edge types, namely Bike-lane and Road. Towns have properties like names, and coordinates specifying their exact location, Bike-lanes and Roads have length and possibly toll.
GQL queries are essentially SQL queries over relations of nodes, edges, and properties, extracted using patterns that capture both data and graph topology (i.e., paths).
Example 1.1.
To find all pairs of towns accessible by a bike lane we apply the pattern
on . The output is a binary relation with attributes , containing, among others, the pair . To find pairs of places accessible by one or more bike-lanes, we can incorporate unbounded repetition of edges:
| (1) |
Here, the output is the transitive closure of the previous output. We can refine matched patterns by appending a Boolean filter, e.g., returning every town reachable by bicycle from Leerdam with one or more bike-lanes:
The condition filters the matches to paths starting at Leerdam. To prevent re-using the same bike-lane or revisiting the same place we prefix the pattern with an appropriate restrictor: we use simple to forbid repeating a node, or trail to forbid re-using an edge. For instance, suppose we want to organize a day trip from Meekerk to Leerdam using at least two bike lanes without passing through the same town twice. In this case, we would use the pattern
Here, the simple restrictor enforces the non-repetition of nodes.
In GQL, SQL-like-queries are applied to the relations produced by pattern matching over the graph. To query a round-trip, out by bicycle on bike lanes and back by car on roads, we combine the pattern in (1), namely , with the pattern
via that joins the two relations on the conjunction of equalities.
In this paper, we study the query evaluation problem of GQL: given a GQL query , a property graph , and a candidate tuple , determine whether belongs to the result of evaluating over . To study the complexity of the problem, we use data complexity [30], which is the standard complexity measure for query evaluation problems. That is, since we typically deal with queries of “small size” and “large” databases, we consider the query component as fixed (i.e., not part of the input) and only measure the computational complexity in terms of the data (i.e., ).
Contributions.
Our analysis is centered on the core fragment of GQL as formalized in [16], which captures the essential pattern-matching constructs and their combination via relational algebra. In addition, we study an extension of this core with restrictors (e.g., simple, trail, shortest), which are part of practical GQL but are not included in the core fragment. Our complexity results distinguish explicitly between these two settings.
Theorem 1.2.
The data complexity of GQL extended with path restrictors is -complete. The data complexity of GQL without restrictors improves to NL-complete.
That is, GQL query evaluation is representative of problems that can be solved in polynomial time with logarithmically many calls to NP oracles. Note that lies in the second-level of polynomial hierarchy (which is in PSpace), and subsumes the entire boolean hierarchy (which is a boolean closure of NP-complete problems). The class includes some natural problems related to optimization (e.g., [31, 29]) and logical reasoning (e.g., [17, 18]). In the absence of path restrictors, the NP-hardness from [27] on querying simple paths or trails of even length no longer applies. Indeed, we show that the complexity in this case drops to NL-complete.
Our proof technique for the upper bound complexities is via a relational embedding of GQL to extensions of first-order logic over relational structures, namely, either with transitive closure operator, or with existential second-order definable relational views. This relational viewpoint of property graphs yields several benefits, including applicability of techniques from embedded finite model theory (see [24, Chapter 13] and [5]) to derive the same data complexity of GQL in the presence of numeric data and arithmetic constraints (e.g. constraints from Tarski’s theory of real field). In particular, the framework essentially allows unrestricted quantification over an infinite domain such as the set of real numbers thereby allowing us to define interesting queries over spatial databases, e.g., there is a path from to that uses edges that lie on a straight-line (see [24, Chapter13]). We summarize this in the following corollary:
Corollary 1.3.
Let be a structure satisfying the property of Restricted Quantifier Collapse (RQC), in particular Linear Real Arithmetic (LRA), Linear Integer Arithmetic (LIA), or Real-ordered Fields (ROF). Then, the data complexity of GQL with restrictors extended with unrestricted quantification over is -complete and, without restrictors, NL-complete.
Related Work.
The study of graph databases in database theory can be traced back to the work of Mendelzon and Wood [28] on Regular Path Queries (RPQ), where they popularized the data model of edge-labeled graphs. This has been the standard graph data model for a long time in database theory [22, 9, 28, 4, 13, 21]. Since then the area has undergone several paradigm shifts on the notion of a “graph data model”, including data graphs [25] and property graphs [2, 11, 14]. Data graphs were introduced in [26, 25] owing to the lack of a treatment of “data” (properties associated with nodes and edges, like “id”, “name” and “age” of a person) in the data model of edge-labeled graphs. Many classical query languages (like RPQ) have been extended to also incorporate such data [2, 25, 3, 12], e.g., in the query language RDPQ (Regular Data Path Queries). Data graphs still do not capture the graph model that has been adopted by practitioners, e.g., the “schemaless” nature of a graph. The property graph data model [2, 11] has been proposed to address such deficiencies.
Unlike the case of GQL, the precise data complexity of most query languages for edge-labeled graphs (e.g., RPQs and extensions) and data graphs (e.g., RDPQs) is known to be NL-complete. For example, see [28, 4, 13, 21, 22, 25]. These results were also recently extended to the case of numeric and string data domains and operations [12]. The reason for the low computational complexity in these settings is analogous to our NL upper bound for GQL without restrictors. By contrast, adding path restrictors is what enables NP-hardness (cf. [27]). Incidentally, our technique of relational embedding can be shown to provide a simpler proof of the NL upper bound in [12]. There are relatively few results on the expressivity landscape of GQL. Initial investigations have been conducted in [16, 8].
Organization.
Section 2 recalls preliminaries on property graphs, GQL, and general logic. Section 3 presents our main complexity results for GQL. In Section 4, we extend the analysis to incorporate data values and domain-specific operators. Section 5 highlights the benefits of analyzing graph query languages from a logical perspective. We conclude in Section 6. Some details are deferred to the full version.
2 Preliminaries: Property Graphs, GQL and Logic
We follow the standard definition of property graph data model, and the formal syntax and semantics of GQL [16, 15, 14]. We also introduce some classical definitions from logic.
Property Graphs.
We assume pairwise disjoint countable infinite sets of nodes , (directed) edges , labels , property values and keys . A property graph is a tuple where , are finite sets of node and edge identifiers, respectively, and are functions that specify the source and target, respectively, of an edge, is a partial function that maps a given edge or node and a key to the corresponding property value, if defined, and specifies the labels attached to nodes and edges. We omit the superscript when it is clear from the context.
2.1 GQL Syntax
We follow the core GQL definition [16]. Core GQL deliberately omits several features present in the full GQL language. In particular, patterns are designed to return relations over an explicitly specified set of variables, ensuring that all query results are in first normal form: relations contain no null values, and all attribute values are atomic (in particular, paths or lists are not first-class values).
Let Vars be an infinite set of variables. Path patterns are defined via mutual recursion along with their free variables . Pattern matching is the key component of GQL. Path patterns are defined recursively as follows:
where
-
and ;
-
variables in node patterns , and edge patterns and are optional,
-
is a conditional pattern, where conditions are given by 222This condition checks whether is labeled with . For convenience, we often use the shorthand , which incorporates the label directly into the node pattern. where , , and ;
The free variables of path patterns are defined as follows:
We then define output patterns as where
-
is sequence of restrictors such that parts within squared brackets are optional, and
-
is a (possibly empty) finite sequence of elements of the form and where and .
Intuitively, imposes constraints on the matched paths, and specifies which variables and properties are returned (i.e., projected) in the output relation.
Notice that while [16] omitted restrictors from the language, we include them and give them a precise semantics that is consistent with the standard [15], extending the core fragment and aligning the formal model more closely with the practical language.
Finally, we associate every output pattern with a relation symbol . GQL queries are then defined as the closure of these symbols under the standard operators of relational algebra.444Notice that while [16] uses a linear form of relational algebra, we use the more convenient standard relational algebra as the equivalence is already established in that work. Formally,
for every output pattern where is a vector of Vars and with . Note that the operators used here are the standard operators of relational algebra, namely union , Cartesian product , difference , projection , and selection , with the usual semantics over relations (see, e.g., [1]). The schema of a GQL query is defined inductively. For the base case, we set For composite queries the schema is defined in the standard way (see, e.g., [1]).
2.2 GQL Semantics
The semantics of output patterns is defined in terms of the semantics of path patterns. We therefore begin by defining the latter.
A path in a property graph is an alternating sequence of nodes and edges that start and end with a node, that is, where , and . Each edge must connect the adjacent nodes, meaning either (1) and or (2) and .
The semantics of a path pattern over a property graph is defined as a set of pairs , where:
-
is a path in , and
-
is a partial assignment that is defined on .
We define , and . For two paths , we write to indicate that . In this case, is the concatenation of the paths. For partial mappings , we use to denote that for every , it holds that and define if , and otherwise. We represent mappings as sets of elements , where . (If then we represent by .)
The semantics of path patterns on a graph is defined in Figure 2. We emphasize that the semantics of repetition deliberately ignores variable inside the repeated subpattern, following [16]. This restriction ensures that all query results are in first normal form, avoiding list-valued outputs that are permitted in the full GQL language but excluded from the core fragment.
For the semantics of output patterns , we first define the intermediate semantics of path patterns preceded by restrictors, iterating through possible cases. For , we define where if and only if is a simple path or a trail, respectively. Next, for of the form (with the restrictors being optional) we define
where is the minimal length among paths that match with the same endpoints as , or, more formally,
Let be a (possibly empty) finite sequence of elements of the form and where and . We say that a mapping is compatible with if for each , is defined on , and for each , is defined on and is defined. In this case, we define as the projection of on :
Finally, we define . Note that the semantics of an output pattern can be interpreted as a relation as it is a set of partial mappings that share the same domain. Once this is fixed, the semantics of an entire GQL query is obtained exactly as in standard relational algebra (see, e.g., [1]).
2.3 First and Second-Order Logic
We assume basic familiarity with mathematical logic (e.g., [24]). In the sequel, we deal only with finite relational structures.
Relational structures.
We fix disjoint countably infinite sets of relation names Rel, constant names Const, and variables Vars. Every relation name is associated with a positive integer, namely its arity . We write to make the arity explicit. A vocabulary is a finite set . A relation is a finite set of tuples in . A -structure maps every to a finite relation . Its active domain is . Property graphs can naturally be viewed as -structures over the vocabulary consisting of the relation names and interpreted accordingly.
First-order logic.
FO is defined in the usual way over -structures. That is, terms are defined by where , and formulas . We use the standard as syntactic sugar.
For a formula , we write to explicitly indicate that are its free variables. An -valuation is a function mapping variables of to elements of the active domain of a relational structure . We write for the truth value or of under the valuation . We denote by the set of valuations that satisfy in , that is, valuations for which .
Transitive closure.
First-order logic extended with the transitive-closure operator is denoted FO[TC]. Transitive-closure formulas are of the form , where are the free variables. Such a formula is true in a structure under a valuation iff there exists a finite sequence of tuples with and , such that for every , , where is the valuation mapping , and to , and respectively.
Second-order logic.
SO (second-order logic) extends FO by allowing quantification not only over individual elements of the active domain, but also over relation symbols of arbitrary arity. Concretely, SO formulas may include subformulas of the form
where is a relation variable and is an FO formula in which may occur as .
The fragment ESO consists of those SO formulas in which all second-order quantifiers are existentially quantified. Note that negation in ESO is permitted only within the first-order component and cannot apply to second-order quantifiers.
3 Complexity Bounds for GQL Queries
We now use standard logics to capture core GQL with and without restrictors, turning syntactic translations into complexity bounds.
3.1 Restrictor-Free GQL Queries and FO[TC]
We call a GQL query restrictor-free if no output pattern occurring in it is prefixed by a restrictor.
Lemma 3.1.
For every restrictor-free GQL query there is an FO[TC] formula where such that for every graph .
Proof Sketch.
The proof translates a restrictor-free GQL query into an FO[TC] formula whose answer relation coincides with the query result. The construction involves three main steps:
(1) Path patterns.
For every path pattern we build an FO[TC] formula whose free variables are the start node and end node of the matched path, and the pattern variables . The translation is recursive:
-
Atomic patterns use predicates such as for node patterns, and combination of , , for edge patterns, depending on their direction.
-
Union and concatenation. translates to disjunction, and for we use an existentially quantified concatenation node.
-
Filters. A condition becomes , where each atomic condition (, , etc.) is rendered, in turn, into FO.
-
Kleene bounds. Bounded repetition unrolls into a finite disjunction of FO formula; unbounded repetition is captured with a transitive closure operator applied to .
(2) Output patterns.
An output pattern returns a tuple of node/edge IDs and property values. To construct the corresponding output pattern formula, we start from and, for each element in the return list , add a first-order constraint that links the output variable to the witness variables introduced by .
(3) Full queries.
A restrictor-free GQL query is just a relational-algebra expression over the auxiliary relations defined in step (2). Because every RA operator is FO-definable, an easy induction pushes all definitions inside and yields a single FO[TC] sentence whose free variables .
Example 3.2.
Combining Lemma 3.1 with the known fact that the data complexity of the evaluation problem for FO[TC] is NL-complete [24] gives an NL upper bound. A matching lower bound via a reduction from graph reachability yields the following tight bound.
Theorem 3.3.
The data complexity of the evaluation problem for restrictor-free GQL queries is NL-complete.
Having settled the complexity of restrictor-free queries, we now turn to queries with restrictors.
3.2 GQL Queries and FO[ESO]
We define FO[ESO] as first-order logic extended with ESO-based first-order views. Specifically, we call an ESO formula whose free variables are first-order variables an ESO FO-view, and define FO[ESO] as the set of first-order formulas that may include such views as sub-formulas.
Lemma 3.4.
For every GQL query with restrictors there is an FO[ESO] formula with such that if and only if for every graph .
Proof Sketch.
The proof translates a GQL query with restrictors into a FO[ESO] formula whose emptiness coincides with the query’s emptiness.
(1) Encoding a restricted path.
We encode a path with a ternary relation containing the triples . For the simple restrictor we use the FO test . To define it we use the following auxiliary shortcuts
The conjunction of the following requirements gives us :
-
(i)
There is exactly one source
-
(ii)
There is exactly one target
-
(iii)
Every internal node (i.e., neither the source nor the target) has precisely one incomig edge and one outgoing edge where and is defined symmetrically.
For the trail restrictor, we drop condition (iii) and instead require that each edge has at most one successor edge and one predecessor edge. To express this, we define a successor formula over pairs of edges.
and with that at hand, we define
For the shortest restrictor, no special handling is needed, as the emptiness of a pattern is preserved when this restrictor is applied.
(2) Changing the atomic patterns.
For every path pattern we build, by structural induction, an ESO formula with that is true iff encodes a restricted path matching . Only the base cases differ from the FO[TC] construction of Lemma 3.1, for example:
with and as reconstructed above from . A restricted path pattern is therefore represented by an ESO sentence with free variables .
(3) From output patterns to queries.
Every output pattern introduces a relation symbol and the ESO definition obtained in step 2. A complete GQL query is an RA expression over these symbols. Because each RA operator (projection, join, union, difference) is FO-definable, substituting the ESO definitions and pushing the FO connectives outward yields an FO[ESO] formula satisfying for every graph .
Example 3.5.
Continuing Example 3.2, if the pattern is preceded by the restrictor simple then the translation is where is obtained from by replacing with derived from (as detailed in the proof sketch of Lemma 3.4).
The complexity class consists of decision problems solvable in deterministic polynomial time using logarithmically many adaptive queries to an NP oracle [31, 29]. Equivalently, it can be defined as the class of problems solvable by first generating polynomially many NP oracle queries, performing all of them in parallel (non-adaptively), and then computing the final answer from the oracle’s yes/no responses.
Corollary 3.6.
The data complexity of the evaluation problem for GQL queries is in .
Proof Sketch.
Let be a GQL query and let be the FO[ESO] formula guaranteed in Lemma 3.4. Let us denote by the first-order ESO views. Assume that each has arity , and let us denote .
-
1.
For every and every tuple ask the NP oracles whether . The total number of queries is .
-
2.
Issue this batch of polynomially many queries in parallel to obtain the complete satisfying assignments for all of the s.
-
3.
Evaluate the remaining first-order part of deterministically in time.
Notice that the algorithm makes polynomially many non-adaptive NP calls.
Is the bound tight?
To investigate this, we introduce the Odd-Index problem. In its original form [31, Theorem 5.2], the problem asks: given a list of Boolean formulas in 3-CNF, is there an odd index such that:
-
all formulas are satisfiable, and
-
all formulas are unsatisfiable?
This problem can be generalized by replacing the 3-CNF satisfiability with any NP-hard decision problem. In our context we replace it with simple-path (trail) even-length reachability in graphs. Formally, we define the following problem:
Given a list , where each is a graph and are designated nodes, determine whether there exists an odd index such that:
for all , there is a simple path (trail) of even length from to in , and
for all , there is no such simple path (trail) of even length.
We reduce this problem to the evaluation of a GQL query, thereby establishing the following lower bound.
Lemma 3.7.
The evaluation problem for GQL queries with restrictors is -hard.
Theorem 3.8.
The evaluation problem for GQL queries with restrictors is -complete.
This completes the -completeness characterization for GQL queries with restrictors.
3.3 Proof of Lemma 3.7: Lower Bound
We give a log-space reduction from the -complete Odd-Index problem to the evaluation of a GQL query that uses the simple restrictor. (A similar construction works with trail.)
Query.
We define the query where
Graph construction.
Assume the input list is pairwise disjoint, and each carries labels , respectively. We build , depicted in Figure 3, as follows:
-
1.
Lower layer.
-
(a)
For every add a fresh copy .
-
(b)
Add a fresh node labeled by , and an edge .
-
(c)
For each add an edge .
-
(d)
For each odd add a node labeled , and an edge .
-
(a)
-
2.
Upper layer.
-
(a)
For every add a fresh copy with nodes (replacing ).
-
(b)
Add an edge for every odd and .
-
(c)
Add a fresh node labeled by , and edges for all .
-
(a)
Label summary: all sources carry ; all targets carry ; each (odd ) carries .
Notice that construction is first-order definable and uses only logarithmic space.
Correctness.
To prove correctness, we investigate both parts and of the query in the following lemmas.
Lemma 3.9.
evaluated on returns exactly those nodes such that for every , the graph contains a simple path of even-length from to .
Proof.
Assume first that evaluated on returns a node . Due to ’s definition, there must exist in a simple path of the form
where (1) ; (2) is the unique fresh node labeled created in Step 1(b), (3) is the source of in the the lower layer; (4) each consists of an even number of edges; and (5) is labeled .
Notice that the only -labelled nodes are . Let us denote for the corresponding odd . By construction is attached to , hence .
Due to the structure of and to the labels specified in , the matched path is forced to traverse, in order,
employing the connecting edges for . As the overall walk is simple, in each lower copy the sub-path from to is itself simple. Consequently, for all , it holds that contains a simple path of even length from to .
Conversely, suppose there is an odd index such that every has a simple even-length path . Concatenate those paths with the connecting edges
The result is a simple path that matches , hence is returned.
Lemma 3.10.
evaluated on returns exactly those nodes such that, for every , the graph contains no simple path of even-length from to .
Proof.
Recall We refer to the patterns before and after , respectively, as left and right parts.
Left part.
The projection simply returns every -labelled vertex, i.e. the odd-indexed nodes .
Right part.
A node is matched to the right part if there is a path
exists in . where is of even length, The edge is the only occurrence of two consecutive -labelled nodes, so any matched path must enter the upper copy at its source and reach without repeating nodes. Because each is disjoint from the rest of the graph, such a sub-path exists iff the original graph contains a simple path of even length .
The difference of the left part and the right part
Due to the above, is outputted by whenever there is no even-length simple path in from to for every .
Combining Claims 1 and 2.
Claim 1 shows that returns precisely those markers for which every graph with admits a simple even-length path. Claim 2 shows that returns exactly those same markers for which no graph with admits such a path. Since our full query takes the intersection of these two results, it will be nonempty exactly when there exists some index satisfying both “all earlier graphs succeed” and “all later graphs fail”. But this is exactly the odd-index condition required by the source problem, which completes the correctness argument.
Exactly the same reduction goes through if we replace the simple restrictor by trail, yielding identical bound.
4 Incorporating Domain-Specific Operators
Logics considered so far let us combine the topology of a graph with simple data tests restricted to equality. Yet, practical languages operate over concrete domains equipped with a rich set of comparisons and functions.
To add such data operations without worsening complexity, we rely on classical results from the study of constraint databases [23] and embedded finite model theory [19, 6]. These results allow us to extend GQL with typed data operations while preserving data-complexity bounds.
The underlying idea is to “embed” a finite database inside an infinite structure with a decidable first-order theory. Queries can then use formulas over to express operations on domain values. Three notable examples [19, Chapter 5]) include:
-
The Linear Integer Arithmetic (LIA) structure – linear arithmetic over integers.
-
The Linear Real Arithmetic (LRA) structure – linear arithmetic over reals.
-
The Real Ordered Field (ROF) structure – real closed field (Tarski’s structure).
We focus on these numeric structures, though similar approaches exist for other domains like strings (e.g., reducts of the universal automatic structure [7]).
4.1 Embedded Finite Model Framework
Embedded finite structures.
An element from the domain of is definable over if there exists a -formula such that for each we have iff . For example, over , the definable elements are exactly the rationals. An -embedded finite relational structure over is a finite relational structure whose domain consists of such definable elements.
Logics with active–domain quantifiers.
A hybrid transitive-closure operator
is defined like the standard TC except that every intermediate tuple must lie in the active domain. We denote by FO[HTC] first-order logic extended with hybrid TC operators.
Active-domain restrictions also apply to second-order quantifiers. In HSO for hybrid second-order logic, relation variables range only over the active domain. We write HESO for its existential fragment.
For any , let denote the logic extended with predicates from an infinite structure , enriched with active-domain quantifiers and . A formula is active-domain if all quantifiers are of this form.
Restricted-quantifier collapses.
Over the arithmetic domains introduced above, quantifiers can be restricted to the active domain without losing expressive power:
Proposition 4.1 (Restricted-quantifier collapse [6]).
Let . Over -embedded structures:
-
(i)
Every -formula is equivalent to an active-domain -formula, and its data complexity lies in NL.
-
(ii)
Every -formula is equivalent to an active-domain -formula, and its data complexity lies in NP.
These collapses allow us enriching GQL with operations from while keeping the usual bounds.
4.2 Extending GQL with Data Types
We fix an infinite structure . and define GQL queries with an -data type. To this end, we first extend the definition of terms to -terms defined as follows:
where is an -definable constant, is a variable ranging over the domain of , is an -ary function name in the vocabulary of , , , and every is an -term. We also extend the definition of conditions to -conditions by adding where is an -ary relation name in the vocabulary of , and every is an -term. The semantics of extends by interpreting and “inside” .
Example 4.2.
Continuing Example 3.2, suppose we also want to enforce that the Manhattan distance between the towns is below a fixed . We can add the filter
which requires access to built-in arithmetic relations for absolute value, addition, subtraction, and comparison .
Using Proposition 4.1, the upper bounds extend to GQL queries with data types.
Theorem 4.3.
For every , the data complexity of the evaluation problem of a Boolean GQL query with an -data type is
-
NL-complete if is restrictor-free;
-
-complete otherwise.
GQL can support multiple data types (e.g., strings, numbers) using disjoint infinite structures with restricted quantifier collapse, while preserving data complexity as long as typed variables range over disjoint domains.
5 Logical Graph Querying Benefits
This section advocates viewing graph query languages through a logical lens. Embedding GQL into formal logic simplifies reasoning, clarifies expressiveness, and preserves complexity bounds. We showcase several examples unlocked by this embedding, including schema-level queries and extensions beyond plain GQL.
Meta-Querying.
GQL does not support quantification over properties or labels, limiting its ability to express meta-level queries such as schema checks or property comparisons. For instance, to return pairs of nodes that hold exactly the same data, we have:
where is used as a shorthand for bidirectional implication. Similarly, to ensure that all bike lanes in Example 3.2 are toll-free, we can replace with
where verifies the condition holds. While GQL cannot test for the absence of a toll property, this enriched query remains in NL.
Beyond GQL’s Expressiveness.
GQL is limited in checking conditions on unbounded edge traversals, for instance, checking for decreasing values on edges along a path [16]. The next query expresses this: outputs towns accessible by bike lanes with decreasing lengths:
where
where checks if and are adjacent edges with decreasing lengths:
Here we compute the transitive closure over edges rather than nodes, as it is in GQL’s iteration.
6 Conclusion
In this paper, we have answered a fundamental questions regarding evaluating GQL queries, i.e., its data complexity. Although its complexity () is higher than that of its SQL counterpart ( polynomial-time), we have shown that the restrictor-free fragment is in NL. We have shown that our results extend to settings with data.
Future Work.
We believe that our logical perspectives on graph databases could further advance the study of graph databases. As we have shown, not only do they generalize GQL in expressivity (e.g., meta-querying, cf. Section 5), they also allow us to employ classical techniques from relational structures (e.g., embedded finite model theory).
One interesting future avenue concerns the extension of GQL with aggregation over paths (by, e.g., summing, counting, averaging, over a given path). While aggregation results are available for relational databases (e.g., in embedded finite model theory), most positive results (e.g., see Chapter 5 of [19]) do not extend to paths and remain within first-order logic.
References
- [1] Serge Abiteboul, Richard Hull, and Victor Vianu. Foundations of Databases. Addison–Wesley, Reading, MA, 1995.
- [2] Renzo Angles, Marcelo Arenas, Pablo Barceló, Aidan Hogan, Juan L. Reutter, and Domagoj Vrgoc. Foundations of modern query languages for graph databases. ACM Comput. Surv., 50(5):68:1–68:40, 2017. doi:10.1145/3104031.
- [3] Pablo Barceló, Gaëlle Fontaine, and Anthony Widjaja Lin. Expressive path queries on graph with data. Log. Methods Comput. Sci., 11(4), 2015. doi:10.2168/LMCS-11(4:1)2015.
- [4] Pablo Barceló, Leonid Libkin, Anthony Widjaja Lin, and Peter T. Wood. Expressive languages for path queries over graph-structured data. ACM Trans. Database Syst., 37(4):31:1–31:46, 2012. doi:10.1145/2389241.2389250.
- [5] Michael Benedikt. Generalizing finite model theory. In Logic Colloquium ’03, pages 3–24. Cambridge University Press, 2006.
- [6] Michael Benedikt and Leonid Libkin. Relational queries over interpreted structures. J. ACM, 47(4):644–680, 2000. doi:10.1145/347476.347477.
- [7] Michael Benedikt, Leonid Libkin, Thomas Schwentick, and Luc Segoufin. Definable relations and first-order query languages over strings. J. ACM, 50(5):694–751, 2003. doi:10.1145/876638.876642.
- [8] Michael Benedikt, Anthony Widjaja Lin, and Di-De Yen. Revisiting the expressiveness landscape of data graph queries. CoRR, abs/2406.17871, 2024. doi:10.48550/arXiv.2406.17871.
- [9] Diego Calvanese, Giuseppe De Giacomo, Maurizio Lenzerini, and Moshe Y. Vardi. Containment of conjunctive regular path queries with inverse. In KR, 2000.
- [10] GQL Standards Committee. GQL standards website, 2024. Accessed: November 2024. URL: https://www.gqlstandards.org/.
- [11] Alin Deutsch, Nadime Francis, Alastair Green, Keith Hare, Bei Li, Leonid Libkin, Tobias Lindaaker, Victor Marsault, Wim Martens, Jan Michels, Filip Murlak, Stefan Plantikow, Petra Selmer, Oskar van Rest, Hannes Voigt, Domagoj Vrgoc, Mingxi Wu, and Fred Zemke. Graph pattern matching in GQL and SQL/PGQ. In SIGMOD, 2022. doi:10.1145/3514221.3526057.
- [12] Diego Figueira, Artur Jeż, and Anthony W. Lin. Data path queries over embedded graph databases. In ACM Symposium on Principles of Database Systems (PODS), 2022. doi:10.1145/3517804.3524159.
- [13] Daniela Florescu, Alon Y. Levy, and Dan Suciu. Query containment for conjunctive queries with regular expressions. In ACM Symposium on Principles of Database Systems (PODS), 1998. doi:10.1145/275487.275503.
- [14] Nadime Francis, Amélie Gheerbrant, Paolo Guagliardo, Leonid Libkin, Victor Marsault, Wim Martens, Filip Murlak, Liat Peterfreund, Alexandra Rogova, and Domagoj Vrgoc. GPC: A pattern calculus for property graphs. In ACM Symposium on Principles of Database Systems (PODS), pages 241–250. ACM, 2023. doi:10.1145/3584372.3588662.
- [15] Nadime Francis, Amélie Gheerbrant, Paolo Guagliardo, Leonid Libkin, Victor Marsault, Wim Martens, Filip Murlak, Liat Peterfreund, Alexandra Rogova, and Domagoj Vrgoc. A researcher’s digest of GQL (invited talk). In International Conference on Database Theory (ICDT), volume 255 of LIPIcs, pages 1:1–1:22. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2023. doi:10.4230/LIPIcs.ICDT.2023.1.
- [16] Amelie Gheerbrant, Leonid Libkin, Liat Peterfreund, and Alexandra Rogova. GQL and SQL/PGQ: Theoretical Models and Expressive Power. Proceedings of the VLDB Endowment (PVLDB), 18(6):1798–1810, 2025. doi:10.14778/3725688.3725707.
- [17] Stefan Göller, Richard Mayr, and Anthony Widjaja To. On the computational complexity of verifying one-counter processes. In Proceedings of the 24th Annual IEEE Symposium on Logic in Computer Science, LICS 2009, 11-14 August 2009, Los Angeles, CA, USA, pages 235–244. IEEE Computer Society, 2009. doi:10.1109/LICS.2009.37.
- [18] Georg Gottlob. Np trees and carnap’s modal logic. J. ACM, 42(2):421–457, 1995. doi:10.1145/201019.201031.
- [19] E. Grädel, P. G. Kolaitis, L. Libkin, M. Marx, J. Spencer, M. Y. Vardi, Y. Venema, and S. Weinstein. Finite Model Theory and Its Applications. Springer, 2007.
- [20] Alastair Green, Paolo Guagliardo, and Leonid Libkin. Property graphs and paths in gql: Mathematical definitions. Technical Reports TR-2021-01, Linked Data Benchmark Council (LDBC), October 2021. doi:10.54285/ldbc.TZJP7279.
- [21] Jelle Hellings, Bart Kuijpers, Jan Van den Bussche, and Xiaowang Zhang. Walk logic as a framework for path query languages on graph databases. In International Conference on Database Theory (ICDT), 2013. doi:10.1145/2448496.2448512.
- [22] H. V. Jagadish, Angela Bonifati, George Fletcher, Hannes Voigt, and Nikolay Yakovets. Querying Graphs. Morgan and Claypool Publishers, 2018.
- [23] Gabriel Kuper, Leonid Libkin, and Jan Paredaens. Constraint Databases. Springer, 2000.
- [24] Leonid Libkin. Elements of finite model theory, volume 41. Springer, 2004. doi:10.1007/978-3-662-07003-1.
- [25] Leonid Libkin, Wim Martens, and Domagoj Vrgoc. Querying graphs with data. J. ACM, 63(2):14:1–14:53, 2016. doi:10.1145/2850413.
- [26] Leonid Libkin and Domagoj Vrgoc. Regular path queries on graphs with data. In Alin Deutsch, editor, International Conference on Database Theory (ICDT), pages 74–85. ACM, 2012. doi:10.1145/2274576.2274585.
- [27] Wim Martens, Matthias Niewerth, and Tina Popp. A trichotomy for regular trail queries. Log. Methods Comput. Sci., 19(4), 2023. doi:10.46298/LMCS-19(4:20)2023.
- [28] Alberto O. Mendelzon and Peter T. Wood. Finding regular simple paths in graph databases. SIAM J. Comput., 24(6):1235–1258, 1995. doi:10.1137/S009753979122370X.
- [29] Holger Spakowski and Jörg Vogel. Theta-completeness: A classical approach for new results. In Sanjiv Kapoor and Sanjiva Prasad, editors, Foundations of Software Technology and Theoretical Computer Science, 20th Conference, FST TCS 2000 New Delhi, India, December 13-15, 2000, Proceedings, volume 1974 of Lecture Notes in Computer Science, pages 348–360. Springer, 2000. doi:10.1007/3-540-44450-5_28.
- [30] Moshe Y. Vardi. The complexity of relational query languages (extended abstract). In Proceedings of the 14th Annual ACM Symposium on Theory of Computing, May 5-7, 1982, San Francisco, California, USA, pages 137–146, New York, NY, USA, 1982. Association for Computing Machinery. doi:10.1145/800070.802186.
- [31] Klaus W. Wagner. More complicated questions about maxima and minima, and some closures of NP. Theor. Comput. Sci., 51:53–80, 1987. doi:10.1016/0304-3975(87)90049-1.
