January 17, 2019·4 min read·engineeringpostgresqlgraphscypher

AgensGraph 2.1 makes SQL and graph expressions fit together

AgensGraph 2.1 improves the boundary between Cypher and PostgreSQL expressions, with changes to type conversion, shortest paths and graph metadata.

A database that accepts two query languages has to define what happens when their expressions meet. Supporting SQL and Cypher in one query makes that question unavoidable. A function call needs arguments of the right types, and its result has to make sense to the surrounding expression. AgensGraph 2.1 addresses several of these boundaries, alongside changes to shortest-path queries and graph metadata.

The January 7 announcement presents AgensGraph as a PostgreSQL-based database for relational and graph data. Its 2.1.0 release notes, published January 17, give the more useful account of what changed. Built-in functions become usable through changes to constants and casts. Cypher gains subquery support for IN. Several graph operations also receive correctness fixes.

I default to PostgreSQL for relational work, and its capacity to support substantial additions is part of that preference. AgensGraph interests me because it applies that foundation to a different query model. The useful question is how much of the existing database machinery remains available when the query stops looking like ordinary SQL.

Functions need compatible expression types

The release notes group built-in function support with changes to constant handling and type conversion. That grouping explains why exposing functions involves more than recognizing their names. A query processor must give each argument a type that the selected function accepts. A literal in one language may not have the representation that a function inherited from another language expects.

The announcement specifically mentions handling UNKNOWNOID constants with jsonb and text, as well as preserving parameters as supplied. These are separate concerns. A constant may need its type resolved during query processing, while a parameter must retain the meaning supplied through the query interface. Treating both as interchangeable text would make integration appear simpler while moving ambiguity into execution.

AgensGraph 2.1 adds automatic type casting for function calls and operators. It also implements pre-evaluation of Cypher type casts. These changes put conversion into expression processing, where a function or operator can receive a value of the expected type. The release notes separately describe coercing return values to jsonb. Argument conversion and return conversion therefore both receive attention in this release.

This is relevant to anyone combining graph properties with database functions. A graph query language becomes less useful if every operation requires a parallel collection of graph-specific functions. Making existing built-ins accessible reduces that duplication. It also makes the rules for conversion part of the language contract, since an implicit conversion can affect which expressions are accepted.

The announcement changes the described conversion route for graph identifiers from jsonb to graphid to a route involving numeric. That is a specific implementation detail, not a general promise that every PostgreSQL type and every Cypher value now interoperate. The release supports a narrower conclusion. The project is repairing concrete expression boundaries that interfere with using the two query systems together.

Shortest paths include correctness work

Shortest-path changes occupy a substantial part of the release notes. The supported forms now include a shortest path without a path variable name, property constraints on the shortest path, and a variable name on its relationship. Each affects the query that a user can express. A query that needs only an endpoint should not acquire an unnecessary binding merely to satisfy a syntax restriction.

Property constraints matter because the set of eligible relationships defines the path problem. A shortest path through unrestricted relationships answers a different question from a shortest path through relationships that meet a condition. The notes announce support for that constraint, without supplying a benchmark or claiming a particular speedup for constrained traversals.

The fixes include an incorrect shortest-path result when labels are absent. That deserves attention independently of the performance heading. Faster traversal is useful only if the query retains the intended meaning. An incorrect result can pass unnoticed when the returned path looks plausible, whereas a rejected expression at least makes the failure visible to its caller.

I put more weight on these explicit correctness fixes than on an unquantified performance claim. The release identifies particular query forms and particular failure cases. That gives an engineer enough information to recognize whether an application uses the affected operation, without treating a general performance description as evidence about a particular workload.

Metadata and repeated writes have their own state

Graph metadata receives a configuration option controlling automatic behavior and a regather_graphmeta() function that resets and gathers it. These additions expose some control over metadata maintenance. The announcement does not establish a universal configuration recommendation, so the presence of the option alone is not a reason to disable automatic handling.

The release notes also fix a fatal metadata case involving a read-only main transaction and a subtransaction that writes a graph. This is another integration boundary. The graph implementation has to handle transaction state inherited from the database while maintaining its own metadata. The documented failure concerns that particular combination, and should not be generalized into a claim about every read-only transaction.

Repeated SET execution has a memory-leak fix. The notes connect it with removing a feature that merged expression modifications to the same element. That makes this release relevant to programs that repeatedly modify graph elements, even if they do not use shortest-path queries. A separate fix concerns missing material in pg_dump, which brings graph representation into the database export path as well.

The versioned README describes integrating relational and graph models within one database and combining SQL with Cypher in a single query. Version 2.1 makes that proposition more concrete through its handling of expressions and database utilities. Its documented fixes cover operations that a combined system has to support beyond reading a graph, including exporting data and maintaining metadata during transactions.