From 6862fcd91808602317376e8fe24f28fcfc4de063 Mon Sep 17 00:00:00 2001 From: Man Zeng Date: Fri, 5 Jun 2026 22:13:47 +0800 Subject: [PATCH] Clean up orphaned properties when dropping a label The orphaned property cleanup in RemoveRelations() was missing the drop_label case, leaving properties that no label references. --- src/backend/commands/propgraphcmds.c | 2 +- src/test/regress/expected/graph_table.out | 18 ++++++++++++++++++ src/test/regress/sql/graph_table.sql | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/backend/commands/propgraphcmds.c b/src/backend/commands/propgraphcmds.c index cc516e27020..7c8f397afbf 100644 --- a/src/backend/commands/propgraphcmds.c +++ b/src/backend/commands/propgraphcmds.c @@ -1638,7 +1638,7 @@ AlterPropGraph(ParseState *pstate, const AlterPropGraphStmt *stmt) } /* Remove any orphaned pg_propgraph_property entries */ - if (stmt->drop_properties || stmt->drop_vertex_tables || stmt->drop_edge_tables) + if (stmt->drop_label || stmt->drop_properties || stmt->drop_vertex_tables || stmt->drop_edge_tables) { foreach_oid(propoid, get_graph_property_ids(pgrelid)) { diff --git a/src/test/regress/expected/graph_table.out b/src/test/regress/expected/graph_table.out index cc6d80afd82..9617b4aa3e8 100644 --- a/src/test/regress/expected/graph_table.out +++ b/src/test/regress/expected/graph_table.out @@ -1044,4 +1044,22 @@ SELECT src.vname, count(*) FROM v1 AS src v13 | 1 (3 rows) +-- DROP LABEL should clean up orphaned properties +CREATE TABLE v4 (a int PRIMARY KEY, b int, c int); +INSERT INTO v4 VALUES (1, 2, 3); +CREATE PROPERTY GRAPH g5 + VERTEX TABLES ( + v4 LABEL l1 PROPERTIES (a, b, c) + LABEL l2 PROPERTIES (a) + ); +ALTER PROPERTY GRAPH g5 ALTER VERTEX TABLE v4 DROP LABEL l1; +SELECT pgpname FROM pg_propgraph_property + WHERE pgppgid = 'g5'::regclass ORDER BY pgpname; + pgpname +--------- + a +(1 row) + +DROP PROPERTY GRAPH g5; +DROP TABLE v4; -- leave the objects behind for pg_upgrade/pg_dump tests diff --git a/src/test/regress/sql/graph_table.sql b/src/test/regress/sql/graph_table.sql index 0e381ec72bc..ab89bdc1553 100644 --- a/src/test/regress/sql/graph_table.sql +++ b/src/test/regress/sql/graph_table.sql @@ -596,4 +596,18 @@ SELECT src.vname, count(*) FROM v1 AS src HAVING count(*) >= (SELECT count(*) FROM GRAPH_TABLE (g1 MATCH (a IS vl1 | vl2) COLUMNS (a.vname AS n)) WHERE n = src.vname) ORDER BY vname; +-- DROP LABEL should clean up orphaned properties +CREATE TABLE v4 (a int PRIMARY KEY, b int, c int); +INSERT INTO v4 VALUES (1, 2, 3); +CREATE PROPERTY GRAPH g5 + VERTEX TABLES ( + v4 LABEL l1 PROPERTIES (a, b, c) + LABEL l2 PROPERTIES (a) + ); +ALTER PROPERTY GRAPH g5 ALTER VERTEX TABLE v4 DROP LABEL l1; +SELECT pgpname FROM pg_propgraph_property + WHERE pgppgid = 'g5'::regclass ORDER BY pgpname; +DROP PROPERTY GRAPH g5; +DROP TABLE v4; + -- leave the objects behind for pg_upgrade/pg_dump tests -- 2.45.2