From 8e630ed6b73f5a0cd4031ac9747d3ffc0623501d Mon Sep 17 00:00:00 2001 From: Ashutosh Bapat Date: Thu, 28 May 2026 02:47:33 +0530 Subject: [PATCH v20260708 3/5] View referencing labels shared by vertex and edge tables While at it add a test for view containing labels which are shared by both vertex and edge tables. When such a label is dropped from only vertex tables or only edge tables, the view may be rendered invalid because properties only associated with that label can not be resolved. The fix will need to wait for the SQL/PGQ standard to specify the behaviour in such a case. Author: Ashutosh Bapat --- src/test/regress/expected/graph_table.out | 20 ++++++++++++++++++++ src/test/regress/sql/graph_table.sql | 13 +++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/test/regress/expected/graph_table.out b/src/test/regress/expected/graph_table.out index 869ef481c04..0ccebf1aea5 100644 --- a/src/test/regress/expected/graph_table.out +++ b/src/test/regress/expected/graph_table.out @@ -1008,6 +1008,19 @@ ALTER PROPERTY GRAPH g1 ALTER VERTEX TABLE v2 DROP LABEL vl2; -- error ERROR: cannot drop label vl2 of property graph g1 because other objects depend on it DETAIL: view v_empty_label depends on label vl2 of property graph g1 HINT: Use DROP ... CASCADE to drop the dependent objects too. +-- l1 is shared by all vertex tables and edge tables. Dropping it from all +-- vertex tables only renders a view unusable. This is because the standard +-- differentiates between a vertex label and an edge label even though they +-- share the same name. Waiting for the standard to clarify the expected +-- behavior in this case. +CREATE VIEW v_shared_label AS SELECT * FROM GRAPH_TABLE (g1 MATCH (v IS l1) COLUMNS (v.elname)); +BEGIN; +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_shared_label; +ERROR: no property graph element of type "vertex" has label "l1" associated with it in property graph "g1" +ROLLBACK; -- ruleutils reverse parsing SELECT pg_get_viewdef('customers_us'::regclass); pg_get_viewdef @@ -1028,6 +1041,13 @@ SELECT pg_get_viewdef('v_empty_label'::regclass); FROM GRAPH_TABLE (g1 MATCH (v IS l1|vl1|vl2|vl3 WHERE (v.vprop1 = 10)) COLUMNS (v.elname AS elname)); (1 row) +SELECT pg_get_viewdef('v_shared_label'::regclass); + pg_get_viewdef +------------------------------------------------------------------------ + SELECT elname + + FROM GRAPH_TABLE (g1 MATCH (v IS l1) COLUMNS (v.elname AS elname)); +(1 row) + -- test view/graph nesting CREATE VIEW customers_view AS SELECT customer_id, 'redacted' || customer_id AS name_redacted, address FROM customers; SELECT * FROM customers; diff --git a/src/test/regress/sql/graph_table.sql b/src/test/regress/sql/graph_table.sql index b6a20db7a41..9e5817bb4ca 100644 --- a/src/test/regress/sql/graph_table.sql +++ b/src/test/regress/sql/graph_table.sql @@ -566,9 +566,22 @@ ALTER PROPERTY GRAPH myshop ALTER VERTEX TABLE products 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 vl1; -- error ALTER PROPERTY GRAPH g1 ALTER VERTEX TABLE v2 DROP LABEL vl2; -- error +-- l1 is shared by all vertex tables and edge tables. Dropping it from all +-- vertex tables only renders a view unusable. This is because the standard +-- differentiates between a vertex label and an edge label even though they +-- share the same name. Waiting for the standard to clarify the expected +-- behavior in this case. +CREATE VIEW v_shared_label AS SELECT * FROM GRAPH_TABLE (g1 MATCH (v IS l1) COLUMNS (v.elname)); +BEGIN; +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_shared_label; +ROLLBACK; -- ruleutils reverse parsing SELECT pg_get_viewdef('customers_us'::regclass); SELECT pg_get_viewdef('v_empty_label'::regclass); +SELECT pg_get_viewdef('v_shared_label'::regclass); -- test view/graph nesting -- 2.34.1