Skip to content

Commit fdb9bb7

Browse files
ashutosh-bapathackorum
authored andcommitted
View referencing labels shared by vertex and edge tables
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 it does not find any elements associated with the label. The fix depends upon how the SQL/PGQ standard specifies the behaviour in such a case. Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
1 parent 6e89028 commit fdb9bb7

2 files changed

Lines changed: 42 additions & 4 deletions

File tree

src/test/regress/expected/graph_table.out

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -999,8 +999,7 @@ ALTER PROPERTY GRAPH myshop ALTER VERTEX TABLE products
999999
ERROR: cannot drop property price of property graph myshop because other objects depend on it
10001000
DETAIL: view customers_us depends on property price of property graph myshop
10011001
HINT: Use DROP ... CASCADE to drop the dependent objects too.
1002-
-- ruleutils reverse parsing
1003-
SELECT pg_get_viewdef('customers_us'::regclass);
1002+
SELECT pg_get_viewdef('customers_us'::regclass); -- ruleutils reverse parsing
10041003
pg_get_viewdef
10051004
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
10061005
SELECT g.customer_name, +
@@ -1012,6 +1011,29 @@ SELECT pg_get_viewdef('customers_us'::regclass);
10121011
ORDER BY g.customer_name, g.product_name;
10131012
(1 row)
10141013

1014+
-- l1 is shared by all vertex tables and edge tables. Dropping it only from all
1015+
-- vertex tables renders a view unusable. This is because the standard considers
1016+
-- a label shared between vertex labels and edge labels as two different labels
1017+
-- vertex label and edge label respectively. Further note that the standard
1018+
-- still requires the two labels to have the same properties associated with
1019+
-- them. We need the standard to clarify the behaviour in this case: should we
1020+
-- prohibit dropping an element specific label or return no rows when the label
1021+
-- exists but is not associated with any element of required type.
1022+
CREATE VIEW v_shared_label AS SELECT * FROM GRAPH_TABLE (g1 MATCH (v IS l1) COLUMNS (v.elname));
1023+
BEGIN;
1024+
ALTER PROPERTY GRAPH g1 ALTER VERTEX TABLE v1 DROP LABEL l1;
1025+
ALTER PROPERTY GRAPH g1 ALTER VERTEX TABLE v2 DROP LABEL l1;
1026+
ALTER PROPERTY GRAPH g1 ALTER VERTEX TABLE v3 DROP LABEL l1;
1027+
SELECT * FROM v_shared_label;
1028+
ERROR: no property graph element of type "vertex" has label "l1" associated with it in property graph "g1"
1029+
ROLLBACK;
1030+
SELECT pg_get_viewdef('v_shared_label'::regclass); -- ruleutils reverse parsing
1031+
pg_get_viewdef
1032+
------------------------------------------------------------------------
1033+
SELECT elname +
1034+
FROM GRAPH_TABLE (g1 MATCH (v IS l1) COLUMNS (v.elname AS elname));
1035+
(1 row)
1036+
10151037
-- test view/graph nesting
10161038
CREATE VIEW customers_view AS SELECT customer_id, 'redacted' || customer_id AS name_redacted, address FROM customers;
10171039
SELECT * FROM customers;

src/test/regress/sql/graph_table.sql

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,24 @@ ALTER PROPERTY GRAPH myshop ALTER VERTEX TABLE customers
561561
ALTER LABEL customers DROP PROPERTIES (address); -- error
562562
ALTER PROPERTY GRAPH myshop ALTER VERTEX TABLE products
563563
ALTER LABEL products DROP PROPERTIES (price); -- error
564-
-- ruleutils reverse parsing
565-
SELECT pg_get_viewdef('customers_us'::regclass);
564+
SELECT pg_get_viewdef('customers_us'::regclass); -- ruleutils reverse parsing
565+
566+
-- l1 is shared by all vertex tables and edge tables. Dropping it only from all
567+
-- vertex tables renders a view unusable. This is because the standard considers
568+
-- a label shared between vertex labels and edge labels as two different labels
569+
-- vertex label and edge label respectively. Further note that the standard
570+
-- still requires the two labels to have the same properties associated with
571+
-- them. We need the standard to clarify the behaviour in this case: should we
572+
-- prohibit dropping an element specific label or return no rows when the label
573+
-- exists but is not associated with any element of required type.
574+
CREATE VIEW v_shared_label AS SELECT * FROM GRAPH_TABLE (g1 MATCH (v IS l1) COLUMNS (v.elname));
575+
BEGIN;
576+
ALTER PROPERTY GRAPH g1 ALTER VERTEX TABLE v1 DROP LABEL l1;
577+
ALTER PROPERTY GRAPH g1 ALTER VERTEX TABLE v2 DROP LABEL l1;
578+
ALTER PROPERTY GRAPH g1 ALTER VERTEX TABLE v3 DROP LABEL l1;
579+
SELECT * FROM v_shared_label;
580+
ROLLBACK;
581+
SELECT pg_get_viewdef('v_shared_label'::regclass); -- ruleutils reverse parsing
566582

567583
-- test view/graph nesting
568584

0 commit comments

Comments
 (0)