Re: Storing Property Graphs like Views (as a serialized analyzed parse tree)

From: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
To: Hannu Krosing <hannuk(at)google(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Storing Property Graphs like Views (as a serialized analyzed parse tree)
Date: 2026-11-26 13:56:09
Message-ID: CAExHW5s7qFdWzAk_B9fJqkAXvOqFGNec7eY7s-7hMb4HwVQDew@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Nov 26, 2026 at 3:48 AM Hannu Krosing <hannuk(at)google(dot)com> wrote:

> Hi hackers,
>
> Looking back at the issues that led to reverting SQL/PGQ before PG 19
> (orphaned labels and properties on CASCADE drops, partial-drop consistency
> problems, missing pg_dump dependency transfers, locking gaps across
> catalog scans, and privilege mismatches), a large share of the trouble
> came from decomposing a single property graph into five normalized
> pg_propgraph_* catalogs with independent OIDs and syscaches.
>
> Before the catalog layer is reworked for PG 20, I'd like to propose
> storing a Property Graph the same way we store any other View: a pg_class
> entry (relkind = 'g', sharing the relation namespace and ACLs) paired with
> a
> single pg_node_tree holding the post-parse-analysis graph definition
> (either in pg_rewrite or in a single-row catalog), cached in relcache.
>
> Conceptually, a property graph is very close to a multi-table view: it
> has no storage of its own and simply projects labels, keys, join links,
> and SQL expressions over underlying relations. Treating it like a view
> buys a lot of proven Postgres infrastructure almost for free:
>
> 1. Atomic dependencies and CASCADE: Walking one analyzed tree with
> recordDependencyOnExpr() captures tables, columns, types, collations,
> functions, operators, and implicit casts in one place. RESTRICT and
> CASCADE work on the graph as a unit (just like views), avoiding
> orphan labels/properties and custom GC passes in dependency.c.
>

This means that if a SQL function that a property of a property graph
depends upon gets DROP CASCADEed, whole property graph gets dropped. That's
not how standard specifies it. It specifies that only the affected element
should get dropped. We don't want to add logic in dependency tracking
mechanism to expand the property graph and find out the element that should
be dropped. We need OID for each element at least.

>
> 2. Clean pg_dump and RENAME behavior: Because references in an analyzed
> node tree use OIDs and attnums, table/column/schema renames work
> automatically via ruleutils.c. pg_dump gets complete dependencies
> from a single object (and can break view/matview dependency loops
> using the same shell + OR REPLACE split views use).
>

See my rough proposal at [1].

>
> 3. Unified locking, privileges, and caching: Deserializing once into a
> relcache memory context eliminates 8 permanent syscaches and repeated
> catalog scans during query rewrite, while reusing view-style locking
> (AccessExclusiveLock on DDL, AcquireRewriteLocks on rewrite) and
> RTEPermissionInfo (owner vs. security_invoker).

> 4. Lightweight introspection: The SQL/PGQ information_schema views and
> psql describe commands can be backed by small set-returning C
> functions over the cached definition, rather than dedicated catalog
> tables.
>

A property graph with thousands of labels and properties (if not elements)
would eat a lot of memory even if the query doesn't use all of them and in
every backend that uses the property graph.

>
> The main trade-off is that ALTER PROPERTY GRAPH rewrites onepg_node_tree
> tuple instead of inserting or deleting individual catalog rows, which
> seems entirely fine for rare DDL.
>

I doubt that's the only case, at least above two cases need a better
solution.

Also please take a look at [2] and [3].

[1]
https://www.postgresql.org/message-id/CAExHW5sUhT9MmJSEGAKMX8z8NYkt0dxeGw_Q4f7_afVDtRkCZw@mail.gmail.com
[2]
https://www.postgresql.org/message-id/CAExHW5tQWFV=zahj_tzGcjTfbkW6_esP8zuQJmZfAoMQZOcWVw@mail.gmail.com
[3]
https://www.postgresql.org/message-id/CAExHW5vjV=wCGU-JVRRj_96JqQWY0uX3fJXwX3ckVZyg2mR4bA@mail.gmail.com

--
Best Wishes,
Ashutosh Bapat

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jelte Fennema-Nio 2026-11-26 14:10:59 Re: Reapply graceful socket shutdown on Windows (revert 29992a6a509)
Previous Message Daniel Gustafsson 2026-11-26 13:55:21 Re: Fix a wrong comment in UpdateDeadTupleRetentionStatus()