Graphiti: Bridging Graph and Relational Database Queries

Yang He, Ruijie Fang, Işıl Dillig, Yuepeng Wang

Abstract

This paper presents an automated reasoning technique for checking equivalence between graph database queries written in Cypher and relational queries in SQL. To formalize a suitable notion of equivalence in this setting, we introduce the concept of database transformers, which transform database instances between graph and relational models. We then propose a novel verification methodology that checks equivalence modulo a given transformer by reducing the original problem to verifying equivalence between a pair of SQL queries. This reduction is achieved by embedding a subset of Cypher into SQL through syntax-directed translation, allowing us to leverage existing research on automated reasoning for SQL while obviating the need for reasoning simultaneously over two different data models. We have implemented our approach in a tool called Graphiti and used it to check equivalence between graph and relational queries. Our experiments demonstrate that Graphiti is useful both for verification and refutation and that it can uncover subtle bugs, including those found in Cypher tutorials and academic papers.

Introduction

As organizations migrate from traditional relational databases (SQL) to more flexible graph databases (Cypher), developers face a daunting task: translating complex business logic between two fundamentally different data models. In SQL, data is organized into tables and connected via joins; in Cypher, data exists as a web of nodes and edges. This translation is notoriously error-prone due to subtle differences in how these languages handle relationships, null values, and aggregations. Until now, there was no formal way to define "equivalence" across these models, let alone an automated way to check it.

The Graphiti Methodology

Graphiti is the first automated reasoning tool designed to verify whether a graph query (Cypher) and a relational query (SQL) are semantically equivalent. The core innovation lies in a reduction process that transforms the cross-model verification problem into a standard SQL-to-SQL comparison.

The Graphiti workflow: reducing Cypher-SQL equivalence to SQL-SQL equivalence using transformers and transpilation.

The process involves four key components:

  1. Database Transformers: A Domain-Specific Language (DSL) that defines how a graph instance maps to a relational instance, providing the mathematical foundation for equivalence.
  2. Induced Relational Schemas: Graphiti automatically generates a "Standard Database Transformer" (SDT) that maps a graph's nodes and edges into a natural relational format.
  3. Syntax-Directed Transpilation: A "correct-by-construction" algorithm translates the Cypher query into an equivalent SQL query over the induced schema.
  4. The Reduction Trick: By converting the Cypher query into SQL, Graphiti can leverage existing SQL solvers (like VeriEQL or Mediator) to compare the result against the target SQL query.
Mapping between a graph schema (left) and its induced relational schema (right) via a transformer.

Experimental Evaluation

The researchers evaluated Graphiti on a diverse suite of 410 benchmarks, including examples from StackOverflow, official Neo4j tutorials, academic papers, and LLM-generated translations.

Key Results

  • Bug Detection: Graphiti identified 34 non-equivalent query pairs, including errors in official documentation and academic papers. For instance, a Neo4j tutorial intended to teach SQL users Cypher contained a non-equivalent query pair that Graphiti successfully refuted.
  • Verification Power: Using the Mediator backend, Graphiti proved equivalence for approximately 80% of the supported query pairs.
  • Efficiency: The transpilation process is highly efficient, typically completing in milliseconds. Furthermore, the automatically generated SQL queries were found to be competitive with hand-written versions.

Discussion and Key Insights

A major finding was that aggregation is a primary source of error; most translation mistakes occur because Cypher and SQL differ in their handling of grouping and counting. Graphiti’s formal semantics for "Featherweight Cypher" specifically target these edge cases. Additionally, the results highlight that while LLMs are proficient at syntax, they frequently fail at the semantic nuances of database migration, making verification tools essential for AI-assisted development.

Limitations and Future Work

Graphiti currently supports "Featherweight Cypher," which excludes advanced features like variable-length path patterns and specific graph algorithms like shortestPath. Future work involves expanding language support and developing a graphical interface to help users build database transformers more intuitively.

Summary updated

Abstract

This paper presents an automated reasoning technique for checking equivalence between graph database queries written in Cypher and relational queries in SQL. To formalize a suitable notion of equivalence in this setting, we introduce the concept of database transformers, which transform database instances between graph and relational models. We then propose a novel verification methodology that checks equivalence modulo a given transformer by reducing the original problem to verifying equivalence between a pair of SQL queries. This reduction is achieved by embedding a subset of Cypher into SQL through syntax-directed translation, allowing us to leverage existing research on automated reasoning for SQL while obviating the need for reasoning simultaneously over two different data models. We have implemented our approach in a tool called Graphiti and used it to check equivalence between graph and relational queries. Our experiments demonstrate that Graphiti is useful both for verification and refutation and that it can uncover subtle bugs, including those found in Cypher tutorials and academic papers.
BibTeX
@inproceedings{he2025graphiti,
  author = {Yang He and Ruijie Fang and Işıl Dillig and Yuepeng Wang},
  title = {{Graphiti: Bridging Graph and Relational Database Queries}},
  booktitle = {Proceedings of the ACM on Programming Languages},
  year = {2025},
  doi = {10.1145/3729319},
}
Figure