[Paper Review] Querying for Paths in Graphs using Context-Free Path Queries
This paper introduces all-path and single-path query semantics for context-free path queries in graph databases, enabling retrieval of actual paths rather than just node-pairs. It proposes a formal framework using annotated context-free grammars to represent all paths and a novel algorithm to find minimum-length paths, demonstrating feasibility even for large-scale graphs with high result sizes.
Navigational queries for graph-structured data, such as the regular path queries and the context-free path queries, are usually evaluated to a relation of node-pairs $(m, n)$ such that there is a path from $m$ to $n$ satisfying the conditions of the query. Although this relational query semantics has practical value, we believe that the relational query semantics can only provide limited insight in the structure of the graph data. To address the limits of the relational query semantics, we introduce the all-path query semantics and the single-path query semantics. Under these path-based query semantics, a query is evaluated to all paths satisfying the conditions of the query, or, respectively, to a single such path. While focusing on context-free path queries, we provide a formal framework for evaluating queries on graphs using both path-based query semantics. For the all-path query semantics, we show that the result of a query can be represented by a finite context-free grammar annotated with node-information relevant for deriving each path in the query result. For the single-path query semantics, we propose to search for a path of minimum length. We reduce the problem of finding such a path of minimum length to finding a string of minimum length in a context-free language, and for deriving such a string we propose a novel algorithm. Our initial results show that the path-based query semantics have added practical value and that query evaluation for both path-based query semantics is feasible, even when query results grow very large. For the single-path query semantics, determining strict worst-case upper bounds on the size of the query result remains the focus of future work.
Motivation & Objective
- To address the limitations of traditional relational and boolean query semantics in graph databases, which obscure path structure and hinder debugging and insight.
- To propose path-based query semantics—specifically all-path and single-path semantics—that return actual paths rather than just node-pairs or truth values.
- To provide a formal framework for evaluating context-free path queries under these new semantics, enabling deeper structural understanding of graph data.
- To demonstrate the practical feasibility of path-based query evaluation, even when query results are large or complex.
Proposed method
- Represent the result of an all-path query using a context-free grammar annotated with node information to uniquely derive each path in the result.
- Reduce the problem of finding a minimum-length path under single-path semantics to finding a shortest string in a context-free language.
- Propose a novel algorithm for deriving the shortest string in a context-free language, which corresponds to the shortest path in the graph.
- Use bottom-up parsing techniques to evaluate queries, with performance sensitive to grammar ambiguity.
- Implement and evaluate the algorithms on synthetic graphs, including double-cyclic graphs with up to 4,750 nodes and 11 million paths.
- Analyze the impact of grammar ambiguity on performance, showing significant differences in running time even for equivalent languages.
Experimental results
Research questions
- RQ1Can path-based query semantics improve insight into graph structure compared to traditional relational query semantics?
- RQ2How can the result of a context-free path query be represented and efficiently computed when returning all actual paths?
- RQ3What is the most efficient way to compute a single path under the single-path query semantics, especially the shortest such path?
- RQ4How does grammar ambiguity affect the performance of path-based query evaluation?
- RQ5Can path-based query evaluation be optimized for unambiguous or deterministic grammars, or scaled using parallel/distributed architectures?
Key findings
- The all-path query semantics can be effectively represented using an annotated context-free grammar that captures node information for each derived path.
- The single-path query semantics can be reduced to finding the shortest string in a context-free language, which is solved via a novel algorithm with a runtime of 1.5 seconds for the longest path in a 4,750-node graph.
- On a double-cyclic graph with 4,750 nodes, the algorithm evaluated a query with 11 million paths in 4.3 seconds, demonstrating scalability.
- Performance varies significantly with grammar ambiguity: even equivalent grammars can yield vastly different running times, as seen with query q₁ and q₂.
- The algorithm scales well on large graphs, with query evaluation remaining practical despite massive result sizes.
- The study identifies open problems, including determining worst-case bounds on result size for single-path semantics and optimizing for unambiguous grammars.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.