Hi Ashutosh

I re-checked the official SQL/PGQ standard (ISO/IEC 9075-16) to verify
whether property graphs differ from views on DROP ... CASCADE of
referenced objects, and specifically whether dropping a routine/function
used in a property expression is supposed to drop only the affected
element/property or the whole property graph.

The standard actually specifies whole-object drops for property graphs,
using the exact same "abandoned descriptor" mechanism in <revoke
statement> (9075-2 12.7 / 9075-16 12.3) that ISO SQL uses for views:

1. DROP / ALTER of referenced objects (Clause 11):
   In 11.4 <drop column definition>, 11.5 <drop table statement>,
   11.7 <drop view statement>, 11.14 <alter routine statement>,
   11.15 <drop routine statement>, and 11.8-11.13 / 11.16-11.18
   (domains, collations, UDTs, attributes, casts, orderings, sequences),
   9075-16 adds *only* a RESTRICT Syntax Rule inserting:

     "Any <value expression> associated with the <query expression> or a
     property of any label, either of which are included in any element
     table descriptor included in the tabular property graph descriptor
     included in any SQL-property graph descriptor."

   into the same 9075-2 RESTRICT list where views already appear. Every
   one of those subclauses states:

     "General Rules: No additional General Rules."

   None of them specify an implicit ALTER PROPERTY GRAPH to remove just
   the affected element table, label, or property.

2. CASCADE behavior via 12.3 <revoke statement> (modifies 9075-2 12.7):
   Just like views, CASCADE from DROP TABLE / VIEW / COLUMN / ROUTINE is
   executed through <revoke statement>. In 9075-16 12.3:

   - GR 3) (inserted right after the abandoned-view rules in 9075-2
     12.7 GR 12)b)) defines an entire SQL-property graph descriptor PG
     as "abandoned" if the revoke removes any required privilege for any
     vertex or edge table descriptor ET in TPGD, including:
       * table/column SELECT privileges for ET, its keys, and edge
         source/destination keys (GR 3)a)-c)), and
       * for any <value expression> VE of any property of any label of
         ET: SELECT on referenced tables/columns, USAGE on domains/UDTs/
         collations, and specifically GR 3)d)v):
         "The required execute privileges of VE."

   - GR 9) raises SQLSTATE 2B000 under RESTRICT if any SQL-property
     graph descriptor is abandoned.

   - GR 10) handles CASCADE by dropping the entire property graph:

       "For every abandoned SQL-property graph descriptor PG, let S1.PN
       be the <property graph name> of PG. The following <drop property
       graph statement> is effectively executed without further Access
       Rule checking:
         DROP PROPERTY GRAPH S1.PN CASCADE"

3. Dependent views and explicit ALTER PROPERTY GRAPH:
   - 11.27 <drop property graph statement> GR 1) executes
     REVOKE ALL PRIVILEGES ON PROPERTY GRAPH PGN FROM A CASCADE, and
     12.3 GR 2) marks any view referencing PGN as abandoned, cascading
     to DROP VIEW ... CASCADE.
   - Even when the user *explicitly* runs ALTER PROPERTY GRAPH to drop
     an element table (11.22), label (11.25), or property (11.26), the
     standard checks and cascades dependencies at the whole-graph (GD)
     level (RESTRICT rejects if the graph is referenced by any view,
     constraint, routine, trigger, or other property graph; CASCADE
     drops every dependent view/property graph as a whole).

So from a standards-compliance standpoint, we do not need per-element or
per-property OIDs in pg_depend to support partial cascading drops on
DROP FUNCTION / DROP COLUMN / DROP TABLE CASCADE -- dropping the whole
property graph as a single unit (just like a view) is exactly what
ISO/IEC 9075-16 specifies.

Regards,
Hannu

On Thu, Nov 26, 2026 at 10:17 PM Hannu Krosing <[email protected]> wrote:
>
> On Thu, Nov 26, 2026 at 2:56 PM Ashutosh Bapat
> <[email protected]> wrote:
> >
> >
> >
> > On Thu, Nov 26, 2026 at 3:48 AM Hannu Krosing <[email protected]> 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_afvdtrk...@mail.gmail.com
> > [2] 
> > https://www.postgresql.org/message-id/CAExHW5tQWFV=zahj_tzgcjtfbkw6_esp8zuqjmzfaomqzoc...@mail.gmail.com
> > [3] 
> > https://www.postgresql.org/message-id/CAExHW5vjV=wcgu-jvrrj_96jqqwy0ux3fjxwx3ckvzyg2mr...@mail.gmail.com
> >
> > --
> > Best Wishes,
> > Ashutosh Bapat


Reply via email to