| From: | Hannu Krosing <hannuk(at)google(dot)com> |
|---|---|
| To: | Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(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 21:17:22 |
| Message-ID: | CAMT0RQQcdrDQJ4mxomdwMMHoNGRJ=rOBgyYZ_zYc4_k8xGW6jQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Thu, Nov 26, 2026 at 2:56 PM Ashutosh Bapat
<ashutosh(dot)bapat(dot)oss(at)gmail(dot)com> wrote:
>
>
>
> 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.
Are Property Graphs fundamentally different from Views in this regard ?
At high level they look like a special kind of View.
This is what a quick search about the difference between plain VIEWs
and PROPERTY GRAPHS came back with (it may be wrong, will have to
check the actual standard)
No, the core ANSI/ISO standard rule is the same. Under ISO/IEC 9075-16
(SQL/PGQ), a Property Graph is treated as a schema-level view-like
metadata descriptor over underlying tables. Executing ALTER TABLE ...
DROP COLUMN ... CASCADE drops any dependent property graph if the
dropped column is referenced by that graph, while RESTRICT blocks the
drop.
However, because a property graph maps relational columns to graph
keys, labels, and properties, the dependency scope and real-world
implementations have distinct nuances.
How Dependency Evaluation Works in SQL/PGQ
• Referenced Columns Trigger a Drop. A property graph depends on a
column if that column is used in a vertex or edge KEY clause, a
PROPERTIES list, a SOURCE KEY / DESTINATION KEY mapping, or a dynamic
LABEL expression.
• Implicit DROP PROPERTY GRAPH CASCADE. When CASCADE is specified and
a referenced column is dropped, the standard executes an implicit DROP
PROPERTY GRAPH <graph_name> CASCADE. It does not simply strip that
single property from the graph definition; the entire property graph
object is removed.
• Recursive Cascading to Views. Because DROP PROPERTY GRAPH cascades,
any SQL views or routines that query that graph via GRAPH_TABLE(...)
are also automatically dropped.
• Implicit PROPERTIES ARE ALL COLUMNS. Just like SELECT * in a
standard view, if a vertex or edge table is defined with PROPERTIES
ARE ALL COLUMNS (or defaults to it), the standard resolves that list
to the table's existing columns at creation time. Dropping any column
from that table triggers the cascade and drops the property graph.
• Unreferenced Columns. If an element table explicitly lists
PROPERTIES (col_a, col_b) or NO PROPERTIES, dropping an unreferenced
col_c leaves the property graph intact.
Real-World RDBMS Implementation Differences
Just as with standard views, commercial and open-source engines
diverge from strict ANSI CASCADE behavior when managing property
graphs:
• Oracle Database (23ai / 26ai): Does not drop the property graph when
an underlying column is dropped. Instead, Oracle marks the PROPERTY
GRAPH object as INVALID—even if the dropped column was not referenced
by the graph—requiring you to run ALTER PROPERTY GRAPH <name> COMPILE
(or recreate it if the dropped column was used).
• PostgreSQL: Follows the ANSI dependency model strictly by tracking
column-level dependencies in pg_depend, meaning DROP COLUMN ...
CASCADE drops dependent property graphs and any downstream GRAPH_TABLE
views. (Note: Due to complex dependency and catalog edge cases around
DROP and foreign keys, PostgreSQL developers opted to defer SQL/PGQ
out of the PostgreSQL 19 release to refine its dependency handling.)
• Google Cloud Spanner: Requires you to drop or update dependent
schema objects explicitly before dropping a referenced column,
behaving closer to RESTRICT rather than silently cascading
deletions.Or maybe we are doing Views wrong, and DROP COLUMN should
just remove that
...
>> 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.
Is the PGQ current implementation caching individual parts of property graphs ?
Again, how and why is this different from a large View over many
tables with hundreds or thousands of fields?
>>
>> 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].
Thanks, I will.
> [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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Manu | 2026-11-26 21:17:43 | Re: Allow progress tracking of sub-commands |
| Previous Message | Heikki Linnakangas | 2026-11-26 21:04:38 | Re: Fix two race conditions in processing interrupts |