| From: | Hannu Krosing <hannuk(at)google(dot)com> |
|---|---|
| To: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Storing Property Graphs like Views (as a serialized analyzed parse tree) |
| Date: | 2026-11-25 22:18:19 |
| Message-ID: | CAMT0RQSmWK=XNqADqU5xNF4UTLfYNWu-bwYtjLat8GuO3Wh=jg@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
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.
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).
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.
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.
Does this direction make sense to folks working on resurrecting SQL/PGQ?
Cheers,
Hannu
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2026-11-25 22:22:40 | Re: [PATCH] Fix encoding-dependent LIKE/regex selectivity estimates |
| Previous Message | Andrey Rachitskiy | 2026-11-25 21:14:33 | Re: Fix OOM when rendering large geometry arrays |