Querying Graph-Relational Data

Michael J. Sullivan, Zhibo Chen, Elvis Pranskevichus, Robert J. Simmons, Victor Petrovykh, Aljaž Mur Eržen, Yury Selivanov · DOI

TL;DR

This paper introduces the graph-relational database model and its implementation in the Gel system (formerly EdgeDB). It provides a formal foundation for a query language, EdgeQL, that allows developers to fetch deeply nested, "object-shaped" data in a single, highly efficient PostgreSQL query, effectively solving the notorious "n+1 query problem" inherent in traditional ORMs.

What Problem Does This Paper Address?

For decades, developers have struggled with the object-relational impedance mismatch. Applications think in terms of objects and trees (e.g., a Movie with a list of Actors, each having a Profile), while relational databases think in terms of flat tables and rows.

To bridge this, we usually turn to Object-Relational Mappers (ORMs). However, ORMs often fall into two traps:

  1. The n+1 Problem: They fetch the main object and then issue a separate query for every related child object, leading to massive network overhead.
  2. Redundancy: They use massive JOIN statements that return "denormalized" data, repeating parent information for every child row and wasting bandwidth.

The authors propose a middle ground: a model that feels like a graph or document database to the developer but retains the strict typing, performance, and reliability of a relational backend.

Methods

The authors define the graph-relational model, which treats data as a collection of nodes (entities) connected by directed edges (relationships).

Key Innovations:

  • EdgeQL: A SQL-style language designed for "shaping" data. Instead of flat joins, users write nested selections that look remarkably like the JSON they expect to receive.
  • Cardinality Modes: The paper introduces a formal type system using five cardinality modes (e.g., [1, 1] for required single, [0, ∞] for optional multi). This replaces the messy "null" logic of SQL with a mathematically sound semiring, allowing the compiler to reason about whether a result is a single value or a set.
  • The Gel Compiler: The core of the system is a compiler that translates these high-level, nested EdgeQL queries into a single, optimized PostgreSQL query. It leverages non-standard PostgreSQL features like array_agg and json_agg to package nested data efficiently on the database side before sending it over the wire.
  • Link Properties: Unlike standard relational models, relationships (edges) can have their own properties (e.g., the specific character name an actor plays in a movie) without requiring the developer to manually manage intermediate join tables.

Datasets

The authors evaluate their system using IMDBench, a benchmark modeled after an IMDB-like movie database.

  • Structure: It includes entities like Movies, Persons, Directors, and Actors, with complex many-to-many relationships.
  • Comparison: Gel is benchmarked against six industry-standard ORMs: Django and SQLAlchemy (Python), and TypeORM, Sequelize, Prisma, and Drizzle (Node.js/JS).
  • Baseline: The "gold standard" comparison is asyncpg, a high-performance, raw PostgreSQL driver for Python using hand-tuned SQL.

Key Insights and Ideas

  • Compositionality is King: Because EdgeQL is formally defined and compositional, you can nest queries inside other queries without a performance cliff. The compiler "flattens" the logic into one database round-trip.
  • Cardinality as a Type: By making cardinality (how many items are returned) part of the type system, Gel can automatically generate precise TypeScript types for the application, reducing runtime errors.
  • Backlinks as First-Class Citizens: The model treats reverse relationships (e.g., "find all movies directed by this person") as naturally as forward ones, using a dedicated backlink operator (⊳).
  • The "Single Query" Guarantee: A fundamental constraint of the Gel implementation is that every EdgeQL query must compile to exactly one SQL query, ensuring predictable performance.

Key Results

  • Throughput: In the IMDBench benchmarks, Gel (both Python and JS versions) significantly outperformed all six ORMs. For example, Gel achieved over 500 iterations/s, while popular ORMs like Prisma and Django hovered between 70 and 110 iterations/s.
  • Near-Native Speed: Gel reached within 20% of the performance of hand-tuned, raw SQL (asyncpg). This is a major win, as it offers the developer productivity of an ORM with the speed of a database expert.
  • Latency: By collapsing multiple round-trips into one, Gel drastically reduced latency, especially in environments with simulated network delays where traditional ORMs struggled.

Limitations and Future Work

  • The De-duplication "Dance": The authors admit a slight discrepancy between their formal model and the actual implementation regarding when results should be de-duplicated (e.g., if two movies have the same director). They view this as an ongoing design conversation between "pure" compositionality and practical user expectations.
  • Static Visibility: Currently, whether a property is "visible" or "hidden" is tracked during query execution. The authors suggest moving this to the static type-checking phase to improve client-side code generation.
  • Feature Parity: The formalization in the paper does not yet cover some of Gel's more advanced features, such as inheritance, subtyping, and complex database constraints, which are earmarked for future formalization efforts.

Summary updated

BibTeX
@misc{sullivan2025querying,
  author = {Michael J. Sullivan and Zhibo Chen and Elvis Pranskevichus and Robert J. Simmons and Victor Petrovykh and Aljaž Mur Eržen and Yury Selivanov},
  title = {{Querying Graph-Relational Data}},
  year = {2025},
  eprint = {2507.16089},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2507.16089},
}

Loading related content...

Figure