pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: zengman <zengman@halodbtech.com>
To: pgsql-hackers <pgsql-hackers@lists.postgresql.org>
Cc: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Cc: Peter Eisentraut <peter@eisentraut.org>
Subject: (SQL/PGQ) Clean up orphaned properties when dropping a label
Date: Fri, 5 Jun 2026 22:29:12 +0800
Message-ID: <tencent_76F6ACA2364EAA1E5DBD7A47@qq.com> (raw)

Hi all,

I noticed that ALTER PROPERTY GRAPH ... DROP LABEL doesn't clean up
orphaned pg_propgraph_property entries. The cleanup condition in
RemoveRelations() only checks for drop_properties,
drop_vertex_tables, and drop_edge_tables, but not drop_label.

Before fix:

```sql
postgres@zxm-VMware-Virtual-Platform:~/code/postgres$ psql
psql (19beta1)
Type "help" for help.

postgres=# CREATE TABLE v4 (a int PRIMARY KEY, b int, c int);
CREATE TABLE
postgres=# CREATE PROPERTY GRAPH g5
    VERTEX TABLES (
        v4 LABEL l1 PROPERTIES (a, b, c)
           LABEL l2 PROPERTIES (a)
    );
CREATE PROPERTY GRAPH
postgres=# ALTER PROPERTY GRAPH g5 ALTER VERTEX TABLE v4 DROP LABEL l1;
ALTER PROPERTY GRAPH
postgres=# SELECT pgpname FROM pg_propgraph_property
    WHERE pgppgid = 'g5'::regclass ORDER BY pgpname;
 pgpname
---------
 a
 b
 c
(3 rows)
```

After fix:
```sql
postgres@zxm-VMware-Virtual-Platform:~/code/postgres$ psql
psql (19beta1)
Type "help" for help.

postgres=# CREATE TABLE v4 (a int PRIMARY KEY, b int, c int);
CREATE TABLE
postgres=# CREATE PROPERTY GRAPH g5
    VERTEX TABLES (
        v4 LABEL l1 PROPERTIES (a, b, c)
           LABEL l2 PROPERTIES (a)
    );
CREATE PROPERTY GRAPH
postgres=# ALTER PROPERTY GRAPH g5 ALTER VERTEX TABLE v4 DROP LABEL l1;
ALTER PROPERTY GRAPH
postgres=# SELECT pgpname FROM pg_propgraph_property
    WHERE pgppgid = 'g5'::regclass ORDER BY pgpname;
 pgpname
---------
 a
(1 row)
```

```sql
CREATE TABLE v4 (a int PRIMARY KEY, b int, c int);
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;
```

--
regards,
Man Zeng

Attachments:

0001-Clean-up-orphaned-properties-when-dropping-a-label.patch (application/octet-stream, 3.0K) download From 6862fcd91808602317376e8fe24f28fcfc4de063 Mon Sep 17 00:00:00 2001 From: Man Zeng <zengman@halodbtech.com> 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

view thread (10+ messages)  latest in thread

Message-ID: <tencent_76F6ACA2364EAA1E5DBD7A47@qq.com>
Permalink:  ../tencent_76F6ACA2364EAA1E5DBD7A47@qq.com/
Also on:    postgresql.org/message-id/tencent_76F6ACA2364EAA1E5DBD7A47@qq.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: zengman@halodbtech.com, pgsql-hackers@lists.postgresql.org, ashutosh.bapat.oss@gmail.com, peter@eisentraut.org
  Subject: Re: (SQL/PGQ) Clean up orphaned properties when dropping a label
  In-Reply-To: <tencent_76F6ACA2364EAA1E5DBD7A47@qq.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox