Vertex/Edge label and view

From: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Peter Eisentraut <peter(at)eisentraut(dot)org>
Subject: Vertex/Edge label and view
Date: 2026-08-07 06:47:31
Message-ID: CAExHW5toFV8b984ipuBSAar-W50K=+XmPOcG5ZUZNP4jrf4zSg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Peter, All,

A label in a property graph can be shared by both vertex and edge elements.
When such a label is used in a view, it can be rendered useless by dropping
that label from all vertex elements or edge elements as follows.

To run the reproducer you need to first run graph_table.sql from regression.

CREATE VIEW v_empty_label AS SELECT * FROM GRAPH_TABLE (g1 MATCH (v
WHERE v.vprop1 = 10) COLUMNS (v.elname));

ALTER PROPERTY GRAPH g1 ALTER VERTEX TABLE v1 DROP LABEL l1;
ALTER PROPERTY GRAPH g1 ALTER VERTEX TABLE v2 DROP LABEL l1;
ALTER PROPERTY GRAPH g1 ALTER VERTEX TABLE v3 DROP LABEL l1;
SELECT * FROM v_empty_label;
ERROR: no property graph element of type "vertex" has label "l1"
associated with it in property graph "g1"

The three ALTER TABLE statements drop label l1 from all the vertex
elements. But that does not lead to removing that label from the property
graph since there are edge elements associated with that label. The SELECT
at the end throws an error because the rewriter can not find an element
associated with the label mentioned in the view.

Myself and Peter this problem in PGConf.dev and thought that the error is
an artifact of the term "vertex labels" (or edge label) in the standard; a
term which is not properly defined in the standard. If a label is
associated with an element types (vertex or edge) in the catalog itself
i.e. element type is also part of the unique key of catalog
pg_propgraph_label, we will be able to add a dependency between the view
and the element type specific label. This in turn will prohibit dropping
the element type specific label from the catalog. The view won't be
rendered invalid then. This isn't that straight forward since such a label
still needs to have the same properties associated with it independent of
the element type. So we need pg_propgraph_label to contain only the label
name and have a separate catalog pg_proprgaph_elem_type_label (or some
such) which associates a label with an element type. The view should add
dependency on the row in the latter catalog.

Otherwise, standard needs to define the result of the query when a label
exists but is not associated with any element of required type - which
essentially would mean returning 0 rows since there are no elements
associated with the label.

I think we need the standard to define the behaviour in such a case.

Attached patch adds a test case to graph_table.sql showing this problem. We
may want to commit the test case so that someone coming across the issue
knows that this is the expected behaviour pending for clarification from
the standard.

Oracle prohibits sharing labels across vertex and edge elements, but other
graph databases allow it and so does the SQL/PGQ standard. I think it's a
useful feature, so I'm not thinking of doing it the Oracle way myself. But
if there are more people who think otherwise, I am ok with it.

[1]
https://www.postgresql.org/message-id/CAExHW5twGP5Zuk4Zch4kz8XDrSpckWQipMs=ysAj8GmqNa2FCQ@mail.gmail.com

--
Best Wishes,
Ashutosh Bapat

Attachment Content-Type Size
v20260807-0001-View-referencing-labels-shared-by-vertex-a.patch text/x-patch 6.0 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Smith 2026-08-07 07:03:38 Re: pg_createsubscriber: allow duplicate subscription names
Previous Message Hayato Kuroda (Fujitsu) 2026-08-07 06:44:22 RE: 019_replslot_limit.pl might fail due to checkpoint skipped