(SQL/PGQ) Clean up orphaned properties when dropping a label

From: zengman <zengman(at)halodbtech(dot)com>
To: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>, Peter Eisentraut <peter(at)eisentraut(dot)org>
Subject: (SQL/PGQ) Clean up orphaned properties when dropping a label
Date: 2026-06-05 14:29:12
Message-ID: tencent_76F6ACA2364EAA1E5DBD7A47@qq.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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(at)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(at)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

Attachment Content-Type Size
0001-Clean-up-orphaned-properties-when-dropping-a-label.patch application/octet-stream 3.0 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message zengman 2026-06-05 14:37:43 Re: (SQL/PGQ) cache lookup failed for label
Previous Message Fujii Masao 2026-06-05 14:28:44 Re: Prevent remote libpq notices from being sent to clients